From patchwork Tue Jan 17 09:50:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 2229 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp444097vsb; Tue, 17 Jan 2017 01:50:44 -0800 (PST) X-Received: by 10.223.165.1 with SMTP id i1mr7903931wrb.82.1484646644578; Tue, 17 Jan 2017 01:50:44 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a17si24420539wrd.133.2017.01.17.01.50.44; Tue, 17 Jan 2017 01:50:44 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6739A68A0E7; Tue, 17 Jan 2017 11:50:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from golem.pkh.me (LStLambert-657-1-117-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9F7E68A09E for ; Tue, 17 Jan 2017 11:50:25 +0200 (EET) Received: from localhost (golem.pkh.me [local]) by golem.pkh.me (OpenSMTPD) with ESMTPA id bbdd51fd; Tue, 17 Jan 2017 09:50:35 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Jan 2017 10:50:31 +0100 Message-Id: <20170117095031.5558-1-u@pkh.me> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/h264dec: remove flush goto in decode callback X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Clément Bœsch --- libavcodec/h264dec.c | 70 +++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 0cb0352485..0232bbaa23 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -1090,6 +1090,39 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g return 0; } +static int send_next_delayed_frame(H264Context *h, AVFrame *dst_frame, + int *got_frame, int buf_index) +{ + int ret, i, out_idx; + H264Picture *out = h->delayed_pic[0]; + + h->cur_pic_ptr = NULL; + h->first_field = 0; + + out_idx = 0; + for (i = 1; + h->delayed_pic[i] && + !h->delayed_pic[i]->f->key_frame && + !h->delayed_pic[i]->mmco_reset; + i++) + if (h->delayed_pic[i]->poc < out->poc) { + out = h->delayed_pic[i]; + out_idx = i; + } + + for (i = out_idx; h->delayed_pic[i]; i++) + h->delayed_pic[i] = h->delayed_pic[i + 1]; + + if (out) { + out->reference &= ~DELAYED_PIC_REF; + ret = finalize_frame(h, dst_frame, out, got_frame); + if (ret < 0) + return ret; + } + + return buf_index; +} + static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { @@ -1097,9 +1130,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, int buf_size = avpkt->size; H264Context *h = avctx->priv_data; AVFrame *pict = data; - int buf_index = 0; - H264Picture *out; - int i, out_idx; + int buf_index; int ret; h->flags = avctx->flags; @@ -1121,36 +1152,9 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, ff_h264_unref_picture(h, &h->last_pic_for_ec); /* end of stream, output what is still in the buffers */ - if (buf_size == 0) { - out: - - h->cur_pic_ptr = NULL; - h->first_field = 0; - - out = h->delayed_pic[0]; - out_idx = 0; - for (i = 1; - h->delayed_pic[i] && - !h->delayed_pic[i]->f->key_frame && - !h->delayed_pic[i]->mmco_reset; - i++) - if (h->delayed_pic[i]->poc < out->poc) { - out = h->delayed_pic[i]; - out_idx = i; - } - - for (i = out_idx; h->delayed_pic[i]; i++) - h->delayed_pic[i] = h->delayed_pic[i + 1]; + if (buf_size == 0) + return send_next_delayed_frame(h, pict, got_frame, 0); - if (out) { - out->reference &= ~DELAYED_PIC_REF; - ret = finalize_frame(h, pict, out, got_frame); - if (ret < 0) - return ret; - } - - return buf_index; - } if (h->is_avc && av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, NULL)) { int side_size; uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size); @@ -1172,7 +1176,7 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) { av_assert0(buf_index <= buf_size); - goto out; + return send_next_delayed_frame(h, pict, got_frame, buf_index); } if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {