From 33908f08377dd6abb219b4a080f65cb2eec938e6 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Thu, 27 Aug 2015 03:29:29 +0200 Subject: [PATCH] lavf/mov: Support unusual alac files without frma and alac atoms. Fixes ticket #4747. --- libavformat/mov.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index efde072c38..45367d39f7 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1436,6 +1436,32 @@ 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; + ret = ffio_ensure_seekback(pb, 8); + if (ret < 0) + return ret; + 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