[FFmpeg-cvslog] asfdec: Account for different Format Data sizes

Alexandra Hájková git at videolan.org
Thu Aug 16 00:49:31 EEST 2018


ffmpeg | branch: release/3.2 | Alexandra Hájková <alexandra.khirnova at gmail.com> | Wed Feb  8 12:51:37 2017 +0100| [32e8eed1ae5fe694c070dacfa517295be786dfbe] | committer: James Almer

asfdec: Account for different Format Data sizes

Some muxers may use the BMP_HEADER Format Data size instead
of the ASF-specific one.

Signed-off-by: Diego Biurrun <diego at biurrun.de>
(cherry picked from commit 42f27d1b8eab9ea88d2e9faeb35f72dd72eca7b4)
Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=32e8eed1ae5fe694c070dacfa517295be786dfbe
---

 libavformat/asfdec_o.c | 12 +++++++-----
 libavformat/riff.h     |  3 ++-
 libavformat/riffdec.c  |  7 ++++---
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index 56f8446b5f..593c010204 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -691,20 +691,22 @@ static int asf_read_properties(AVFormatContext *s, const GUIDParseTable *g)
 
 static int parse_video_info(AVIOContext *pb, AVStream *st)
 {
-    uint16_t size;
+    uint16_t size_asf; // ASF-specific Format Data size
+    uint32_t size_bmp; // BMP_HEADER-specific Format Data size
     unsigned int tag;
 
     st->codecpar->width  = avio_rl32(pb);
     st->codecpar->height = avio_rl32(pb);
     avio_skip(pb, 1); // skip reserved flags
-    size = avio_rl16(pb); // size of the Format Data
-    tag  = ff_get_bmp_header(pb, st, NULL);
+    size_asf = avio_rl16(pb);
+    tag = ff_get_bmp_header(pb, st, &size_bmp);
     st->codecpar->codec_tag = tag;
     st->codecpar->codec_id  = ff_codec_get_id(ff_codec_bmp_tags, tag);
+    size_bmp = FFMAX(size_asf, size_bmp);
 
-    if (size > BMP_HEADER_SIZE) {
+    if (size_bmp > BMP_HEADER_SIZE) {
         int ret;
-        st->codecpar->extradata_size  = size - BMP_HEADER_SIZE;
+        st->codecpar->extradata_size  = size_bmp - BMP_HEADER_SIZE;
         if (!(st->codecpar->extradata = av_malloc(st->codecpar->extradata_size +
                                                AV_INPUT_BUFFER_PADDING_SIZE))) {
             st->codecpar->extradata_size = 0;
diff --git a/libavformat/riff.h b/libavformat/riff.h
index fe87e81933..995867a989 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -41,9 +41,10 @@ void ff_end_tag(AVIOContext *pb, int64_t start);
 /**
  * Read BITMAPINFOHEADER structure and set AVStream codec width, height and
  * bits_per_encoded_sample fields. Does not read extradata.
+ * Writes the size of the BMP file to *size.
  * @return codec tag
  */
-int ff_get_bmp_header(AVIOContext *pb, AVStream *st, unsigned *esize);
+int ff_get_bmp_header(AVIOContext *pb, AVStream *st, uint32_t *size);
 
 void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, const AVCodecTag *tags, int for_asf, int ignore_extradata);
 
diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c
index 1602c31169..8e9827f65b 100644
--- a/libavformat/riffdec.c
+++ b/libavformat/riffdec.c
@@ -205,11 +205,12 @@ enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps)
     return id;
 }
 
-int ff_get_bmp_header(AVIOContext *pb, AVStream *st, unsigned *esize)
+int ff_get_bmp_header(AVIOContext *pb, AVStream *st, uint32_t *size)
 {
     int tag1;
-    if(esize) *esize  = avio_rl32(pb);
-    else                avio_rl32(pb);
+    uint32_t size_ = avio_rl32(pb);
+    if (size)
+        *size = size_;
     st->codecpar->width  = avio_rl32(pb);
     st->codecpar->height = (int32_t)avio_rl32(pb);
     avio_rl16(pb); /* planes */



More information about the ffmpeg-cvslog mailing list