From patchwork Sat Dec 24 09:41:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 1905 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp228802vsb; Sat, 24 Dec 2016 01:41:21 -0800 (PST) X-Received: by 10.28.74.215 with SMTP id n84mr7166744wmi.9.1482572481120; Sat, 24 Dec 2016 01:41:21 -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 l10si38825814wjr.92.2016.12.24.01.41.20; Sat, 24 Dec 2016 01:41:21 -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 19D47689B29; Sat, 24 Dec 2016 11:41:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D7349680501 for ; Sat, 24 Dec 2016 11:41:04 +0200 (EET) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id uBO9f5cc008354 for ; Sat, 24 Dec 2016 10:41:05 +0100 (CET) Received: by phare.normalesup.org (Postfix, from userid 1001) id AD661E0087; Sat, 24 Dec 2016 10:41:05 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Dec 2016 10:41:01 +0100 Message-Id: <20161224094101.27898-2-george@nsup.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161224094101.27898-1-george@nsup.org> References: <20161224093958.GA2111506@phare.normalesup.org> <20161224094101.27898-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Sat, 24 Dec 2016 10:41:06 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 2/2] lavfi/buffersrc: push the frame deeper if requested. 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Reduce peak memory consumption with ffmpeg in certain cases. Signed-off-by: Nicolas George --- libavfilter/buffersrc.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) Unchanged. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 1314397a32..77fd174219 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -173,6 +173,20 @@ int attribute_align_arg av_buffersrc_add_frame_flags(AVFilterContext *ctx, AVFra return ret; } +static int push_frame(AVFilterGraph *graph) +{ + int ret; + + while (1) { + ret = ff_filter_graph_run_once(graph); + if (ret == AVERROR(EAGAIN)) + break; + if (ret < 0) + return ret; + } + return 0; +} + static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags) { @@ -185,6 +199,11 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, if (!frame) { s->eof = 1; ff_avfilter_link_set_in_status(ctx->outputs[0], AVERROR_EOF, AV_NOPTS_VALUE); + if ((flags & AV_BUFFERSRC_FLAG_PUSH)) { + ret = push_frame(ctx->graph); + if (ret < 0) + return ret; + } return 0; } else if (s->eof) return AVERROR(EINVAL); @@ -239,6 +258,12 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, if ((ret = ctx->output_pads[0].request_frame(ctx->outputs[0])) < 0) return ret; + if ((flags & AV_BUFFERSRC_FLAG_PUSH)) { + ret = push_frame(ctx->graph); + if (ret < 0) + return ret; + } + return 0; }