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
35#include "internal.h"35#include "internal.h"
36 36
37typedef struct {37typedef struct {
38 const AVClass *class;
39 int sample_rate_arg;
38 double ratio;40 double ratio;
39 struct SwrContext *swr;41 struct SwrContext *swr;
40 int64_t next_pts;42 int64_t next_pts;
41 int req_fullfilled;43 int req_fullfilled;
42} AResampleContext;44} AResampleContext;
43 45
44static av_cold int init(AVFilterContext *ctx, const char *args)46static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
45{47{
46 AResampleContext *aresample = ctx->priv;48 AResampleContext *aresample = ctx->priv;
47 int ret = 0;49 int ret = 0;
48 char *argd = av_strdup(args);
49 50
50 aresample->next_pts = AV_NOPTS_VALUE;51 aresample->next_pts = AV_NOPTS_VALUE;
51 aresample->swr = swr_alloc();52 aresample->swr = swr_alloc();
@@ -54,27 +55,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 2 unmodified lines
54 goto end;55 goto end;
55 }56 }
56 57
57 if (args) {58 if (opts) {
58 char *ptr = argd, *token;59 AVDictionaryEntry *e = NULL;
59 60
60 while (token = av_strtok(ptr, ":", &ptr)) {61 while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
61 char *value;62 const char *token = e->key;
62 av_strtok(token, "=", &value);63 const char *value = e->value;
63 64 if ((ret = av_opt_set(aresample->swr, token, value, 0)) < 0)
64 if (value) {65 goto end;
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 }
74 }66 }
67 av_dict_free(opts);
75 }68 }
69 if (aresample->sample_rate_arg > 0)
70 av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
76end:71end:
77 av_free(argd);
78 return ret;72 return ret;
79}73}
80 74
@@ -257,6 +251,34 @@ static int request_frame(AVFilterLink *outlink) · 176 unmodified lines
257 return ret;251 return ret;
258}252}
259 253
254static const AVClass *resample_child_class_next(const AVClass *prev)
255{
256 return prev ? NULL : swr_get_class();
257}
258
259static 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
268static 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
273static 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
260static const AVFilterPad aresample_inputs[] = {282static const AVFilterPad aresample_inputs[] = {
261 {283 {
262 .name = "default",284 .name = "default",
@@ -279,10 +301,11 @@ static const AVFilterPad aresample_outputs[] = { · 16 unmodified lines
279AVFilter avfilter_af_aresample = {301AVFilter avfilter_af_aresample = {
280 .name = "aresample",302 .name = "aresample",
281 .description = NULL_IF_CONFIG_SMALL("Resample audio data."),303 .description = NULL_IF_CONFIG_SMALL("Resample audio data."),
282 .init = init,304 .init_dict = init_dict,
283 .uninit = uninit,305 .uninit = uninit,
284 .query_formats = query_formats,306 .query_formats = query_formats,
285 .priv_size = sizeof(AResampleContext),307 .priv_size = sizeof(AResampleContext),
308 .priv_class = &aresample_class,
286 .inputs = aresample_inputs,309 .inputs = aresample_inputs,
287 .outputs = aresample_outputs,310 .outputs = aresample_outputs,
288};311};
libavfilter/avfilter.c+0−1
@@ -676,7 +676,6 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 675 unmodified lines
676static const char *const filters_left_to_update[] = {676static const char *const filters_left_to_update[] = {
677 "abuffer",677 "abuffer",
678 "aconvert",678 "aconvert",
679 "aresample",
680 "atempo",679 "atempo",
681 "buffer",680 "buffer",
682 "flite",681 "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