From patchwork Sat Jul 15 10:45:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42698 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239405pzb; Sat, 15 Jul 2023 03:47:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlE6EufnxmuFnFw1PRyp2DnUy79kr8F+IPTsVa2j6bPCqkSNeggDBg8o1m0U6E/F8Fi1Jze/ X-Received: by 2002:aa7:c3d8:0:b0:51d:eb90:4928 with SMTP id l24-20020aa7c3d8000000b0051deb904928mr6928806edr.30.1689418067401; Sat, 15 Jul 2023 03:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418067; cv=none; d=google.com; s=arc-20160816; b=RZzlBL++0l7sT5FLWZqQP+MQ6w3ZT1VXCjM6Sab0lxK8ykVjxPo9bPPnp7y0oa1kEO j4uPEhwk43ykcSQGxTywH06KwMulKOm752d/cEcbVryrxf0ajzaWMTxDQ98xvMR9qwPY YO+q+aATeISWbOZnqVKBrVKtGsFIKn0cs5kvBhixnyPqaFOpUUmMIUwAda7GFvOWQ50p 6LP6EpQCW5NgTz/a16O3GTL0z1+VRpSwupepelASryuQO4YG1Ib0Au12x30zJimuhC1m 6+ntqBekyVo0T1fPU0n7AZrnTi6trrt+NxLmq/+ZJh36ycEoy8vWBD2hYxBdixDSFJCl Nr9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=MQ4ATfD6WXYHVEt96fQeF0kVVfxbu+IwUhA1qpE3bqE=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ZjjNL7xZlsrC6ISgA+Mdf2UV7rz+2jSTqMWQE0KjwqdmAxrxp/lWl9xhxGwavt3aFN IwqHpMEwmZAHOyqE25VvBNHr1VykbmPH4CNk1OXlgfIEdgD3q0gjogxULkLzBPnT0spk Yp0k38hgC9d53L4bfv5v9v1hxGLKhzRyYcKMkMdRUJCngsWNbf5MdNumWBW1QigJOeze jljbz9kKRpEuOqX/k7Co3WH+hMYaaoeDa3/b63BsuO7Xi3OT5wL6MxZ7771DSMh3eUF3 ETMtWUkHLlgNfqRNebNReULAFNKN6JDFCF0iA8oYHDbQLf1uFNX5Z5WIkFCWk1gxTpjA 5tlA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r19-20020aa7d593000000b0051e22d772a2si11298712edq.679.2023.07.15.03.47.46; Sat, 15 Jul 2023 03:47:47 -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 C105D68C60F; Sat, 15 Jul 2023 13:46:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B5B3768C60F for ; Sat, 15 Jul 2023 13:46:32 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EDFA92404EE for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XmcRbhdx-W6X for ; Sat, 15 Jul 2023 12:46:29 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 8C677240591 for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 38AA23A128F for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:30 +0200 Message-Id: <20230715104611.17902-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/47] fftools/ffmpeg_filter: restrict reap_filters() to a single filtergraph X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bCgiCjzF85Bd This is more natural, as all except one of its callers require processing only one filtergraph. --- fftools/ffmpeg.c | 10 +++++++++- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_filter.c | 33 ++++++++++++++++----------------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cbeddab125..27c4e7ef26 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1171,7 +1171,15 @@ static int transcode_step(OutputStream *ost) if (ret < 0) return ret == AVERROR_EOF ? 0 : ret; - return reap_filters(0); + // process_input() above might have caused output to become available + // in multiple filtergraphs, so we process all of them + for (int i = 0; i < nb_filtergraphs; i++) { + ret = reap_filters(filtergraphs[i], 0); + if (ret < 0) + return ret; + } + + return 0; } /* diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 7c4f4365c6..0189bee0f3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -766,12 +766,12 @@ void fg_free(FilterGraph **pfg); int fg_transcode_step(FilterGraph *graph, InputStream **best_ist); /** - * Get and encode new output from any of the filtergraphs, without causing + * Get and encode new output from specified filtergraph, without causing * activity. * * @return 0 for success, <0 for severe errors */ -int reap_filters(int flush); +int reap_filters(FilterGraph *fg, int flush); int ffmpeg_parse_options(int argc, char **argv); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index e14b8f0f3c..49e0800e6e 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1695,24 +1695,23 @@ int filtergraph_is_simple(const FilterGraph *fg) return fgp->is_simple; } -int reap_filters(int flush) +int reap_filters(FilterGraph *fg, int flush) { + FilterGraphPriv *fgp = fgp_from_fg(fg); + AVFrame *filtered_frame = fgp->frame; + + if (!fg->graph) + return 0; + /* Reap all buffers present in the buffer sinks */ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - OutputFilterPriv *ofp; - FilterGraphPriv *fgp; - AVFrame *filtered_frame; - AVFilterContext *filter; + for (int i = 0; i < fg->nb_outputs; i++) { + OutputFilter *ofilter = fg->outputs[i]; + OutputStream *ost = ofilter->ost; + OutputFilterPriv *ofp = ofp_from_ofilter(ofilter); + AVFilterContext *filter = ofp->filter; + int ret = 0; - if (!ost->filter || !ost->filter->graph->graph) - continue; - fgp = fgp_from_fg(ost->filter->graph); - ofp = ofp_from_ofilter(ost->filter); - filter = ofp->filter; - - filtered_frame = fgp->frame; - while (1) { FrameData *fd; @@ -1931,7 +1930,7 @@ int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference) return ret; } - ret = reap_filters(0); + ret = reap_filters(fg, 0); if (ret < 0 && ret != AVERROR_EOF) { av_log(fg, AV_LOG_ERROR, "Error while filtering: %s\n", av_err2str(ret)); return ret; @@ -2000,10 +1999,10 @@ int fg_transcode_step(FilterGraph *graph, InputStream **best_ist) *best_ist = NULL; ret = avfilter_graph_request_oldest(graph->graph); if (ret >= 0) - return reap_filters(0); + return reap_filters(graph, 0); if (ret == AVERROR_EOF) { - reap_filters(1); + reap_filters(graph, 1); for (int i = 0; i < graph->nb_outputs; i++) { OutputFilter *ofilter = graph->outputs[i]; OutputFilterPriv *ofp = ofp_from_ofilter(ofilter);