comparison mpeg12.c @ 7935:21df17686936 libavcodec

Guess picture type from picture coding extension when the main header is damaged.
author michael
date Sun, 28 Sep 2008 23:19:12 +0000
parents 8195c970d077
children a9734fe0811e
comparison
equal deleted inserted replaced
7934:9daf67c7e880 7935:21df17686936
1499 s->chroma_inter_matrix[j] = v; 1499 s->chroma_inter_matrix[j] = v;
1500 } 1500 }
1501 } 1501 }
1502 } 1502 }
1503 1503
1504 static void mpeg_decode_picture_coding_extension(MpegEncContext *s) 1504 static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
1505 { 1505 {
1506 MpegEncContext *s= &s1->mpeg_enc_ctx;
1507
1506 s->full_pel[0] = s->full_pel[1] = 0; 1508 s->full_pel[0] = s->full_pel[1] = 0;
1507 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4); 1509 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
1508 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4); 1510 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
1509 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4); 1511 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
1510 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4); 1512 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
1513 if(!s->pict_type && s1->mpeg_enc_ctx_allocated){
1514 av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code, guessing missing values\n");
1515 if(s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1]==15){
1516 if(s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
1517 s->pict_type= FF_I_TYPE;
1518 else
1519 s->pict_type= FF_P_TYPE;
1520 }else
1521 s->pict_type= FF_B_TYPE;
1522 s->current_picture.pict_type= s->pict_type;
1523 s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
1524 s->first_slice= 1;
1525 }
1511 s->intra_dc_precision = get_bits(&s->gb, 2); 1526 s->intra_dc_precision = get_bits(&s->gb, 2);
1512 s->picture_structure = get_bits(&s->gb, 2); 1527 s->picture_structure = get_bits(&s->gb, 2);
1513 s->top_field_first = get_bits1(&s->gb); 1528 s->top_field_first = get_bits1(&s->gb);
1514 s->frame_pred_frame_dct = get_bits1(&s->gb); 1529 s->frame_pred_frame_dct = get_bits1(&s->gb);
1515 s->concealment_motion_vectors = get_bits1(&s->gb); 1530 s->concealment_motion_vectors = get_bits1(&s->gb);
1571 break; 1586 break;
1572 case 0x7: 1587 case 0x7:
1573 mpeg_decode_picture_display_extension(s1); 1588 mpeg_decode_picture_display_extension(s1);
1574 break; 1589 break;
1575 case 0x8: 1590 case 0x8:
1576 mpeg_decode_picture_coding_extension(s); 1591 mpeg_decode_picture_coding_extension(s1);
1577 break; 1592 break;
1578 } 1593 }
1579 } 1594 }
1580 1595
1581 static void exchange_uv(MpegEncContext *s){ 1596 static void exchange_uv(MpegEncContext *s){
2291 if (slice_end(avctx, picture)) { 2306 if (slice_end(avctx, picture)) {
2292 if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice 2307 if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
2293 *data_size = sizeof(AVPicture); 2308 *data_size = sizeof(AVPicture);
2294 } 2309 }
2295 } 2310 }
2311 s2->pict_type= 0;
2296 return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); 2312 return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
2297 } 2313 }
2298 2314
2299 input_size = buf_end - buf_ptr; 2315 input_size = buf_end - buf_ptr;
2300 2316
2309 input_size); 2325 input_size);
2310 break; 2326 break;
2311 2327
2312 case PICTURE_START_CODE: 2328 case PICTURE_START_CODE:
2313 /* we have a complete image: we try to decompress it */ 2329 /* we have a complete image: we try to decompress it */
2314 mpeg1_decode_picture(avctx, 2330 if(mpeg1_decode_picture(avctx,
2315 buf_ptr, input_size); 2331 buf_ptr, input_size) < 0)
2332 s2->pict_type=0;
2316 break; 2333 break;
2317 case EXT_START_CODE: 2334 case EXT_START_CODE:
2318 mpeg_decode_extension(avctx, 2335 mpeg_decode_extension(avctx,
2319 buf_ptr, input_size); 2336 buf_ptr, input_size);
2320 break; 2337 break;
2354 if(s2->codec_id == CODEC_ID_MPEG2VIDEO){ 2371 if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
2355 if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom) 2372 if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
2356 break; 2373 break;
2357 } 2374 }
2358 2375
2376 if(!s2->pict_type){
2377 av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n");
2378 break;
2379 }
2380
2359 if(s2->first_slice){ 2381 if(s2->first_slice){
2360 s2->first_slice=0; 2382 s2->first_slice=0;
2361 if(mpeg_field_start(s2) < 0) 2383 if(mpeg_field_start(s2) < 0)
2362 return -1; 2384 return -1;
2363 } 2385 }