[FFmpeg-cvslog] avfilter: always call ff_default_query_formats

Niklas Haas git at videolan.org
Sun Dec 31 23:49:35 EET 2023


ffmpeg | branch: master | Niklas Haas <git at haasn.dev> | Fri Oct 20 15:33:16 2023 +0200| [0e9cf1abf558a5c71834548679c658b68244289d] | committer: Niklas Haas

avfilter: always call ff_default_query_formats

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0e9cf1abf558a5c71834548679c658b68244289d
---

 libavfilter/avfiltergraph.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 9e9464c034..114dfaa655 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -340,33 +340,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)
@@ -415,10 +403,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 */



More information about the ffmpeg-cvslog mailing list