[FFmpeg-cvslog] libavformat/mtv: make clear we assume bpp is always 16

Reynaldo H. Verdejo Pinochet git at videolan.org
Thu Jan 23 21:41:32 CET 2014


ffmpeg | branch: master | Reynaldo H. Verdejo Pinochet <r.verdejo at sisa.samsung.com> | Thu Jan 23 16:18:57 2014 -0300| [ba15aab4a4a296c632bd8d3428b002055109c7d1] | committer: Reynaldo H. Verdejo Pinochet

libavformat/mtv: make clear we assume bpp is always 16

All samples in the wild are RGB565/555 and we are already
acting on this assumption when pushing out the video frames,
so if we get anything != than 16 for bpp we just override
this value for doing any calculations making our approach
consistent.

Also avoid repeatedly shifting bpp.

Signed-off-by: Reynaldo H. Verdejo Pinochet <r.verdejo at sisa.samsung.com>

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

 libavformat/mtv.c |   28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/libavformat/mtv.c b/libavformat/mtv.c
index 0ce3f8e..250da00 100644
--- a/libavformat/mtv.c
+++ b/libavformat/mtv.c
@@ -32,6 +32,7 @@
 #define MTV_ASUBCHUNK_DATA_SIZE 500
 #define MTV_HEADER_SIZE 512
 #define MTV_AUDIO_PADDING_SIZE 12
+#define MTV_IMAGE_DEFAULT_BPP 16
 #define AUDIO_SAMPLING_RATE 44100
 
 typedef struct MTVDemuxContext {
@@ -75,8 +76,13 @@ static int mtv_probe(AVProbeData *p)
             return 0;
     }
 
-    if(p->buf[51] != 16)
-        return AVPROBE_SCORE_EXTENSION / 2; // But we are going to assume 16bpp anyway ..
+    /* Image bpp is not an absolutely required
+     * field as we latter claim it should be 16
+     * no matter what. All samples in the wild
+     * are RGB565/555.
+     */
+    if(p->buf[51] != MTV_IMAGE_DEFAULT_BPP)
+        return AVPROBE_SCORE_EXTENSION / 2;
 
     /* We had enough data to parse header values
      * but we expect to be able to get 512 bytes
@@ -102,22 +108,30 @@ static int mtv_read_header(AVFormatContext *s)
     mtv->audio_identifier  = avio_rl24(pb);
     mtv->audio_br          = avio_rl16(pb);
     mtv->img_colorfmt      = avio_rl24(pb);
-    mtv->img_bpp           = avio_r8(pb);
+    mtv->img_bpp           = avio_r8(pb)>>3;
     mtv->img_width         = avio_rl16(pb);
     mtv->img_height        = avio_rl16(pb);
     mtv->img_segment_size  = avio_rl16(pb);
 
+    /* Assume 16bpp even if claimed otherwise.
+     * We know its going to be RGBG565/555 anyway
+     */
+    if (mtv->img_bpp != MTV_IMAGE_DEFAULT_BPP) {
+        av_log (s, AV_LOG_WARNING, "Header claims %dbpp (!= 16). Ignoring\n",
+                mtv->img_bpp);
+        mtv->img_bpp = MTV_IMAGE_DEFAULT_BPP;
+    }
+
     /* Calculate width and height if missing from header */
 
-    if(mtv->img_bpp>>3){
     if(!mtv->img_width && mtv->img_height)
-        mtv->img_width=mtv->img_segment_size / (mtv->img_bpp>>3)
+        mtv->img_width=mtv->img_segment_size / (mtv->img_bpp)
                         / mtv->img_height;
 
     if(!mtv->img_height && mtv->img_width)
-        mtv->img_height=mtv->img_segment_size / (mtv->img_bpp>>3)
+        mtv->img_height=mtv->img_segment_size / (mtv->img_bpp)
                         / mtv->img_width;
-    }
+
     if(!mtv->img_height || !mtv->img_width || !mtv->img_segment_size){
         av_log(s, AV_LOG_ERROR, "width or height or segment_size is invalid and I cannot calculate them from other information\n");
         return AVERROR(EINVAL);



More information about the ffmpeg-cvslog mailing list