[FFmpeg-devel] [RFC] Add IFF-ANIM decoder to Makefile and all that stuff...

Stefano Sabatini stefano.sabatini-lala
Wed Apr 21 02:00:34 CEST 2010


On date Wednesday 2010-04-21 00:34:49 +0200, Sebastian Vater encoded:
[...]
> +static int decode_frame_anim(AVCodecContext *avctx,
> +                            void *data, int *data_size,
> +                            AVPacket *avpkt)

nit++: vertical indent void and AVPacket indented one space more

> +{
> +    decode_frame_ilbm(avctx,data,data_size,avpkt);
> +    av_log(avctx, AV_LOG_DEBUG, "decode_frame_anim stub\n");
> +
> +    return -1;
> +}
> +
>  static int decode_frame_byterun1(AVCodecContext *avctx,
>                              void *data, int *data_size,
>                              AVPacket *avpkt)
> @@ -216,6 +238,13 @@
>      return 0;
>  }
>  
> +static av_cold int decode_end_anim(AVCodecContext *avctx)
> +{
> +    av_log(avctx, AV_LOG_DEBUG, "decode_end_anim stub\n");
> +
> +    return decode_end(avctx);
> +}
> +
>  AVCodec iff_ilbm_decoder = {
>      "iff_ilbm",
>      AVMEDIA_TYPE_VIDEO,
> @@ -241,3 +270,16 @@
>      CODEC_CAP_DR1,
>      .long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"),
>  };
> +
> +AVCodec iff_anim_decoder = {
> +    "iff_anim",
> +    AVMEDIA_TYPE_VIDEO,
> +    CODEC_ID_IFF_ANIM,
> +    sizeof(IffContext),
> +    decode_init_anim,
> +    NULL,
> +    decode_end_anim,
> +    decode_frame_anim,
> +    CODEC_CAP_DR1,
> +    .long_name = NULL_IF_CONFIG_SMALL("IFF ANIM"),
> +};
> Index: ffmpeg-svn/libavformat/iff.c
> ===================================================================
> --- ffmpeg-svn/libavformat/iff.c	(r??vision 22924)
> +++ ffmpeg-svn/libavformat/iff.c	(copie de travail)
> @@ -2,6 +2,7 @@
>   * IFF (.iff) file demuxer
>   * Copyright (c) 2008 Jaikrishnan Menon <realityman at gmx.net>
>   * Copyright (c) 2010 Peter Ross <pross at xvid.org>
> + * Copyright (c) 2010 Sebastian Vater <cdgs.basty at googlemail.com>
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -54,6 +55,12 @@
>  #define ID_BODY       MKTAG('B','O','D','Y')
>  #define ID_ANNO       MKTAG('A','N','N','O')
>  
> +#define ID_ANIM       MKTAG('A','N','I','M')
> +#define ID_ANHD       MKTAG('A','N','H','D')
> +#define ID_DLTA       MKTAG('D','L','T','A')
> +#define ID_SXHD       MKTAG('S','X','H','D')
> +#define ID_SBDY       MKTAG('S','B','D','Y')

nit: alphabetical order

