History

avfilter/aresample: use init_dict system and set child AVOption context correctly

Parts of this commit are based on: 4fa1f52e

Michael Niedermayer committed 13 years ago

Commit 4f43e9b1 parent f6bfeef2 files · +44 −22Browse files

Unified · Split

2 files
  1. libavfilter/af_aresample.c +44 −21
  2. libavfilter/avfilter.c +0 −1
libavfilter/af_aresample.c+44−21
@@ -35,17 +35,18 @@ · 34 unmodified lines
3535 #include "internal.h"
3636
3737 typedef struct {
38+ const AVClass *class;
39+ int sample_rate_arg;
3840 double ratio;
3941 struct SwrContext *swr;
4042 int64_t next_pts;
4143 int req_fullfilled;
4244 } AResampleContext;
4345
44−static av_cold int init(AVFilterContext *ctx, const char *args)
46+static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
4547 {
4648 AResampleContext *aresample = ctx->priv;
4749 int ret = 0;
48− char *argd = av_strdup(args);
4950
5051 aresample->next_pts = AV_NOPTS_VALUE;
5152 aresample->swr = swr_alloc();
@@ -54,27 +55,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 2 unmodified lines
5455 goto end;
5556 }
5657
57− if (args) {
58− char *ptr = argd, *token;
59−
60− while (token = av_strtok(ptr, ":", &ptr)) {
61− char *value;
62− av_strtok(token, "=", &value);
63−
64− if (value) {
65− if ((ret = av_opt_set(aresample->swr, token, value, 0)) < 0)
66− goto end;
67− } else {
68− int out_rate;
69− if ((ret = ff_parse_sample_rate(&out_rate, token, ctx)) < 0)
70− goto end;
71− if ((ret = av_opt_set_int(aresample->swr, "osr", out_rate, 0)) < 0)
72− goto end;
73− }
58+ if (opts) {
59+ AVDictionaryEntry *e = NULL;
60+
61+ while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
62+ const char *token = e->key;
63+ const char *value = e->value;
64+ if ((ret = av_opt_set(aresample->swr, token, value, 0)) < 0)
65+ goto end;
7466 }
67+ av_dict_free(opts);
7568 }
69+ if (aresample->sample_rate_arg > 0)
70+ av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
7671 end:
77− av_free(argd);
7872 return ret;
7973 }
8074
@@ -257,6 +251,34 @@ static int request_frame(AVFilterLink *outlink) · 176 unmodified lines
257251 return ret;
258252 }
259253
254+static const AVClass *resample_child_class_next(const AVClass *prev)
255+{
256+ return prev ? NULL : swr_get_class();
257+}
258+
259+static void *resample_child_next(void *obj, void *prev)
260+{
261+ AResampleContext *s = obj;
262+ return prev ? NULL : s->swr;
263+}
264+
265+#define OFFSET(x) offsetof(AResampleContext, x)
266+#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
267+
268+static const AVOption options[] = {
269+ {"sample_rate", NULL, OFFSET(sample_rate_arg), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
270+ {NULL}
271+};
272+
273+static const AVClass aresample_class = {
274+ .class_name = "aresample",
275+ .item_name = av_default_item_name,
276+ .option = options,
277+ .version = LIBAVUTIL_VERSION_INT,
278+ .child_class_next = resample_child_class_next,
279+ .child_next = resample_child_next,
280+};
281+
260282 static const AVFilterPad aresample_inputs[] = {
261283 {
262284 .name = "default",
@@ -279,10 +301,11 @@ static const AVFilterPad aresample_outputs[] = { · 16 unmodified lines
279301 AVFilter avfilter_af_aresample = {
280302 .name = "aresample",
281303 .description = NULL_IF_CONFIG_SMALL("Resample audio data."),
282− .init = init,
304+ .init_dict = init_dict,
283305 .uninit = uninit,
284306 .query_formats = query_formats,
285307 .priv_size = sizeof(AResampleContext),
308+ .priv_class = &aresample_class,
286309 .inputs = aresample_inputs,
287310 .outputs = aresample_outputs,
288311 };
libavfilter/avfilter.c+0−1
@@ -676,7 +676,6 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 675 unmodified lines
676676 static const char *const filters_left_to_update[] = {
677677 "abuffer",
678678 "aconvert",
679− "aresample",
680679 "atempo",
681680 "buffer",
682681 "flite",

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