History

avfilter/vf_spp: Use preinit instead of init_dict

By using preinit, the AVDCT 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, even if it is just an unrecognized option. This behaviour has been inherited by avfilter_init_dict(), contradicting its documentation. This is also fixed in this commit.

Andreas Rheinhardt committed 5 years ago

Commit a85d2de1 parent 0c34cf81 file · +8 −18Browse files

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

Unified · Split

libavfilter/vf_spp.c+8−18
@@ -338,6 +338,12 @@ static int config_input(AVFilterLink *inlink) · 337 unmodified lines
338338 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
339339 const int bps = desc->comp[0].depth;
340340
341+ s->store_slice = store_slice_c;
342+ switch (s->mode) {
343+ case MODE_HARD: s->requantize = hardthresh_c; break;
344+ case MODE_SOFT: s->requantize = softthresh_c; break;
345+ }
346+
341347 av_opt_set_int(s->dct, "bits_per_sample", bps, 0);
342348 avcodec_dct_init(s->dct);
343349
@@ -451,30 +457,14 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 107 unmodified lines
451457 return AVERROR(ENOSYS);
452458 }
453459
454−static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
460+static av_cold int preinit(AVFilterContext *ctx)
455461 {
456462 SPPContext *s = ctx->priv;
457− int ret;
458463
459464 s->dct = avcodec_dct_alloc();
460465 if (!s->dct)
461466 return AVERROR(ENOMEM);
462467
463− if (opts) {
464− AVDictionaryEntry *e = NULL;
465−
466− while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
467− if ((ret = av_opt_set(s->dct, e->key, e->value, 0)) < 0)
468− return ret;
469− }
470− av_dict_free(opts);
471− }
472−
473− s->store_slice = store_slice_c;
474− switch (s->mode) {
475− case MODE_HARD: s->requantize = hardthresh_c; break;
476− case MODE_SOFT: s->requantize = softthresh_c; break;
477− }
478468 return 0;
479469 }
480470
@@ -508,7 +498,7 @@ const AVFilter ff_vf_spp = { · 27 unmodified lines
508498 .name = "spp",
509499 .description = NULL_IF_CONFIG_SMALL("Apply a simple post processing filter."),
510500 .priv_size = sizeof(SPPContext),
511− .init_dict = init_dict,
501+ .preinit = preinit,
512502 .uninit = uninit,
513503 .query_formats = query_formats,
514504 FILTER_INPUTS(spp_inputs),

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