From patchwork Thu Nov 9 12:19:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44585 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4fa4:b0:181:818d:5e7f with SMTP id gh36csp444024pzb; Thu, 9 Nov 2023 04:26:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpbP1E3wbc46hzVTFXI7tUjuOZPBb4rYAhN8xLeOqhOUhYcpx/cPzCP8m+F/qwWAQMaLMV X-Received: by 2002:a50:c019:0:b0:543:5293:9a81 with SMTP id r25-20020a50c019000000b0054352939a81mr4170040edb.8.1699532766476; Thu, 09 Nov 2023 04:26:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699532766; cv=none; d=google.com; s=arc-20160816; b=F+6Nm79GK2Lth5zXGnn8tmcirFa87XtJ1ZAoUuzLWyicPQfCR/v3xkavbgw95AjgfZ FNoJsq/G6LG0V/vSOMhDKxs1mz9d0DQF/qYfQkdWOUhlus14c5N8r/EsTJMzzW9ewYYR +yqJGqwHwh2tICgGI4cSIte90IXVjNvRFoRahuOTQHJe0HOFSaV9sIF/iT39TKX+3OH6 UJuixMxPLX7WLai6NVo12DGgPnVWN8119meSR6CDJQidFFrZRV3qqN4GBh1wJaiIv4wh BgUVhBQ2FkyUaDShy2bdoHAciyXIqx/ZjI4TjromSB9XOPe2skVdeZ6C/kF5eHpOj3bG JRQg== 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=o+oK6dSB0mBMFt5PrwdT4OE7SIQOSZKM9Xn0MlhZ8YQ=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=pGi2JUwAFE+G8Ov31gzPpfh97kVqM1VJ7/WYZJK2K3nA65aNBly3cTimHx6EgyAR0b H7aMpSsZMQja7zXUwjh8LoeL1C3n1s/LQTRhIJWPdnA0qh7gYS1Kt0NXgTMCoy1oyEzO 99LEg83s+UH+im/HKqsedFrXugka3bf2Hmb5HRY/9Wgr/ocM4D85xQZNJCaxO3JNSs5R pHzrHW22bpa8SK1y15BU7L/rhHOGL2q0czeS8hSjjjPTQpe566wnBqJBtF0bTSO12zoX K0X9OCZ70JPZk56T+T5+DuDN37mR9Sa07Y0Vaazr32HUMk6mjp4wYw49mhQgIPp8t0Jz 9K8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=E0A2beZl; 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 q17-20020a056402519100b0053f9371b60esi8219819edd.274.2023.11.09.04.26.06; Thu, 09 Nov 2023 04:26:06 -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=E0A2beZl; 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 E6EA368CBDD; Thu, 9 Nov 2023 14:25:45 +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 B61B668CBCB for ; Thu, 9 Nov 2023 14:25:36 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 1ECEE4B527; Thu, 9 Nov 2023 13:25:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1699532736; bh=Fge18/bG4h1ilIXmC0znakqn+wW+wSSmGOPKLQkFG3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E0A2beZl5FIF8iXMyLvTmebQGYfkiBNqyyCYcfjqh2uXN/c2BKVLZFCPkxRTJGEZd yFDTX0JIe8NKhDbZjaViBb+VHrEmdfsTB1/tb86ofpS4ShY1H+tGhIu/ngWFqqFBf/ ZoiwQ5WqY7TUvw1wAcgO+pScGigvvdg8OpTDF0Bs= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Nov 2023 13:19:34 +0100 Message-ID: <20231109122534.124157-3-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109122534.124157-1-ffmpeg@haasn.xyz> References: <20231109122534.124157-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/25] 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: 6LgJiUvcdC11 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 */