Mercurial > libavcodec.hg
comparison h264.c @ 5723:49a5d44423ef libavcodec
h264/PAFF preparation: use DELAYED_PIC_REF to mark non-refs frames as held for delayed output
patch by Jeff Downs, heydowns a borg d com
original thread:
Subject: [FFmpeg-devel] [PATCH] Implement PAFF in H.264
Date: 18/09/07 20:30
author | andoma |
---|---|
date | Wed, 26 Sep 2007 13:28:13 +0000 |
parents | f45228f65e06 |
children | 0591d5928fe8 |
comparison
equal
deleted
inserted
replaced
5722:d1707b860013 | 5723:49a5d44423ef |
---|---|
35 | 35 |
36 #include "cabac.h" | 36 #include "cabac.h" |
37 | 37 |
38 //#undef NDEBUG | 38 //#undef NDEBUG |
39 #include <assert.h> | 39 #include <assert.h> |
40 | |
41 /** | |
42 * Value of Picture.reference when Picture is not a reference picture, but | |
43 * is held for delayed output. | |
44 */ | |
45 #define DELAYED_PIC_REF 4 | |
40 | 46 |
41 static VLC coeff_token_vlc[4]; | 47 static VLC coeff_token_vlc[4]; |
42 static VLC chroma_dc_coeff_token_vlc; | 48 static VLC chroma_dc_coeff_token_vlc; |
43 | 49 |
44 static VLC total_zeros_vlc[15]; | 50 static VLC total_zeros_vlc[15]; |
3089 | 3095 |
3090 static inline void unreference_pic(H264Context *h, Picture *pic){ | 3096 static inline void unreference_pic(H264Context *h, Picture *pic){ |
3091 int i; | 3097 int i; |
3092 pic->reference=0; | 3098 pic->reference=0; |
3093 if(pic == h->delayed_output_pic) | 3099 if(pic == h->delayed_output_pic) |
3094 pic->reference=1; | 3100 pic->reference=DELAYED_PIC_REF; |
3095 else{ | 3101 else{ |
3096 for(i = 0; h->delayed_pic[i]; i++) | 3102 for(i = 0; h->delayed_pic[i]; i++) |
3097 if(pic == h->delayed_pic[i]){ | 3103 if(pic == h->delayed_pic[i]){ |
3098 pic->reference=1; | 3104 pic->reference=DELAYED_PIC_REF; |
3099 break; | 3105 break; |
3100 } | 3106 } |
3101 } | 3107 } |
3102 } | 3108 } |
3103 | 3109 |
3540 int num_ref_idx_active_override_flag; | 3546 int num_ref_idx_active_override_flag; |
3541 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; | 3547 static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; |
3542 unsigned int slice_type, tmp, i; | 3548 unsigned int slice_type, tmp, i; |
3543 int default_ref_list_done = 0; | 3549 int default_ref_list_done = 0; |
3544 | 3550 |
3545 s->current_picture.reference= h->nal_ref_idc != 0; | |
3546 s->dropable= h->nal_ref_idc == 0; | 3551 s->dropable= h->nal_ref_idc == 0; |
3547 | 3552 |
3548 first_mb_in_slice= get_ue_golomb(&s->gb); | 3553 first_mb_in_slice= get_ue_golomb(&s->gb); |
3549 | 3554 |
3550 if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){ | 3555 if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){ |
3650 av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, | 3655 av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, |
3651 s->avctx->time_base.num, s->avctx->time_base.den, 1<<30); | 3656 s->avctx->time_base.num, s->avctx->time_base.den, 1<<30); |
3652 } | 3657 } |
3653 } | 3658 } |
3654 | 3659 |
3655 if(h0->current_slice == 0){ | |
3656 if(frame_start(h) < 0) | |
3657 return -1; | |
3658 } | |
3659 if(h != h0) | |
3660 clone_slice(h, h0); | |
3661 | |
3662 s->current_picture_ptr->frame_num= //FIXME frame_num cleanup | |
3663 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); | 3660 h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); |
3664 | 3661 |
3665 h->mb_mbaff = 0; | 3662 h->mb_mbaff = 0; |
3666 h->mb_aff_frame = 0; | 3663 h->mb_aff_frame = 0; |
3667 if(h->sps.frame_mbs_only_flag){ | 3664 if(h->sps.frame_mbs_only_flag){ |
3673 } else { | 3670 } else { |
3674 s->picture_structure= PICT_FRAME; | 3671 s->picture_structure= PICT_FRAME; |
3675 h->mb_aff_frame = h->sps.mb_aff; | 3672 h->mb_aff_frame = h->sps.mb_aff; |
3676 } | 3673 } |
3677 } | 3674 } |
3675 | |
3676 if(h0->current_slice == 0){ | |
3677 if(frame_start(h) < 0) | |
3678 return -1; | |
3679 } | |
3680 if(h != h0) | |
3681 clone_slice(h, h0); | |
3682 | |
3683 s->current_picture_ptr->frame_num= h->frame_num; //FIXME frame_num cleanup | |
3684 | |
3678 assert(s->mb_num == s->mb_width * s->mb_height); | 3685 assert(s->mb_num == s->mb_width * s->mb_height); |
3679 if(first_mb_in_slice << h->mb_aff_frame >= s->mb_num || | 3686 if(first_mb_in_slice << h->mb_aff_frame >= s->mb_num || |
3680 first_mb_in_slice >= s->mb_num){ | 3687 first_mb_in_slice >= s->mb_num){ |
3681 av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); | 3688 av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); |
3682 return -1; | 3689 return -1; |
3761 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE) | 3768 else if(h->pps.weighted_bipred_idc==2 && h->slice_type==B_TYPE) |
3762 implicit_weight_table(h); | 3769 implicit_weight_table(h); |
3763 else | 3770 else |
3764 h->use_weight = 0; | 3771 h->use_weight = 0; |
3765 | 3772 |
3766 if(s->current_picture.reference) | 3773 if(h->nal_ref_idc) |
3767 decode_ref_pic_marking(h0, &s->gb); | 3774 decode_ref_pic_marking(h0, &s->gb); |
3768 | 3775 |
3769 if(FRAME_MBAFF) | 3776 if(FRAME_MBAFF) |
3770 fill_mbaff_ref_list(h); | 3777 fill_mbaff_ref_list(h); |
3771 | 3778 |
3861 h->use_weight, | 3868 h->use_weight, |
3862 h->use_weight==1 && h->use_weight_chroma ? "c" : "" | 3869 h->use_weight==1 && h->use_weight_chroma ? "c" : "" |
3863 ); | 3870 ); |
3864 } | 3871 } |
3865 | 3872 |
3866 if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !s->current_picture.reference){ | 3873 if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){ |
3867 s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; | 3874 s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; |
3868 s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; | 3875 s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; |
3869 }else{ | 3876 }else{ |
3870 s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; | 3877 s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; |
3871 s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; | 3878 s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; |
7359 s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264; | 7366 s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264; |
7360 s->current_picture_ptr->pict_type= s->pict_type; | 7367 s->current_picture_ptr->pict_type= s->pict_type; |
7361 | 7368 |
7362 h->prev_frame_num_offset= h->frame_num_offset; | 7369 h->prev_frame_num_offset= h->frame_num_offset; |
7363 h->prev_frame_num= h->frame_num; | 7370 h->prev_frame_num= h->frame_num; |
7364 if(s->current_picture_ptr->reference){ | 7371 if(s->current_picture_ptr->reference & s->picture_structure){ |
7365 h->prev_poc_msb= h->poc_msb; | 7372 h->prev_poc_msb= h->poc_msb; |
7366 h->prev_poc_lsb= h->poc_lsb; | 7373 h->prev_poc_lsb= h->poc_lsb; |
7367 } | |
7368 if(s->current_picture_ptr->reference) | |
7369 execute_ref_pic_marking(h, h->mmco, h->mmco_index); | 7374 execute_ref_pic_marking(h, h->mmco, h->mmco_index); |
7375 } | |
7370 | 7376 |
7371 ff_er_frame_end(s); | 7377 ff_er_frame_end(s); |
7372 | 7378 |
7373 MPV_frame_end(s); | 7379 MPV_frame_end(s); |
7374 | 7380 |
7390 | 7396 |
7391 assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0])); | 7397 assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0])); |
7392 | 7398 |
7393 h->delayed_pic[pics++] = cur; | 7399 h->delayed_pic[pics++] = cur; |
7394 if(cur->reference == 0) | 7400 if(cur->reference == 0) |
7395 cur->reference = 1; | 7401 cur->reference = DELAYED_PIC_REF; |
7396 | 7402 |
7397 cross_idr = 0; | 7403 cross_idr = 0; |
7398 for(i=0; h->delayed_pic[i]; i++) | 7404 for(i=0; h->delayed_pic[i]; i++) |
7399 if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0) | 7405 if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0) |
7400 cross_idr = 1; | 7406 cross_idr = 1; |
7431 | 7437 |
7432 if(prev == out) | 7438 if(prev == out) |
7433 *data_size = 0; | 7439 *data_size = 0; |
7434 else | 7440 else |
7435 *data_size = sizeof(AVFrame); | 7441 *data_size = sizeof(AVFrame); |
7436 if(prev && prev != out && prev->reference == 1) | 7442 if(prev && prev != out && prev->reference == DELAYED_PIC_REF) |
7437 prev->reference = 0; | 7443 prev->reference = 0; |
7438 h->delayed_output_pic = out; | 7444 h->delayed_output_pic = out; |
7439 #endif | 7445 #endif |
7440 | 7446 |
7441 if(out) | 7447 if(out) |