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.
release/7.0
Niklas Haas 1 year ago
parent 1b0ca47707
commit 0e9cf1abf5
  1. 39
      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 */

Loading…
Cancel
Save