History

avfilter/af_aresample: Use preinit instead of init_dict

By using preinit, the SwrContext already exists directly after allocating the filter, so that the filter's AVClass's child_next becomes usable for setting options with the AV_OPT_SEARCH_CHILDREN search flag. This means that it is no longer necessary to use the init_dict callback for this filter. Furthermore, the earlier code did not abide by the documentation of the init_dict callback at all: Instead of only returning the options that have not been recognized it always returned all options on any av_opt_set() error and errored out in this case; yet if the error was just caused by an unrecognized option, it should not error out at all and instead return said option. This behaviour has been inherited by avfilter_init_dict(), contradicting its documentation. This is also fixed by this commit.

Andreas Rheinhardt committed 5 years ago

Commit 0c34cf81 parent 6c8f96f1 file · +7 −20Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_aresample.c+7−20
@@ -43,31 +43,16 @@ typedef struct AResampleContext { · 42 unmodified lines
4343 int more_data;
4444 } AResampleContext;
4545
46−static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
46+static av_cold int preinit(AVFilterContext *ctx)
4747 {
4848 AResampleContext *aresample = ctx->priv;
49− int ret = 0;
5049
5150 aresample->next_pts = AV_NOPTS_VALUE;
5251 aresample->swr = swr_alloc();
53− if (!aresample->swr) {
54− ret = AVERROR(ENOMEM);
55− goto end;
56− }
57−
58− if (opts) {
59− AVDictionaryEntry *e = NULL;
52+ if (!aresample->swr)
53+ return AVERROR(ENOMEM);
6054
61− while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
62− if ((ret = av_opt_set(aresample->swr, e->key, e->value, 0)) < 0)
63− goto end;
64− }
65− av_dict_free(opts);
66− }
67− if (aresample->sample_rate_arg > 0)
68− av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
69−end:
70− return ret;
55+ return 0;
7156 }
7257
7358 static av_cold void uninit(AVFilterContext *ctx)
@@ -90,6 +75,8 @@ static int query_formats(AVFilterContext *ctx) · 16 unmodified lines
9075 AVFilterChannelLayouts *in_layouts, *out_layouts;
9176 int ret;
9277
78+ if (aresample->sample_rate_arg > 0)
79+ av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
9380 av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
9481 av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
9582 av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
@@ -343,7 +330,7 @@ static const AVFilterPad aresample_outputs[] = { · 247 unmodified lines
343330 const AVFilter ff_af_aresample = {
344331 .name = "aresample",
345332 .description = NULL_IF_CONFIG_SMALL("Resample audio data."),
346− .init_dict = init_dict,
333+ .preinit = preinit,
347334 .uninit = uninit,
348335 .query_formats = query_formats,
349336 .priv_size = sizeof(AResampleContext),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t