]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mjpegdec.c
mjpeg: interlaced buggy avid fix
[ffmpeg] / libavcodec / mjpegdec.c
index 4baacab7334e5bb94aa73817376f1c94c99e28a8..4a5b04672df870f693bde4472bb13f78102ec931 100644 (file)
@@ -108,8 +108,8 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
         init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
         if (ff_mjpeg_decode_dht(s)) {
-            av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table\n");
-            return AVERROR_INVALIDDATA;
+            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 &&
@@ -894,7 +894,8 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i
             }
 
             if (s->restart_interval) --s->restart_count;
-            if (s->restart_interval && show_bits(&s->gb, 8) == 0xFF){ /* skip RSTn */
+            i= 8+((-get_bits_count(&s->gb))&7);
+            if (s->restart_interval && show_bits(&s->gb, i)  == (1<<i)-1){ /* skip RSTn */
                 int pos= get_bits_count(&s->gb);
                 align_get_bits(&s->gb);
                 while(show_bits(&s->gb, 8) == 0xFF)
@@ -1121,9 +1122,8 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
             s->buggy_avid = 1;
 //        if (s->first_picture)
 //            printf("mjpeg: workarounding buggy AVID\n");
-        i = get_bits(&s->gb, 8);
-        if     (i==2) s->bottom_field= 1;
-        else if(i==1) s->bottom_field= 0;
+        i = get_bits(&s->gb, 8); len--;
+        av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i);
 #if 0
         skip_bits(&s->gb, 8);
         skip_bits(&s->gb, 32);
@@ -1446,10 +1446,6 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx,
 
                     s->restart_count = 0;
                     /* nothing to do on SOI */
-                    if (s->got_picture) {
-                        av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
-                        goto eoi_parser;
-                    }
                     break;
                 case DQT:
                     ff_mjpeg_decode_dqt(s);