aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2023-10-20 15:33:16 +0200
committerNiklas Haas <git@haasn.dev>2023-12-31 13:33:01 -0800
commit0e9cf1abf558a5c71834548679c658b68244289d (patch)
tree4f42ae22e0928ff4e2f1e16e5e2d5a0f615e8336
parent1b0ca47707a01dc5709feeda859658a9d13621b8 (diff)
downloadffmpeg-0e9cf1abf558a5c71834548679c658b68244289d.tar.gz
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.
-rw-r--r--libavfilter/avfiltergraph.c39
1 files 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 */