[FFmpeg-devel] [PATCH]lavf/mov: Support alac extradata in wave atom v2
Michael Niedermayer
michael at niedermayer.cc
Thu Aug 6 11:15:40 CEST 2015
On Wed, Aug 05, 2015 at 11:52:43PM +0200, Carl Eugen Hoyos wrote:
> 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
> mov.c | 21 ++++++++++++++++++++-
> 1 file changed, 20 insertions(+), 1 deletion(-)
> d078903c9066e864496f9f29d8761030f001a1d7 patchalacwave3.diff
> 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);
> + }
this assumes that mov_read_default() does not seek outside the atom
i had more thought about something like below
but maybe iam missing something
@@ -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;
+ ffio_ensure_seekback(pb, 8);
+ 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, - 8);
+ atom.size += 8;
+ } else if (!st->codec->extradata_size) {
+#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'));
+ AV_WB64(st->codec->extradata + 12, buffer);
+ avio_read(pb, st->codec->extradata + 20, 16);
+ avio_skip(pb, atom.size - 24);
+ return 0;
+ }
+ }
if ((ret = mov_read_default(c, pb, atom)) < 0)
return ret;
} else
> } else
> avio_skip(pb, atom.size);
> return 0;
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who are best at talking, realize last or never when they are wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150806/be07bcfb/attachment.sig>
More information about the ffmpeg-devel
mailing list