[FFmpeg-devel] [PATCH 6/8] lavfi/af_afir: convert to query_func2()

Anton Khirnov anton at khirnov.net
Thu Aug 29 11:50:50 EEST 2024


Drop redundant ff_set_common_all_channel_counts() /
ff_set_common_all_samplerates() calls, since those happen implicitly in
generic code.
---
 libavfilter/af_afir.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/libavfilter/af_afir.c b/libavfilter/af_afir.c
index 8ab4d544a8..c641893d4a 100644
--- a/libavfilter/af_afir.c
+++ b/libavfilter/af_afir.c
@@ -539,9 +539,11 @@ static int activate(AVFilterContext *ctx)
     return FFERROR_NOT_READY;
 }
 
-static int query_formats(AVFilterContext *ctx)
+static int query_formats(const AVFilterContext *ctx,
+                         AVFilterFormatsConfig **cfg_in,
+                         AVFilterFormatsConfig **cfg_out)
 {
-    AudioFIRContext *s = ctx->priv;
+    const AudioFIRContext *s = ctx->priv;
     static const enum AVSampleFormat sample_fmts[3][3] = {
         { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE },
         { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE },
@@ -549,32 +551,29 @@ static int query_formats(AVFilterContext *ctx)
     };
     int ret;
 
-    if (s->ir_format) {
-        ret = ff_set_common_all_channel_counts(ctx);
-        if (ret < 0)
-            return ret;
-    } else {
+    if (!s->ir_format) {
         AVFilterChannelLayouts *mono = NULL;
         AVFilterChannelLayouts *layouts = ff_all_channel_counts();
 
-        if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts)) < 0)
+        if ((ret = ff_channel_layouts_ref(layouts, &cfg_in[0]->channel_layouts)) < 0)
             return ret;
-        if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
+        if ((ret = ff_channel_layouts_ref(layouts, &cfg_out[0]->channel_layouts)) < 0)
             return ret;
 
         ret = ff_add_channel_layout(&mono, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO);
         if (ret)
             return ret;
         for (int i = 1; i < ctx->nb_inputs; i++) {
-            if ((ret = ff_channel_layouts_ref(mono, &ctx->inputs[i]->outcfg.channel_layouts)) < 0)
+            if ((ret = ff_channel_layouts_ref(mono, &cfg_in[i]->channel_layouts)) < 0)
                 return ret;
         }
     }
 
-    if ((ret = ff_set_common_formats_from_list(ctx, sample_fmts[s->precision])) < 0)
+    if ((ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out,
+                                                sample_fmts[s->precision])) < 0)
         return ret;
 
-    return ff_set_common_all_samplerates(ctx);
+    return 0;
 }
 
 static int config_output(AVFilterLink *outlink)
@@ -783,7 +782,7 @@ const AVFilter ff_af_afir = {
     .description   = NULL_IF_CONFIG_SMALL("Apply Finite Impulse Response filter with supplied coefficients in additional stream(s)."),
     .priv_size     = sizeof(AudioFIRContext),
     .priv_class    = &afir_class,
-    FILTER_QUERY_FUNC(query_formats),
+    FILTER_QUERY_FUNC2(query_formats),
     FILTER_OUTPUTS(outputs),
     .init          = init,
     .activate      = activate,
-- 
2.43.0



More information about the ffmpeg-devel mailing list