From 7ab1ddbaf3f45d7dfe51b1caf78b5ca55fbb2bb6 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 4 Oct 2024 10:09:29 +0200 Subject: [PATCH] lavfi/vf_alphamerge: switch to query_func2() Simplify the implementation by using the fact that ff_set_common_*() will ignore those links on which the formats have already been set. --- libavfilter/vf_alphamerge.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libavfilter/vf_alphamerge.c b/libavfilter/vf_alphamerge.c index 2abb7e5583..c732f29367 100644 --- a/libavfilter/vf_alphamerge.c +++ b/libavfilter/vf_alphamerge.c @@ -96,7 +96,9 @@ static av_cold int init(AVFilterContext *ctx) return 0; } -static int query_formats(AVFilterContext *ctx) +static int query_formats(const AVFilterContext *ctx, + AVFilterFormatsConfig **cfg_in, + AVFilterFormatsConfig **cfg_out) { static const enum AVPixelFormat main_fmts[] = { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P, @@ -105,15 +107,18 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_NONE }; static const enum AVPixelFormat alpha_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE }; - AVFilterFormats *main_formats = ff_make_format_list(main_fmts); int ret; - if ((ret = ff_formats_ref(main_formats, &ctx->inputs[0]->outcfg.formats)) < 0 || - (ret = ff_formats_ref(main_formats, &ctx->outputs[0]->incfg.formats)) < 0) - return ret; + ret = ff_formats_ref(ff_make_format_list(alpha_fmts), + &cfg_in[1]->formats); + if (ret < 0) + return ret; - return ff_formats_ref(ff_make_format_list(alpha_fmts), - &ctx->inputs[1]->outcfg.formats); + ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, main_fmts); + if (ret < 0) + return ret; + + return 0; } static int config_input_main(AVFilterLink *inlink) @@ -203,7 +208,7 @@ const AVFilter ff_vf_alphamerge = { .init = init, FILTER_INPUTS(alphamerge_inputs), FILTER_OUTPUTS(alphamerge_outputs), - FILTER_QUERY_FUNC(query_formats), + FILTER_QUERY_FUNC2(query_formats), .uninit = uninit, .activate = activate, .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,