From patchwork Wed Dec 13 13:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45099 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4263422pzf; Wed, 13 Dec 2023 05:16:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfVe1e9PXCI/pYnGXlLG8leUG1J6Oi1SsdaB9shLtqYIry4BDMjn2lbIU8ENX/7N/hjpmo X-Received: by 2002:a50:cd18:0:b0:54c:6199:97e1 with SMTP id z24-20020a50cd18000000b0054c619997e1mr3462064edi.2.1702473370045; Wed, 13 Dec 2023 05:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702473370; cv=none; d=google.com; s=arc-20160816; b=cnU+/8XATmf+g9dR/xA5nsNwzgT5tANPhNVsuQbuIcD8AXD7HkxCiD8AnOBduhllan FuqrSF18mjBYpep6vSqkNnWTQgH32h1cFxV0IYgmKlrMb7RrHVnP3BBnLP/xCRPjjRbn T+qQZ5XeVGVzP7yyU6UJ5+5rRledZ9q6mUf26MTir4cD1Z9KgRmI4rijqwEBl+GPTVfg ChrfEEsj9d8W/R0kcf99taXfi1WqXX5AzmmDgFZDWp1Dj72f+2g9w0m5+8hwnU+ku8J9 ccreoOcBIl40MJslsPhJjvurU+nvj/4nn10tZScyPuwwNK9sd2huuNgMwCycVDOCF3Cz SKAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=qrkID2ENSAQH5uIUEJuyTy59eY8IpmJlZPblZaWJq0U=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=bmJIZHBCgABrjaC+WUe0ufhvNDKafn/veGmg0IfXideLo0MdjuJnvl/5jYQpf9+81S tUmRuEc/BYqhx2gT6TPhCkcQl409uVTKqMt7SgnFEbzlvuUHTlW7P4aBLzGecCjyNg2u gdnCL3MgEZVmA9gOps5d85Neks6kPL3SGXwP0fOlfVY0UuhmKycYY3NFTjuIuoR8FbJP IC6SVoqTR+nfLEY8wLPfOTUvRxt398eecxO23GCGVnUoX3GSFvHefumSb6i8bcSF2Jdq uudbNbQUZYKXP6F6g1J6z5FHwFru10w0qk6n9Rh9yuyiuhiy973EYyZfVAOtNLop6GRW 1uXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=HB6JesPE; 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 n23-20020a5099d7000000b0054c62822aadsi5440834edb.488.2023.12.13.05.16.09; Wed, 13 Dec 2023 05:16:10 -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; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=HB6JesPE; 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 7963B68D1CD; Wed, 13 Dec 2023 15:15:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83A3168CFA3 for ; Wed, 13 Dec 2023 15:15:39 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 3867C4B966; Wed, 13 Dec 2023 14:15:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702473339; bh=2n/UjgEALUnXEFdbp3MkQj90ZuMuQq4agS3gg6F76Vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HB6JesPEF1tLS7kzReebEDPpTvHxodUGJ0fn/E0EzJkoAaNq3dYNxVi9Um9Lb01p8 ueWfOHfnPm/7hDNy007TeSDJ9e/V3ic+jnT6CFMYaj17TOTFx+WK3G+Yi/XkOpIFzK 4kX0LdEYDEIxNIONzBFiciyvS1abCFzlsyYU6a8U= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 13 Dec 2023 14:11:59 +0100 Message-ID: <20231213131536.10242-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213131536.10242-1-ffmpeg@haasn.xyz> References: <20231213131536.10242-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 02/15] avfilter: always call ff_default_query_formats 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FeukPH5KuVIb From: Niklas Haas Even if a query func is set. This is safe to do, because ff_default_query_formats is documented not to touch any filter lists that were already set by the query func. The reason to do this is because it allows us to extend AVFilterFormatsConfig without having to touch every filter in existence. An alternative implementation of this commit would be to explicitly add a `ff_default_query_formats` call at the end of every query_formats function, but that would end up functionally equivalent to this change while touching a whole lot more code paths for no reason. As a bonus, eliminates some code/logic duplication from this function. --- libavfilter/avfiltergraph.c | 39 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 68daa93e61..625cbc022e 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -341,33 +341,21 @@ static int filter_check_formats(AVFilterContext *ctx) static int filter_query_formats(AVFilterContext *ctx) { int ret; - AVFilterFormats *formats; - AVFilterChannelLayouts *chlayouts; - enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type : - ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type : - AVMEDIA_TYPE_VIDEO; - - if ((ret = ctx->filter->formats.query_func(ctx)) < 0) { - if (ret != AVERROR(EAGAIN)) - av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n", - ctx->name, av_err2str(ret)); - return ret; - } - ret = filter_check_formats(ctx); - if (ret < 0) - return ret; - formats = ff_all_formats(type); - if ((ret = ff_set_common_formats(ctx, formats)) < 0) - return ret; - if (type == AVMEDIA_TYPE_AUDIO) { - if ((ret = ff_set_common_all_samplerates(ctx)) < 0) + if (ctx->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) { + if ((ret = ctx->filter->formats.query_func(ctx)) < 0) { + if (ret != AVERROR(EAGAIN)) + av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n", + ctx->name, av_err2str(ret)); return ret; - chlayouts = ff_all_channel_layouts(); - if ((ret = ff_set_common_channel_layouts(ctx, chlayouts)) < 0) + } + + ret = filter_check_formats(ctx); + if (ret < 0) return ret; } - return 0; + + return ff_default_query_formats(ctx); } static int formats_declared(AVFilterContext *f) @@ -416,10 +404,7 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) AVFilterContext *f = graph->filters[i]; if (formats_declared(f)) continue; - if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) - ret = filter_query_formats(f); - else - ret = ff_default_query_formats(f); + ret = filter_query_formats(f); if (ret < 0 && ret != AVERROR(EAGAIN)) return ret; /* note: EAGAIN could indicate a partial success, not counted yet */