> +
>  #define LEFT    2
>  #define RIGHT   4
>  #define STEREO  6
> @@ -71,7 +78,21 @@
>      BITMAP_BYTERUN1
>  } bitmap_compression_type;
>  
> +typedef enum {
> +    ANIM_BITMAP_RAW,
> +    ANIM_BITMAP_BYTERUN1,
> +    ANIM_LONG_DELTA,
> +    ANIM_SHORT_DELTA,
> +    ANIM_GENERAL_DELTA,
> +    ANIM_BYTE_VERTICAL_DELTA,
> +    ANIM_STEREO_BYTE_DELTA,
> +    ANIM_BYTE_VERTICAL_DELTA_WORD,
> +    ANIM_BYTE_VERTICAL_DELTA_LONG,
> +    ANIM_ERIC_GRAHAM = 74
> +} anim_compression_type;
> +
>  typedef struct {
> +    uint64_t  body_pos;
>      uint32_t  body_size;
>      uint32_t  sent_bytes;
>      uint32_t  audio_frame_count;
> @@ -95,7 +116,7 @@
>      const uint8_t *d = p->buf;
>  
>      if ( AV_RL32(d)   == ID_FORM &&
> -         (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) )
> +         (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM || AV_RL32(d+8) == ID_ANIM) )
>          return AVPROBE_SCORE_MAX;
>      return 0;
>  }
> @@ -106,8 +127,7 @@
>      IffDemuxContext *iff = s->priv_data;
>      ByteIOContext *pb = s->pb;
>      AVStream *st;
> -    uint32_t chunk_id, data_size;
> -    int padding, done = 0;
> +    uint32_t chunk_id, data_size, data_size_skip;
>      int compression = -1;
>      char *buf;
>  
> @@ -115,33 +135,70 @@
>      if (!st)
>        return AVERROR(ENOMEM);
>  
> +    st->codec->bits_per_coded_sample = 8;
>      st->codec->channels = 1;
>      url_fskip(pb, 8);
> -    // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
> +    // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM), interlaced (ILBM) and animated (ANIM) content
>      st->codec->codec_tag = get_le32(pb);
>  
> -    while(!done && !url_feof(pb)) {
> +    while(!url_feof(pb)) {
>          chunk_id = get_le32(pb);
> -        data_size = get_be32(pb);
> -        padding = data_size & 1;
> +        data_size_skip = data_size = get_be32(pb);
> +        data_size_skip += data_size & 1;
>  
> +        av_log(s, AV_LOG_ERROR, "iff: reading chunk %c%c%c%c, size: 0x%08x\n", (char) chunk_id, (char) (chunk_id >> 8), (char) (chunk_id >> 16), (char) (chunk_id >> 24), data_size);

AV_LOG_DEBUG, split overly long line

[...]
> @@ -151,20 +208,55 @@
>                  return AVERROR(ENOMEM);
>              if (get_buffer(pb, st->codec->extradata, data_size) < 0)
>                  return AVERROR(EIO);
> +
> +            data_size_skip -= data_size;
>              break;
>  
> +        case ID_ANHD:
> +            st->codec->codec_type            = AVMEDIA_TYPE_VIDEO;
> +
> +            if (data_size >= 1) {
> +                compression                      = get_byte(pb);
> +
> +                data_size_skip--;
> +            }
> +
> +            if (data_size >= 6) {
> +                url_fskip(pb, 1); // masking
> +//                st->codec->width                 = get_be16(pb);
> +//                st->codec->height                = get_be16(pb);

uh, why commented?

> +                data_size_skip -= 5;
> +            }
> +
> +            break;
> +
>          case ID_BMHD:
>              st->codec->codec_type            = AVMEDIA_TYPE_VIDEO;
> +
> +            if (data_size <= 8)
> +                return AVERROR_INVALIDDATA;
> +
>              st->codec->width                 = get_be16(pb);
>              st->codec->height                = get_be16(pb);
>              url_fskip(pb, 4); // x, y offset
>              st->codec->bits_per_coded_sample = get_byte(pb);
> -            url_fskip(pb, 1); // masking
> -            compression                      = get_byte(pb);
> -            url_fskip(pb, 3); // paddding, transparent
> -            st->sample_aspect_ratio.num      = get_byte(pb);
> -            st->sample_aspect_ratio.den      = get_byte(pb);
> -            url_fskip(pb, 4); // source page width, height
> +
> +            data_size_skip -= 9;
> +
> +            if (data_size >= 11) {
> +                url_fskip(pb, 1); // masking
> +                compression                      = get_byte(pb);
> + 
> +                data_size_skip -= 2;
> +            }
> +            if (data_size >= 16) {
> +                url_fskip(pb, 3); // paddding, transparent
> +                st->sample_aspect_ratio.num      = get_byte(pb);
> +                st->sample_aspect_ratio.den      = get_byte(pb);
> + 
> +                data_size_skip -= 5;
> +            }

I'd wait before to review this as this patch also contains the
compatibility patch changes. Please try to use quilt/git when dealing
with such stack of patches.

Regards.
-- 
FFmpeg = Forgiving & Fostering Murdering Proud Extreme Gargoyle



More information about the ffmpeg-devel mailing list