]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpeg12.c
allows calling avcodec_find_(en|de)coder_by_name with NULL parameter
[ffmpeg] / libavcodec / mpeg12.c
index 966fa489013d2444917cad65ed83f4c3e3be6054..7d818639249309ef9b56e2a3811bef5b49a17078 100644 (file)
@@ -1344,7 +1344,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
     if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) {
         s->full_pel[0] = get_bits1(&s->gb);
         f_code = get_bits(&s->gb, 3);
-        if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
+        if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT)
             return -1;
         s->mpeg_f_code[0][0] = f_code;
         s->mpeg_f_code[0][1] = f_code;
@@ -1352,7 +1352,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx,
     if (s->pict_type == FF_B_TYPE) {
         s->full_pel[1] = get_bits1(&s->gb);
         f_code = get_bits(&s->gb, 3);
-        if (f_code == 0 && avctx->error_resilience >= FF_ER_COMPLIANT)
+        if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT)
             return -1;
         s->mpeg_f_code[1][0] = f_code;
         s->mpeg_f_code[1][1] = f_code;
@@ -1501,13 +1501,28 @@ static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
     }
 }
 
-static void mpeg_decode_picture_coding_extension(MpegEncContext *s)
+static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
 {
+    MpegEncContext *s= &s1->mpeg_enc_ctx;
+
     s->full_pel[0] = s->full_pel[1] = 0;
     s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
     s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
     s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
     s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
+    if(!s->pict_type && s1->mpeg_enc_ctx_allocated){
+        av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code, guessing missing values\n");
+        if(s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1]==15){
+            if(s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
+                s->pict_type= FF_I_TYPE;
+            else
+                s->pict_type= FF_P_TYPE;
+        }else
+            s->pict_type= FF_B_TYPE;
+        s->current_picture.pict_type= s->pict_type;
+        s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
+        s->first_slice= 1;
+    }
     s->intra_dc_precision = get_bits(&s->gb, 2);
     s->picture_structure = get_bits(&s->gb, 2);
     s->top_field_first = get_bits1(&s->gb);
@@ -1573,7 +1588,7 @@ static void mpeg_decode_extension(AVCodecContext *avctx,
         mpeg_decode_picture_display_extension(s1);
         break;
     case 0x8:
-        mpeg_decode_picture_coding_extension(s);
+        mpeg_decode_picture_coding_extension(s1);
         break;
     }
 }
@@ -1776,7 +1791,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
                             && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/;
 
                 if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
-                   || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){
+                   || (avctx->error_recognition >= FF_ER_AGGRESSIVE && left>8)){
                     av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
                     return -1;
                 }else
@@ -1947,7 +1962,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
     s->aspect_ratio_info= get_bits(&s->gb, 4);
     if (s->aspect_ratio_info == 0) {
         av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
-        if (avctx->error_resilience >= FF_ER_COMPLIANT)
+        if (avctx->error_recognition >= FF_ER_COMPLIANT)
             return -1;
     }
     s->frame_rate_index = get_bits(&s->gb, 4);
@@ -2293,6 +2308,7 @@ static int decode_chunks(AVCodecContext *avctx,
                         *data_size = sizeof(AVPicture);
                 }
             }
+            s2->pict_type= 0;
             return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
         }
 
@@ -2311,8 +2327,9 @@ static int decode_chunks(AVCodecContext *avctx,
 
         case PICTURE_START_CODE:
             /* we have a complete image: we try to decompress it */
-            mpeg1_decode_picture(avctx,
-                                    buf_ptr, input_size);
+            if(mpeg1_decode_picture(avctx,
+                                    buf_ptr, input_size) < 0)
+                s2->pict_type=0;
             break;
         case EXT_START_CODE:
             mpeg_decode_extension(avctx,
@@ -2356,6 +2373,11 @@ static int decode_chunks(AVCodecContext *avctx,
                         break;
                 }
 
+                if(!s2->pict_type){
+                    av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n");
+                    break;
+                }
+
                 if(s2->first_slice){
                     s2->first_slice=0;
                             if(mpeg_field_start(s2) < 0)