diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-04-10 13:27:33 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-04-10 13:30:17 +0200 |
commit | 828044aca289f12356e1bdcda232430d8ed22e2d (patch) | |
tree | 89109e640f924cc01ea92b6879c752b3f9bb0257 /libavfilter | |
parent | d2752ef0615d0ce9cdf6effed97cd4750ffde4a9 (diff) | |
parent | 4fa1f52e33b70029e2b621852f3af7c1ef9aecff (diff) | |
download | ffmpeg-828044aca289f12356e1bdcda232430d8ed22e2d.tar.gz |
Merge commit '4fa1f52e33b70029e2b621852f3af7c1ef9aecff'
* commit '4fa1f52e33b70029e2b621852f3af7c1ef9aecff':
af_resample: switch to an AVOptions-based system.
Conflicts:
libavfilter/avfilter.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/af_resample.c | 57 | ||||
-rw-r--r-- | libavfilter/avfilter.c | 20 | ||||
-rw-r--r-- | libavfilter/avfilter.h | 7 |
3 files changed, 59 insertions, 25 deletions
diff --git a/libavfilter/af_resample.c b/libavfilter/af_resample.c index f82a970bb3..7e86684c64 100644 --- a/libavfilter/af_resample.c +++ b/libavfilter/af_resample.c @@ -37,6 +37,7 @@ #include "internal.h" typedef struct ResampleContext { + const AVClass *class; AVAudioResampleContext *avr; AVDictionary *options; @@ -46,26 +47,30 @@ typedef struct ResampleContext { int got_output; } ResampleContext; -static av_cold int init(AVFilterContext *ctx, const char *args) +static av_cold int init(AVFilterContext *ctx, AVDictionary **opts) { ResampleContext *s = ctx->priv; + const AVClass *avr_class = avresample_get_class(); + AVDictionaryEntry *e = NULL; - if (args) { - int ret = av_dict_parse_string(&s->options, args, "=", ":", 0); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "error setting option string: %s\n", args); - return ret; - } - - /* do not allow the user to override basic format options */ - av_dict_set(&s->options, "in_channel_layout", NULL, 0); - av_dict_set(&s->options, "out_channel_layout", NULL, 0); - av_dict_set(&s->options, "in_sample_fmt", NULL, 0); - av_dict_set(&s->options, "out_sample_fmt", NULL, 0); - av_dict_set(&s->options, "in_sample_rate", NULL, 0); - av_dict_set(&s->options, "out_sample_rate", NULL, 0); + while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) { + if (av_opt_find(&avr_class, e->key, NULL, 0, + AV_OPT_SEARCH_FAKE_OBJ | AV_OPT_SEARCH_CHILDREN)) + av_dict_set(&s->options, e->key, e->value, 0); } + e = NULL; + while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX))) + av_dict_set(opts, e->key, NULL, 0); + + /* do not allow the user to override basic format options */ + av_dict_set(&s->options, "in_channel_layout", NULL, 0); + av_dict_set(&s->options, "out_channel_layout", NULL, 0); + av_dict_set(&s->options, "in_sample_fmt", NULL, 0); + av_dict_set(&s->options, "out_sample_fmt", NULL, 0); + av_dict_set(&s->options, "in_sample_rate", NULL, 0); + av_dict_set(&s->options, "out_sample_rate", NULL, 0); + return 0; } @@ -272,6 +277,25 @@ fail: return ret; } +static const AVClass *resample_child_class_next(const AVClass *prev) +{ + return prev ? NULL : avresample_get_class(); +} + +static void *resample_child_next(void *obj, void *prev) +{ + ResampleContext *s = obj; + return prev ? NULL : s->avr; +} + +static const AVClass resample_class = { + .class_name = "resample", + .item_name = av_default_item_name, + .version = LIBAVUTIL_VERSION_INT, + .child_class_next = resample_child_class_next, + .child_next = resample_child_next, +}; + static const AVFilterPad avfilter_af_resample_inputs[] = { { .name = "default", @@ -295,8 +319,9 @@ AVFilter avfilter_af_resample = { .name = "resample", .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."), .priv_size = sizeof(ResampleContext), + .priv_class = &resample_class, - .init = init, + .init_dict = init, .uninit = uninit, .query_formats = query_formats, diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 0b6a65266f..25036fe3a4 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -653,7 +653,9 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque AVDictionary *options = NULL; AVDictionaryEntry *e; int ret=0; - int anton_options = 0; + int anton_options = + !strcmp(filter->filter->name, "resample") + ; if (filter->filter->shorthand) { av_assert0(filter->priv); @@ -688,14 +690,14 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque } } - if (filter->filter->init || filter->filter->init_opaque) { - if (filter->filter->init_opaque) - ret = filter->filter->init_opaque(filter, args, opaque); - else - ret = filter->filter->init(filter, args); - if (ret < 0) - goto fail; - } + if (filter->filter->init_opaque) + ret = filter->filter->init_opaque(filter, args, opaque); + else if (filter->filter->init) + ret = filter->filter->init(filter, args); + else if (filter->filter->init_dict) + ret = filter->filter->init_dict(filter, &options); + if (ret < 0) + goto fail; if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) { av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 282d4dfb51..b19d652f86 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -452,6 +452,13 @@ typedef struct AVFilter { int (*init)(AVFilterContext *ctx, const char *args); /** + * Should be set instead of init by the filters that want to pass a + * dictionary of AVOptions to nested contexts that are allocated in + * init. + */ + int (*init_dict)(AVFilterContext *ctx, AVDictionary **options); + + /** * Filter uninitialization function. Should deallocate any memory held * by the filter, release any buffer references, etc. This does not need * to deallocate the AVFilterContext->priv memory itself. |