From patchwork Fri Jan 13 11:40:07 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: 2203 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp140446vsb; Fri, 13 Jan 2017 03:40:48 -0800 (PST) X-Received: by 10.28.183.5 with SMTP id h5mr1871467wmf.39.1484307647993; Fri, 13 Jan 2017 03:40:47 -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 a26si10919715wrd.196.2017.01.13.03.40.47; Fri, 13 Jan 2017 03:40:47 -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 B4472689FAF; Fri, 13 Jan 2017 13:40:12 +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 F1625687EE6 for ; Fri, 13 Jan 2017 13:40:05 +0200 (EET) Received: from localhost (golem.pkh.me [local]) by golem.pkh.me (OpenSMTPD) with ESMTPA id c2646d1c; Fri, 13 Jan 2017 11:40:08 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Jan 2017 12:40:07 +0100 Message-Id: <20170113114007.15690-3-u@pkh.me> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170113114007.15690-1-u@pkh.me> References: <20170113114007.15690-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/h264dec: reconstruct and debug flush frames as well 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 | 99 +++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 43 deletions(-) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index ed0b7246b7..0cb0352485 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -1037,6 +1037,59 @@ static int is_extra(const uint8_t *buf, int buf_size) return 1; } +static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *got_frame) +{ + int ret; + + if (((h->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) || + (h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) || + out->recovered)) { + + if (!out->recovered) + out->f->flags |= AV_FRAME_FLAG_CORRUPT; + + if (!h->avctx->hwaccel && + (out->field_poc[0] == INT_MAX || + out->field_poc[1] == INT_MAX) + ) { + int p; + AVFrame *f = out->f; + int field = out->field_poc[0] == INT_MAX; + uint8_t *dst_data[4]; + int linesizes[4]; + const uint8_t *src_data[4]; + + av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field); + + for (p = 0; p<4; p++) { + dst_data[p] = f->data[p] + (field^1)*f->linesize[p]; + src_data[p] = f->data[p] + field *f->linesize[p]; + linesizes[p] = 2*f->linesize[p]; + } + + av_image_copy(dst_data, linesizes, src_data, linesizes, + f->format, f->width, f->height>>1); + } + + ret = output_frame(h, dst, out); + if (ret < 0) + return ret; + + *got_frame = 1; + + if (CONFIG_MPEGVIDEO) { + ff_print_debug_info2(h->avctx, dst, NULL, + out->mb_type, + out->qscale_table, + out->motion_val, + NULL, + h->mb_width, h->mb_height, h->mb_stride, 1); + } + } + + return 0; +} + static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { @@ -1074,7 +1127,6 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, h->cur_pic_ptr = NULL; h->first_field = 0; - // FIXME factorize this with the output code below out = h->delayed_pic[0]; out_idx = 0; for (i = 1; @@ -1092,10 +1144,9 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, if (out) { out->reference &= ~DELAYED_PIC_REF; - ret = output_frame(h, pict, out); + ret = finalize_frame(h, pict, out, got_frame); if (ret < 0) return ret; - *got_frame = 1; } return buf_index; @@ -1141,48 +1192,10 @@ static int h264_decode_frame(AVCodecContext *avctx, void *data, return ret; /* Wait for second field. */ - *got_frame = 0; - if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) || - (avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) || - h->next_output_pic->recovered)) { - if (!h->next_output_pic->recovered) - h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT; - - if (!h->avctx->hwaccel && - (h->next_output_pic->field_poc[0] == INT_MAX || - h->next_output_pic->field_poc[1] == INT_MAX) - ) { - int p; - AVFrame *f = h->next_output_pic->f; - int field = h->next_output_pic->field_poc[0] == INT_MAX; - uint8_t *dst_data[4]; - int linesizes[4]; - const uint8_t *src_data[4]; - - av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field); - - for (p = 0; p<4; p++) { - dst_data[p] = f->data[p] + (field^1)*f->linesize[p]; - src_data[p] = f->data[p] + field *f->linesize[p]; - linesizes[p] = 2*f->linesize[p]; - } - - av_image_copy(dst_data, linesizes, src_data, linesizes, - f->format, f->width, f->height>>1); - } - - ret = output_frame(h, pict, h->next_output_pic); + if (h->next_output_pic) { + ret = finalize_frame(h, pict, h->next_output_pic, got_frame); if (ret < 0) return ret; - *got_frame = 1; - if (CONFIG_MPEGVIDEO) { - ff_print_debug_info2(h->avctx, pict, NULL, - h->next_output_pic->mb_type, - h->next_output_pic->qscale_table, - h->next_output_pic->motion_val, - NULL, - h->mb_width, h->mb_height, h->mb_stride, 1); - } } }