Commit 37a558fe authored by Ivan Schreter's avatar Ivan Schreter Committed by Carl Eugen Hoyos

Add SEI recovery point frame counter to H264Context and use it when

setting key_frame.

Patch by Ivan Schreter schreter A gmx D net

Originally committed as revision 17109 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent ed761067
...@@ -2208,6 +2208,7 @@ static av_cold int decode_init(AVCodecContext *avctx){ ...@@ -2208,6 +2208,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
h->thread_context[0] = h; h->thread_context[0] = h;
h->outputed_poc = INT_MIN; h->outputed_poc = INT_MIN;
h->prev_poc_msb= 1<<16; h->prev_poc_msb= 1<<16;
h->sei_recovery_frame_cnt = -1;
return 0; return 0;
} }
...@@ -3141,6 +3142,7 @@ static void flush_dpb(AVCodecContext *avctx){ ...@@ -3141,6 +3142,7 @@ static void flush_dpb(AVCodecContext *avctx){
if(h->s.current_picture_ptr) if(h->s.current_picture_ptr)
h->s.current_picture_ptr->reference= 0; h->s.current_picture_ptr->reference= 0;
h->s.first_field= 0; h->s.first_field= 0;
h->sei_recovery_frame_cnt = -1;
ff_mpeg_flush(avctx); ff_mpeg_flush(avctx);
} }
...@@ -6848,6 +6850,15 @@ static int decode_unregistered_user_data(H264Context *h, int size){ ...@@ -6848,6 +6850,15 @@ static int decode_unregistered_user_data(H264Context *h, int size){
return 0; return 0;
} }
static int decode_recovery_point(H264Context *h){
MpegEncContext * const s = &h->s;
h->sei_recovery_frame_cnt = get_ue_golomb(&s->gb);
skip_bits(&s->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */
return 0;
}
static int decode_sei(H264Context *h){ static int decode_sei(H264Context *h){
MpegEncContext * const s = &h->s; MpegEncContext * const s = &h->s;
...@@ -6873,6 +6884,10 @@ static int decode_sei(H264Context *h){ ...@@ -6873,6 +6884,10 @@ static int decode_sei(H264Context *h){
if(decode_unregistered_user_data(h, size) < 0) if(decode_unregistered_user_data(h, size) < 0)
return -1; return -1;
break; break;
case SEI_TYPE_RECOVERY_POINT:
if(decode_recovery_point(h) < 0)
return -1;
break;
default: default:
skip_bits(&s->gb, 8*size); skip_bits(&s->gb, 8*size);
} }
...@@ -7431,7 +7446,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ ...@@ -7431,7 +7446,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
if((err = decode_slice_header(hx, h))) if((err = decode_slice_header(hx, h)))
break; break;
s->current_picture_ptr->key_frame|= (hx->nal_unit_type == NAL_IDR_SLICE); s->current_picture_ptr->key_frame |=
(hx->nal_unit_type == NAL_IDR_SLICE) ||
(h->sei_recovery_frame_cnt >= 0);
if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5 if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5
&& (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)
&& (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE)
...@@ -7668,6 +7685,7 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -7668,6 +7685,7 @@ static int decode_frame(AVCodecContext *avctx,
ff_er_frame_end(s); ff_er_frame_end(s);
MPV_frame_end(s); MPV_frame_end(s);
h->sei_recovery_frame_cnt = -1;
if (cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) { if (cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) {
/* Wait for second field. */ /* Wait for second field. */
......
...@@ -500,6 +500,15 @@ typedef struct H264Context{ ...@@ -500,6 +500,15 @@ typedef struct H264Context{
*/ */
SEI_PicStructType sei_pic_struct; SEI_PicStructType sei_pic_struct;
/**
* recovery_frame_cnt from SEI message
*
* Set to -1 if no recovery point SEI message found or to number of frames
* before playback synchronizes. Frames having recovery point are key
* frames.
*/
int sei_recovery_frame_cnt;
int is_complex; int is_complex;
int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment