From patchwork Tue Nov 1 14:05:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 1249 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp678877vsb; Tue, 1 Nov 2016 07:03:08 -0700 (PDT) X-Received: by 10.28.48.203 with SMTP id w194mr1894153wmw.115.1478008988905; Tue, 01 Nov 2016 07:03:08 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y200si31167656wme.30.2016.11.01.07.03.08; Tue, 01 Nov 2016 07:03:08 -0700 (PDT) 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 41A74689CC1; Tue, 1 Nov 2016 16:03:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from kimiko.pkh.me (pkh.me [5.196.73.185]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D96E68991E for ; Tue, 1 Nov 2016 16:02:57 +0200 (EET) Received: from localhost (kimiko.pkh.me [local]) by kimiko.pkh.me (OpenSMTPD) with ESMTPA id b7769394; Tue, 1 Nov 2016 14:05:17 +0000 (UTC) From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Nov 2016 15:05:16 +0100 Message-Id: <20161101140516.24431-1-u@pkh.me> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161101135244.GH4602@nb4> References: <20161101135244.GH4602@nb4> Subject: [FFmpeg-devel] [PATCH 2/2] ffmpeg: factor out sending frame to filters 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?= MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Video doesn't exit ffmpeg on error anymore, and audio now prints an error. --- ffmpeg.c | 64 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 7e366f2..36a921a 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2055,9 +2055,35 @@ static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacke return 0; } +static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame) +{ + int i, ret; + AVFrame *f; + + for (i = 0; i < ist->nb_filters; i++) { + if (i < ist->nb_filters - 1) { + f = ist->filter_frame; + ret = av_frame_ref(f, decoded_frame); + if (ret < 0) + break; + } else + f = decoded_frame; + ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f, + AV_BUFFERSRC_FLAG_PUSH); + if (ret == AVERROR_EOF) + ret = 0; /* ignore */ + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Failed to inject frame into filter network: %s\n", av_err2str(ret)); + break; + } + } + return ret; +} + static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output) { - AVFrame *decoded_frame, *f; + AVFrame *decoded_frame; AVCodecContext *avctx = ist->dec_ctx; int i, ret, err = 0, resample_changed; AVRational decoded_frame_tb; @@ -2152,21 +2178,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output) (AVRational){1, avctx->sample_rate}, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last, (AVRational){1, avctx->sample_rate}); ist->nb_samples = decoded_frame->nb_samples; - for (i = 0; i < ist->nb_filters; i++) { - if (i < ist->nb_filters - 1) { - f = ist->filter_frame; - err = av_frame_ref(f, decoded_frame); - if (err < 0) - break; - } else - f = decoded_frame; - err = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f, - AV_BUFFERSRC_FLAG_PUSH); - if (err == AVERROR_EOF) - err = 0; /* ignore */ - if (err < 0) - break; - } + err = send_frame_to_filters(ist, decoded_frame); decoded_frame->pts = AV_NOPTS_VALUE; av_frame_unref(ist->filter_frame); @@ -2176,7 +2188,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output) static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int eof) { - AVFrame *decoded_frame, *f; + AVFrame *decoded_frame; int i, ret = 0, err = 0, resample_changed; int64_t best_effort_timestamp; int64_t dts = AV_NOPTS_VALUE; @@ -2315,23 +2327,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output, int eo } } - for (i = 0; i < ist->nb_filters; i++) { - if (i < ist->nb_filters - 1) { - f = ist->filter_frame; - err = av_frame_ref(f, decoded_frame); - if (err < 0) - break; - } else - f = decoded_frame; - err = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f, AV_BUFFERSRC_FLAG_PUSH); - if (err == AVERROR_EOF) { - err = 0; /* ignore */ - } else if (err < 0) { - av_log(NULL, AV_LOG_FATAL, - "Failed to inject frame into filter network: %s\n", av_err2str(err)); - exit_program(1); - } - } + err = send_frame_to_filters(ist, decoded_frame); fail: av_frame_unref(ist->filter_frame);