From 2e899d3bdf31120df2590611fb84a1225416fbe9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 31 Aug 2024 11:31:52 +0200 Subject: [PATCH] lavfi/af_asr: convert to query_func2() Also, simplify code. --- libavfilter/af_asr.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_asr.c b/libavfilter/af_asr.c index e19b7c3be2..26963222fd 100644 --- a/libavfilter/af_asr.c +++ b/libavfilter/af_asr.c @@ -122,20 +122,33 @@ static av_cold int asr_init(AVFilterContext *ctx) return 0; } -static int query_formats(AVFilterContext *ctx) +static int query_formats(const AVFilterContext *ctx, + AVFilterFormatsConfig **cfg_in, + AVFilterFormatsConfig **cfg_out) { - ASRContext *s = ctx->priv; + static const enum AVSampleFormat formats[] = { + AV_SAMPLE_FMT_S16, + AV_SAMPLE_FMT_NONE, + }; + static const AVChannelLayout layouts[] = { + (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO, + (AVChannelLayout){ .nb_channels = 0 }, + }; + + const ASRContext *s = ctx->priv; int sample_rates[] = { s->rate, -1 }; int ret; - AVFilterFormats *formats = NULL; - AVFilterChannelLayouts *layout = NULL; + ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, formats); + if (ret < 0) + return ret; - if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_S16 )) < 0 || - (ret = ff_set_common_formats (ctx , formats )) < 0 || - (ret = ff_add_channel_layout (&layout , &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO )) < 0 || - (ret = ff_set_common_channel_layouts (ctx , layout )) < 0 || - (ret = ff_set_common_samplerates_from_list(ctx, sample_rates )) < 0) + ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, layouts); + if (ret < 0) + return ret; + + ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, sample_rates); + if (ret < 0) return ret; return 0; @@ -170,5 +183,5 @@ const AVFilter ff_af_asr = { .flags = AVFILTER_FLAG_METADATA_ONLY, FILTER_INPUTS(asr_inputs), FILTER_OUTPUTS(ff_audio_default_filterpad), - FILTER_QUERY_FUNC(query_formats), + FILTER_QUERY_FUNC2(query_formats), };