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
37#include "internal.h"37#include "internal.h"
38 38
39typedef struct ResampleContext {39typedef struct ResampleContext {
40 const AVClass *class;
40 AVAudioResampleContext *avr;41 AVAudioResampleContext *avr;
41 AVDictionary *options;42 AVDictionary *options;
42 43
@@ -46,26 +47,30 @@ typedef struct ResampleContext { · 3 unmodified lines
46 int got_output;47 int got_output;
47} ResampleContext;48} ResampleContext;
48 49
49static av_cold int init(AVFilterContext *ctx, const char *args)50static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
50{51{
51 ResampleContext *s = ctx->priv;52 ResampleContext *s = ctx->priv;
53 const AVClass *avr_class = avresample_get_class();
54 AVDictionaryEntry *e = NULL;
52 55
53 if (args) {56 while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
54 int ret = av_dict_parse_string(&s->options, args, "=", ":", 0);57 if (av_opt_find(&avr_class, e->key, NULL, 0,
55 if (ret < 0) {58 AV_OPT_SEARCH_FAKE_OBJ | AV_OPT_SEARCH_CHILDREN))
56 av_log(ctx, AV_LOG_ERROR, "error setting option string: %s\n", args);59 av_dict_set(&s->options, e->key, e->value, 0);
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);
67 }60 }
68 61
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
69 return 0;74 return 0;
70}75}
71 76
@@ -272,6 +277,25 @@ fail: · 200 unmodified lines
272 return ret;277 return ret;
273}278}
274 279
280static const AVClass *resample_child_class_next(const AVClass *prev)
281{
282 return prev ? NULL : avresample_get_class();
283}
284
285static void *resample_child_next(void *obj, void *prev)
286{
287 ResampleContext *s = obj;
288 return prev ? NULL : s->avr;
289}
290
291static 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
275static const AVFilterPad avfilter_af_resample_inputs[] = {299static const AVFilterPad avfilter_af_resample_inputs[] = {
276 {300 {
277 .name = "default",301 .name = "default",
@@ -295,8 +319,9 @@ AVFilter avfilter_af_resample = { · 17 unmodified lines
295 .name = "resample",319 .name = "resample",
296 .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),320 .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
297 .priv_size = sizeof(ResampleContext),321 .priv_size = sizeof(ResampleContext),
322 .priv_class = &resample_class,
298 323
299 .init = init,324 .init_dict = init,
300 .uninit = uninit,325 .uninit = uninit,
301 .query_formats = query_formats,326 .query_formats = query_formats,
302 327
libavfilter/avfilter.c+5−4
@@ -501,11 +501,12 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 500 unmodified lines
501 }501 }
502 }502 }
503 503
504 if (filter->filter->init) {504 if (filter->filter->init)
505 ret = filter->filter->init(filter, args);505 ret = filter->filter->init(filter, args);
506 if (ret < 0)506 else if (filter->filter->init_dict)
507 goto fail;507 ret = filter->filter->init_dict(filter, &options);
508 }508 if (ret < 0)
509 goto fail;
509 510
510 if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {511 if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
511 av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);512 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
408 */408 */
409 int (*init)(AVFilterContext *ctx, const char *args);409 int (*init)(AVFilterContext *ctx, const char *args);
410 410
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
411 /**418 /**
412 * Filter uninitialization function. Should deallocate any memory held419 * Filter uninitialization function. Should deallocate any memory held
413 * by the filter, release any buffer references, etc. This does not need420 * 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