[FFmpeg-devel] [PATCH] RealMedia muxer: support audio codecs other than AC-3

Michael Niedermayer michaelni
Sun May 9 22:56:07 CEST 2010


On Sun, May 09, 2010 at 03:48:25PM +0200, Francesco Lavra wrote:
> On Sat, 2010-05-08 at 19:14 +0200, Michael Niedermayer wrote:
> > On Sat, May 08, 2010 at 09:15:30AM +0200, Francesco Lavra wrote:
> > > [...]
> > the list is not 1:1 but n:n
> > one codec id can have multiple tags (ex: xvid/divx)
> > and one codec tag can have multiple ids (ex mpeg1/mpeg2)
> > you must check the values against the list
> 
> So the attached patches should be more correct. The changes to
> libavformat/utils.c are in two separate patches: the first one adds the
> two static functions find_avcodectag_from_id() and
> find_avcodectag_from_tag(), and redefines ff_codec_get_tag() and
> ff_codec_get_id() to use the new functions; the second patch adds the
> actual changes to av_write_header().
> 
> > also dont forget to test your code against the regression tests & fate
> 
> Since one regression test (jpegls) broke with this change,
> 01_jpegls.patch contains the necessary addition to riff.c to make the
> test pass.
> Also, I can't run fate since the fate suite folder in mplayerhq.hu (the
> entire samples folder, actually) is currently unavailable.
> 

>  riff.c |    1 +
>  1 file changed, 1 insertion(+)
> ff3a9dc205ca73d0481402456386de4451aada41  01_jpegls.patch
> Index: libavformat/riff.c
> ===================================================================
> --- libavformat/riff.c	(revision 23062)
> +++ libavformat/riff.c	(working copy)
> @@ -129,6 +129,7 @@
>      { CODEC_ID_LJPEG,        MKTAG('L', 'J', 'P', 'G') },
>      { CODEC_ID_MJPEG,        MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
>      { CODEC_ID_JPEGLS,       MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */
> +    { CODEC_ID_JPEGLS,       MKTAG('M', 'J', 'P', 'G') },
>      { CODEC_ID_MJPEG,        MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */
>      { CODEC_ID_MJPEG,        MKTAG('j', 'p', 'e', 'g') },
>      { CODEC_ID_MJPEG,        MKTAG('I', 'J', 'P', 'G') },

ok



>  utils.c |   29 ++++++++++++++++++++++++-----
>  1 file changed, 24 insertions(+), 5 deletions(-)
> ac17a932410847e0eac6b42bd8a7184ed2ec522a  02_utils.patch
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 23062)
> +++ libavformat/utils.c	(working copy)
> @@ -2023,30 +2023,49 @@
>      return ret;
>  }
>  
> -unsigned int ff_codec_get_tag(const AVCodecTag *tags, int id)
> +static const AVCodecTag *find_avcodectag_from_id(const AVCodecTag *tags, int id)
>  {
>      while (tags->id != CODEC_ID_NONE) {
>          if (tags->id == id)
> -            return tags->tag;
> +            return tags;
>          tags++;
>      }
>      return 0;
>  }
>  
> -enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
> +static const AVCodecTag *find_avcodectag_from_tag(const AVCodecTag *tags,
> +                                                  unsigned int tag)
>  {
>      int i;
>      for(i=0; tags[i].id != CODEC_ID_NONE;i++) {
>          if(tag == tags[i].tag)
> -            return tags[i].id;
> +            return tags + i;
>      }
>      for(i=0; tags[i].id != CODEC_ID_NONE; i++) {
>          if(   toupper((tag >> 0)&0xFF) == toupper((tags[i].tag >> 0)&0xFF)
>             && toupper((tag >> 8)&0xFF) == toupper((tags[i].tag >> 8)&0xFF)
>             && toupper((tag >>16)&0xFF) == toupper((tags[i].tag >>16)&0xFF)
>             && toupper((tag >>24)&0xFF) == toupper((tags[i].tag >>24)&0xFF))
> -            return tags[i].id;
> +            return tags + i;
>      }
> +    return 0;

return NULL


> +}
> +
> +unsigned int ff_codec_get_tag(const AVCodecTag *tags, int id)
> +{
> +    const AVCodecTag *avctag = find_avcodectag_from_id(tags, id);
> +
> +    if (avctag)
> +        return avctag->tag;
> +    return 0;
> +}
> +
> +enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
> +{
> +    const AVCodecTag *avctag = find_avcodectag_from_tag(tags, tag);
> +
> +    if (avctag)
> +        return avctag->id;
>      return CODEC_ID_NONE;
>  }
>  

>  utils.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 51 insertions(+), 5 deletions(-)
> 21388c149c24ae10c10565ce74cf1d75005e1f95  03_utils.patch
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 23062)
> +++ libavformat/utils.c	(working copy)
> @@ -2594,6 +2594,51 @@
>      return 0;
>  }
>  
> +static int validate_codec_tag(AVFormatContext *s, AVStream *st)
> +{
> +    const AVCodecTag *avctag;
> +    int n;
> +    enum CodecID id = CODEC_ID_NONE;
> +    unsigned int tag = 0;
> +
> +    /**
> +     * Check that tag + id is in the table
> +     * If neither is in the table -> OK
> +     * If tag is in the table with another id -> FAIL
> +     * If id is in the table with another tag -> FAIL unless strict < normal
> +     */
> +    for (n = 0; s->oformat->codec_tag[n]; n++) {

> +        avctag = find_avcodectag_from_tag(s->oformat->codec_tag[n],
> +                                          st->codec->codec_tag);
> +        while (avctag) {
> +            id = avctag->id;
> +            if (id == st->codec->codec_id)
> +                break;
> +            avctag = find_avcodectag_from_tag(avctag + 1, st->codec->codec_tag);
> +        }
> +        if (id == st->codec->codec_id)
> +            break;

a goto would simplify this

besides, iam not sure if it wouldnt be  simpler to just write a loop that
goes over all AVCodecTag and compares id and tag instead of trying to use 
find_avcodectag_from_tag() ...

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 1
"Used only once"    - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100509/56a9ea5f/attachment.pgp>



More information about the ffmpeg-devel mailing list