History

af_resample: switch to an AVOptions-based system.

Anton Khirnov committed 13 years ago

Commit 4fa1f521 parent b439c993 files · +53 −20Browse files

Unified · Split

3 files
  1. libavfilter/af_resample.c +41 −16
  2. libavfilter/avfilter.c +5 −4
  3. libavfilter/avfilter.h +7 −0
libavfilter/af_resample.c+41−16
@@ -37,6 +37,7 @@ · 36 unmodified lines
3737 #include "internal.h"
3838
3939 typedef struct ResampleContext {
40+ const AVClass *class;
4041 AVAudioResampleContext *avr;
4142 AVDictionary *options;
4243
@@ -46,26 +47,30 @@ typedef struct ResampleContext { · 3 unmodified lines
4647 int got_output;
4748 } ResampleContext;
4849
49−static av_cold int init(AVFilterContext *ctx, const char *args)
50+static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
5051 {
5152 ResampleContext *s = ctx->priv;
53+ const AVClass *avr_class = avresample_get_class();
54+ AVDictionaryEntry *e = NULL;
5255
53− if (args) {
54− int ret = av_dict_parse_string(&s->options, args, "=", ":", 0);
55− if (ret < 0) {
56− av_log(ctx, AV_LOG_ERROR, "error setting option string: %s\n", args);
57− return ret;
58− }
59−
60− /* do not allow the user to override basic format options */
61− av_dict_set(&s->options, "in_channel_layout", NULL, 0);
62− av_dict_set(&s->options, "out_channel_layout", NULL, 0);
63− av_dict_set(&s->options, "in_sample_fmt", NULL, 0);
64− av_dict_set(&s->options, "out_sample_fmt", NULL, 0);
65− av_dict_set(&s->options, "in_sample_rate", NULL, 0);
66− av_dict_set(&s->options, "out_sample_rate", NULL, 0);
56+ while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
57+ if (av_opt_find(&avr_class, e->key, NULL, 0,
58+ AV_OPT_SEARCH_FAKE_OBJ | AV_OPT_SEARCH_CHILDREN))
59+ av_dict_set(&s->options, e->key, e->value, 0);
6760 }
6861
62+ e = NULL;
63+ while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
64+ av_dict_set(opts, e->key, NULL, 0);
65+
66+ /* do not allow the user to override basic format options */
67+ av_dict_set(&s->options, "in_channel_layout", NULL, 0);
68+ av_dict_set(&s->options, "out_channel_layout", NULL, 0);
69+ av_dict_set(&s->options, "in_sample_fmt", NULL, 0);
70+ av_dict_set(&s->options, "out_sample_fmt", NULL, 0);
71+ av_dict_set(&s->options, "in_sample_rate", NULL, 0);
72+ av_dict_set(&s->options, "out_sample_rate", NULL, 0);
73+
6974 return 0;
7075 }
7176
@@ -272,6 +277,25 @@ fail: · 200 unmodified lines
272277 return ret;
273278 }
274279
280+static const AVClass *resample_child_class_next(const AVClass *prev)
281+{
282+ return prev ? NULL : avresample_get_class();
283+}
284+
285+static void *resample_child_next(void *obj, void *prev)
286+{
287+ ResampleContext *s = obj;
288+ return prev ? NULL : s->avr;
289+}
290+
291+static const AVClass resample_class = {
292+ .class_name = "resample",
293+ .item_name = av_default_item_name,
294+ .version = LIBAVUTIL_VERSION_INT,
295+ .child_class_next = resample_child_class_next,
296+ .child_next = resample_child_next,
297+};
298+
275299 static const AVFilterPad avfilter_af_resample_inputs[] = {
276300 {
277301 .name = "default",
@@ -295,8 +319,9 @@ AVFilter avfilter_af_resample = { · 17 unmodified lines
295319 .name = "resample",
296320 .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
297321 .priv_size = sizeof(ResampleContext),
322+ .priv_class = &resample_class,
298323
299− .init = init,
324+ .init_dict = init,
300325 .uninit = uninit,
301326 .query_formats = query_formats,
302327
libavfilter/avfilter.c+5−4
@@ -501,11 +501,12 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 500 unmodified lines
501501 }
502502 }
503503
504− if (filter->filter->init) {
504+ if (filter->filter->init)
505505 ret = filter->filter->init(filter, args);
506− if (ret < 0)
507− goto fail;
508− }
506+ else if (filter->filter->init_dict)
507+ ret = filter->filter->init_dict(filter, &options);
508+ if (ret < 0)
509+ goto fail;
509510
510511 if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
511512 av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
libavfilter/avfilter.h+7−0
@@ -408,6 +408,13 @@ typedef struct AVFilter { · 407 unmodified lines
408408 */
409409 int (*init)(AVFilterContext *ctx, const char *args);
410410
411+ /**
412+ * Should be set instead of init by the filters that want to pass a
413+ * dictionary of AVOptions to nested contexts that are allocated in
414+ * init.
415+ */
416+ int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
417+
411418 /**
412419 * Filter uninitialization function. Should deallocate any memory held
413420 * by the filter, release any buffer references, etc. This does not need

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