changeset 5068:93e369c55c31 libavcodec

fix mjpeg decoding with broken huffman table headers
author ods15
date Wed, 23 May 2007 18:41:34 +0000
parents 6166fbf375cc
children 341a60a511ab
files mjpegdec.c
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mjpegdec.c	Wed May 23 14:55:13 2007 +0000
+++ b/mjpegdec.c	Wed May 23 18:41:34 2007 +0000
@@ -62,6 +62,17 @@
     return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
 }
 
+static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) {
+    build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
+              ff_mjpeg_val_dc_luminance, 12, 0, 0);
+    build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
+              ff_mjpeg_val_dc_chrominance, 12, 0, 0);
+    build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
+              ff_mjpeg_val_ac_luminance, 251, 0, 1);
+    build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
+              ff_mjpeg_val_ac_chrominance, 251, 0, 1);
+}
+
 int ff_mjpeg_decode_init(AVCodecContext *avctx)
 {
     MJpegDecodeContext *s = avctx->priv_data;
@@ -75,21 +86,16 @@
     s->first_picture = 1;
     s->org_height = avctx->coded_height;
 
-    build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
-              ff_mjpeg_val_dc_luminance, 12, 0, 0);
-    build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
-              ff_mjpeg_val_dc_chrominance, 12, 0, 0);
-    build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
-              ff_mjpeg_val_ac_luminance, 251, 0, 1);
-    build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
-              ff_mjpeg_val_ac_chrominance, 251, 0, 1);
+    build_basic_mjpeg_vlc(s);
 
     if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
     {
         av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
         init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
-        ff_mjpeg_decode_dht(s);
-        /* should check for error - but dunno */
+        if (ff_mjpeg_decode_dht(s)) {
+            av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n");
+            build_basic_mjpeg_vlc(s);
+        }
     }
     if (avctx->extradata_size > 9 &&
         AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) {