summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas George <george@nsup.org>2021-07-24 19:37:55 +0200
committerNicolas George <george@nsup.org>2021-08-14 09:17:45 +0200
commit85a6404d7e6c759ddf71d6374812d7ff719728ec (patch)
treed1d6fc6eff506ac53c86431fdc9dd9cca6a0a0f5
parent86d3dd5627b5c8c179aa48c7e4834a69371a14e6 (diff)
lavfi/formats: describe conversion in negotiation structure.
-rw-r--r--libavfilter/avfiltergraph.c45
-rw-r--r--libavfilter/formats.c4
-rw-r--r--libavfilter/formats.h2
3 files changed, 18 insertions, 33 deletions
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 8342e21769..41a91a9bda 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -430,7 +430,7 @@ static int formats_declared(AVFilterContext *f)
static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
{
int i, j, ret;
- int scaler_count = 0, resampler_count = 0;
+ int converter_count = 0;
int count_queried = 0; /* successful calls to query_formats() */
int count_merged = 0; /* successful merge of formats lists */
int count_already_merged = 0; /* lists already merged */
@@ -497,6 +497,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
const AVFilter *filter;
AVFilterLink *inlink, *outlink;
char inst_name[30];
+ const char *opts;
if (graph->disable_auto_convert) {
av_log(log_ctx, AV_LOG_ERROR,
@@ -507,40 +508,18 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx)
}
/* couldn't merge format lists. auto-insert conversion filter */
- switch (link->type) {
- case AVMEDIA_TYPE_VIDEO:
- if (!(filter = avfilter_get_by_name("scale"))) {
- av_log(log_ctx, AV_LOG_ERROR, "'scale' filter "
- "not present, cannot convert pixel formats.\n");
- return AVERROR(EINVAL);
- }
-
- snprintf(inst_name, sizeof(inst_name), "auto_scaler_%d",
- scaler_count++);
-
- if ((ret = avfilter_graph_create_filter(&convert, filter,
- inst_name, graph->scale_sws_opts, NULL,
- graph)) < 0)
- return ret;
- break;
- case AVMEDIA_TYPE_AUDIO:
- if (!(filter = avfilter_get_by_name("aresample"))) {
- av_log(log_ctx, AV_LOG_ERROR, "'aresample' filter "
- "not present, cannot convert audio formats.\n");
- return AVERROR(EINVAL);
- }
-
- snprintf(inst_name, sizeof(inst_name), "auto_resampler_%d",
- resampler_count++);
- if ((ret = avfilter_graph_create_filter(&convert, filter,
- inst_name, graph->aresample_swr_opts,
- NULL, graph)) < 0)
- return ret;
- break;
- default:
+ if (!(filter = avfilter_get_by_name(neg->conversion_filter))) {
+ av_log(log_ctx, AV_LOG_ERROR,
+ "'%s' filter not present, cannot convert formats.\n",
+ neg->conversion_filter);
return AVERROR(EINVAL);
}
-
+ snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
+ neg->conversion_filter, converter_count++);
+ opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph);
+ ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph);
+ if (ret < 0)
+ return ret;
if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0)
return ret;
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 9ddd0e47ea..9e39d65a3c 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -329,11 +329,15 @@ static const AVFilterFormatsMerger mergers_audio[] = {
static const AVFilterNegotiation negotiate_video = {
.nb = FF_ARRAY_ELEMS(mergers_video),
.mergers = mergers_video,
+ .conversion_filter = "scale",
+ .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
};
static const AVFilterNegotiation negotiate_audio = {
.nb = FF_ARRAY_ELEMS(mergers_audio),
.mergers = mergers_audio,
+ .conversion_filter = "aresample",
+ .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
};
const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link)
diff --git a/libavfilter/formats.h b/libavfilter/formats.h
index 6c1eec05ea..ed513c265a 100644
--- a/libavfilter/formats.h
+++ b/libavfilter/formats.h
@@ -78,6 +78,8 @@ typedef struct AVFilterFormatMerger {
typedef struct AVFilterNegotiation {
unsigned nb;
const AVFilterFormatsMerger *mergers;
+ const char *conversion_filter;
+ unsigned conversion_opts_offset;
} AVFilterNegotiation;
const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link);