Mercurial > libavcodec.hg
comparison mpeg12.c @ 10601:5bf8c18a9907 libavcodec
Start decoding from seq/gop too, not just I frames.
Possibly fixes issue1124.
author | michael |
---|---|
date | Mon, 30 Nov 2009 03:32:43 +0000 |
parents | 40af8390d83f |
children | ce2cf9e32b09 |
comparison
equal
deleted
inserted
replaced
10600:40af8390d83f | 10601:5bf8c18a9907 |
---|---|
1172 int slice_count; | 1172 int slice_count; |
1173 int swap_uv;//indicate VCR2 | 1173 int swap_uv;//indicate VCR2 |
1174 int save_aspect_info; | 1174 int save_aspect_info; |
1175 int save_width, save_height, save_progressive_seq; | 1175 int save_width, save_height, save_progressive_seq; |
1176 AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator | 1176 AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator |
1177 | 1177 int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame? |
1178 } Mpeg1Context; | 1178 } Mpeg1Context; |
1179 | 1179 |
1180 static av_cold int mpeg_decode_init(AVCodecContext *avctx) | 1180 static av_cold int mpeg_decode_init(AVCodecContext *avctx) |
1181 { | 1181 { |
1182 Mpeg1Context *s = avctx->priv_data; | 1182 Mpeg1Context *s = avctx->priv_data; |
2313 switch(start_code) { | 2313 switch(start_code) { |
2314 case SEQ_START_CODE: | 2314 case SEQ_START_CODE: |
2315 if(last_code == 0){ | 2315 if(last_code == 0){ |
2316 mpeg1_decode_sequence(avctx, buf_ptr, | 2316 mpeg1_decode_sequence(avctx, buf_ptr, |
2317 input_size); | 2317 input_size); |
2318 s->sync=1; | |
2318 }else{ | 2319 }else{ |
2319 av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code); | 2320 av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code); |
2320 } | 2321 } |
2321 break; | 2322 break; |
2322 | 2323 |
2373 case GOP_START_CODE: | 2374 case GOP_START_CODE: |
2374 if(last_code == 0){ | 2375 if(last_code == 0){ |
2375 s2->first_field=0; | 2376 s2->first_field=0; |
2376 mpeg_decode_gop(avctx, | 2377 mpeg_decode_gop(avctx, |
2377 buf_ptr, input_size); | 2378 buf_ptr, input_size); |
2379 s->sync=1; | |
2378 }else{ | 2380 }else{ |
2379 av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code); | 2381 av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code); |
2380 } | 2382 } |
2381 break; | 2383 break; |
2382 default: | 2384 default: |
2390 if(s2->pict_type==FF_B_TYPE){ | 2392 if(s2->pict_type==FF_B_TYPE){ |
2391 if(!s2->closed_gop) | 2393 if(!s2->closed_gop) |
2392 break; | 2394 break; |
2393 } | 2395 } |
2394 } | 2396 } |
2397 if(s2->pict_type==FF_I_TYPE) | |
2398 s->sync=1; | |
2395 if(s2->next_picture_ptr==NULL){ | 2399 if(s2->next_picture_ptr==NULL){ |
2396 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ | 2400 /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ |
2397 if(s2->pict_type==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; | 2401 if(s2->pict_type==FF_P_TYPE && !s->sync) break; |
2398 } | 2402 } |
2399 /* Skip B-frames if we are in a hurry. */ | 2403 /* Skip B-frames if we are in a hurry. */ |
2400 if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; | 2404 if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; |
2401 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) | 2405 if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) |
2402 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE) | 2406 ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE) |
2481 break; | 2485 break; |
2482 } | 2486 } |
2483 } | 2487 } |
2484 } | 2488 } |
2485 | 2489 |
2490 static void flush(AVCodecContext *avctx){ | |
2491 Mpeg1Context *s = avctx->priv_data; | |
2492 | |
2493 s->sync=0; | |
2494 | |
2495 ff_mpeg_flush(avctx); | |
2496 } | |
2497 | |
2486 static int mpeg_decode_end(AVCodecContext *avctx) | 2498 static int mpeg_decode_end(AVCodecContext *avctx) |
2487 { | 2499 { |
2488 Mpeg1Context *s = avctx->priv_data; | 2500 Mpeg1Context *s = avctx->priv_data; |
2489 | 2501 |
2490 if (s->mpeg_enc_ctx_allocated) | 2502 if (s->mpeg_enc_ctx_allocated) |
2500 mpeg_decode_init, | 2512 mpeg_decode_init, |
2501 NULL, | 2513 NULL, |
2502 mpeg_decode_end, | 2514 mpeg_decode_end, |
2503 mpeg_decode_frame, | 2515 mpeg_decode_frame, |
2504 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, | 2516 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
2505 .flush= ff_mpeg_flush, | 2517 .flush= flush, |
2506 .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), | 2518 .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), |
2507 }; | 2519 }; |
2508 | 2520 |
2509 AVCodec mpeg2video_decoder = { | 2521 AVCodec mpeg2video_decoder = { |
2510 "mpeg2video", | 2522 "mpeg2video", |
2514 mpeg_decode_init, | 2526 mpeg_decode_init, |
2515 NULL, | 2527 NULL, |
2516 mpeg_decode_end, | 2528 mpeg_decode_end, |
2517 mpeg_decode_frame, | 2529 mpeg_decode_frame, |
2518 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, | 2530 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
2519 .flush= ff_mpeg_flush, | 2531 .flush= flush, |
2520 .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), | 2532 .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), |
2521 }; | 2533 }; |
2522 | 2534 |
2523 //legacy decoder | 2535 //legacy decoder |
2524 AVCodec mpegvideo_decoder = { | 2536 AVCodec mpegvideo_decoder = { |
2529 mpeg_decode_init, | 2541 mpeg_decode_init, |
2530 NULL, | 2542 NULL, |
2531 mpeg_decode_end, | 2543 mpeg_decode_end, |
2532 mpeg_decode_frame, | 2544 mpeg_decode_frame, |
2533 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, | 2545 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, |
2534 .flush= ff_mpeg_flush, | 2546 .flush= flush, |
2535 .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), | 2547 .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), |
2536 }; | 2548 }; |
2537 | 2549 |
2538 #if CONFIG_MPEG_XVMC_DECODER | 2550 #if CONFIG_MPEG_XVMC_DECODER |
2539 static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ | 2551 static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ |
2560 mpeg_mc_decode_init, | 2572 mpeg_mc_decode_init, |
2561 NULL, | 2573 NULL, |
2562 mpeg_decode_end, | 2574 mpeg_decode_end, |
2563 mpeg_decode_frame, | 2575 mpeg_decode_frame, |
2564 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY, | 2576 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY, |
2565 .flush= ff_mpeg_flush, | 2577 .flush= flush, |
2566 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"), | 2578 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"), |
2567 }; | 2579 }; |
2568 | 2580 |
2569 #endif | 2581 #endif |
2570 | 2582 |
2577 mpeg_decode_init, | 2589 mpeg_decode_init, |
2578 NULL, | 2590 NULL, |
2579 mpeg_decode_end, | 2591 mpeg_decode_end, |
2580 mpeg_decode_frame, | 2592 mpeg_decode_frame, |
2581 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, | 2593 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, |
2582 .flush= ff_mpeg_flush, | 2594 .flush= flush, |
2583 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"), | 2595 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"), |
2584 }; | 2596 }; |
2585 #endif | 2597 #endif |
2586 | 2598 |
2587 #if CONFIG_MPEG1_VDPAU_DECODER | 2599 #if CONFIG_MPEG1_VDPAU_DECODER |
2593 mpeg_decode_init, | 2605 mpeg_decode_init, |
2594 NULL, | 2606 NULL, |
2595 mpeg_decode_end, | 2607 mpeg_decode_end, |
2596 mpeg_decode_frame, | 2608 mpeg_decode_frame, |
2597 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, | 2609 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, |
2598 .flush= ff_mpeg_flush, | 2610 .flush= flush, |
2599 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"), | 2611 .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"), |
2600 }; | 2612 }; |
2601 #endif | 2613 #endif |
2602 | 2614 |