From f1ccd076801444ab7f524cb13e0886faaf10fd50 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 30 Nov 2015 10:44:39 +0100 Subject: [PATCH] h264: do not call frame_start() for missing frames We do not need to do a full setup like for a real frame, just allocate a buffer and set cur_pic(_ptr). --- libavcodec/h264_slice.c | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 4f2d6a895b..48d520b2a0 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -290,6 +290,33 @@ static int find_unused_picture(H264Context *h) return i; } +static int initialize_cur_frame(H264Context *h) +{ + H264Picture *cur; + int ret; + + release_unused_pictures(h, 1); + ff_h264_unref_picture(h, &h->cur_pic); + h->cur_pic_ptr = NULL; + + ret = find_unused_picture(h); + if (ret < 0) { + av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); + return ret; + } + cur = &h->DPB[ret]; + + ret = alloc_picture(h, cur); + if (ret < 0) + return ret; + + ret = ff_h264_ref_picture(h, &h->cur_pic, cur); + if (ret < 0) + return ret; + h->cur_pic_ptr = cur; + + return 0; +} static void init_dequant8_coeff_table(H264Context *h) { @@ -540,16 +567,11 @@ static int h264_frame_start(H264Context *h) int i, ret; const int pixel_shift = h->pixel_shift; - release_unused_pictures(h, 1); - h->cur_pic_ptr = NULL; - - i = find_unused_picture(h); - if (i < 0) { - av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); - return i; - } - pic = &h->DPB[i]; + ret = initialize_cur_frame(h); + if (ret < 0) + return ret; + pic = h->cur_pic_ptr; pic->reference = h->droppable ? 0 : h->picture_structure; pic->f->coded_picture_number = h->coded_picture_number++; pic->field_picture = h->picture_structure != PICT_FRAME; @@ -563,14 +585,6 @@ static int h264_frame_start(H264Context *h) pic->mmco_reset = 0; pic->recovered = 0; - if ((ret = alloc_picture(h, pic)) < 0) - return ret; - - h->cur_pic_ptr = pic; - ff_h264_unref_picture(h, &h->cur_pic); - if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0) - return ret; - if (CONFIG_ERROR_RESILIENCE && h->enable_er) ff_er_frame_start(&h->slice_ctx[0].er); @@ -1336,7 +1350,7 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl) H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); - ret = h264_frame_start(h); + ret = initialize_cur_frame(h); if (ret < 0) { h->first_field = 0; return ret;