[FFmpeg-devel] [PATCH]lavf/mov: Support alac extradata in wave atom v2

Carl Eugen Hoyos cehoyos at ag.or.at
Wed Aug 5 23:52:43 CEST 2015


On Wednesday 05 August 2015 02:39:38 pm Michael Niedermayer wrote:
> On Mon, Aug 03, 2015 at 11:16:12PM +0200, Carl Eugen Hoyos wrote:
> > Hi!
> >
> > Attached patch fixes ticket #4747 and should not introduce any
> > theoretical regressions.
> >
> > Please review, Carl Eugen
> >
> >  mov.c |   22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> > ffe1a030382f6bc11a5a58ab3cd5e89f8a354529  patchalacwave2.diff
> > diff --git a/libavformat/mov.c b/libavformat/mov.c
> > index 154d2f8..f3cb71f 100644
> > --- a/libavformat/mov.c
> > +++ b/libavformat/mov.c
> > @@ -1435,6 +1435,28 @@ static int mov_read_wave(MOVContext *c,
> > AVIOContext *pb, MOVAtom atom) if (ret < 0)
> >              return ret;
> >      } else if (atom.size > 8) { /* to read frma, esds atoms */
> > +        if (st->codec->codec_id == AV_CODEC_ID_ALAC && atom.size >= 24)
> > { +            uint64_t buffer = avio_rb64(pb);
> > +            atom.size -= 8;
> > +            if (  (buffer & 0xFFFFFFFF) == MKBETAG('f','r','m','a')
> > +                && buffer >> 32 <= atom.size
> > +                && buffer >> 32 >= 8) {
> > +                avio_skip(pb, (buffer >> 32) - 8);
> > +                atom.size -= (buffer >> 32) - 8;
>
> skiping the frma atom instead of passing it to mov_read_default()
> (which might at some point in the future do somehing with it)
> does not feel completely ideal

New patch attached.

Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 154d2f8..157c5c1 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1417,7 +1417,8 @@ static int mov_read_svq3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
-    int ret;
+    int ret, seek_back = 0;
+    int64_t position;
 
     if (c->fc->nb_streams < 1)
         return 0;
@@ -1435,8 +1436,26 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         if (ret < 0)
             return ret;
     } else if (atom.size > 8) { /* to read frma, esds atoms */
+        if (   st->codec->codec_id == AV_CODEC_ID_ALAC
+            && atom.size >= 24
+            && !ffio_ensure_seekback(pb, atom.size)) {
+            seek_back = 1;
+            position = avio_tell(pb);
+        }
         if ((ret = mov_read_default(c, pb, atom)) < 0)
             return ret;
+        if (seek_back && !st->codec->extradata_size) {
+            av_assert0(position == avio_seek(pb, position, SEEK_SET));
+#define ALAC_EXTRADATA_SIZE 36
+            st->codec->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
+            if (!st->codec->extradata)
+                return AVERROR(ENOMEM);
+            st->codec->extradata_size = ALAC_EXTRADATA_SIZE;
+            AV_WB32(st->codec->extradata    , ALAC_EXTRADATA_SIZE);
+            AV_WB32(st->codec->extradata + 4, MKTAG('a','l','a','c'));
+            avio_read(pb, st->codec->extradata + 12, 24);
+            avio_skip(pb, atom.size - 24);
+        }
     } else
         avio_skip(pb, atom.size);
     return 0;


More information about the ffmpeg-devel mailing list