Parts of this commit are based on: 4fa1f52e
Unified · Split
| @@ -35,17 +35,18 @@ · 34 unmodified lines | ||
| 35 | 35 | #include "internal.h" |
| 36 | 36 | |
| 37 | 37 | typedef struct { |
| 38 | + const AVClass *class; | |
| 39 | + int sample_rate_arg; | |
| 38 | 40 | double ratio; |
| 39 | 41 | struct SwrContext *swr; |
| 40 | 42 | int64_t next_pts; |
| 41 | 43 | int req_fullfilled; |
| 42 | 44 | } AResampleContext; |
| 43 | 45 | |
| 44 | −static av_cold int init(AVFilterContext *ctx, const char *args) | |
| 46 | +static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) | |
| 45 | 47 | { |
| 46 | 48 | AResampleContext *aresample = ctx->priv; |
| 47 | 49 | int ret = 0; |
| 48 | − char *argd = av_strdup(args); | |
| 49 | 50 | |
| 50 | 51 | aresample->next_pts = AV_NOPTS_VALUE; |
| 51 | 52 | aresample->swr = swr_alloc(); |
| @@ -54,27 +55,20 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 2 unmodified lines | ||
| 54 | 55 | goto end; |
| 55 | 56 | } |
| 56 | 57 | |
| 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; | |
| 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); | |
| 76 | 71 | end: |
| 77 | − av_free(argd); | |
| 78 | 72 | return ret; |
| 79 | 73 | } |
| 80 | 74 | |
| @@ -257,6 +251,34 @@ static int request_frame(AVFilterLink *outlink) · 176 unmodified lines | ||
| 257 | 251 | return ret; |
| 258 | 252 | } |
| 259 | 253 | |
| 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 | + | |
| 260 | 282 | static const AVFilterPad aresample_inputs[] = { |
| 261 | 283 | { |
| 262 | 284 | .name = "default", |
| @@ -279,10 +301,11 @@ static const AVFilterPad aresample_outputs[] = { · 16 unmodified lines | ||
| 279 | 301 | AVFilter avfilter_af_aresample = { |
| 280 | 302 | .name = "aresample", |
| 281 | 303 | .description = NULL_IF_CONFIG_SMALL("Resample audio data."), |
| 282 | − .init = init, | |
| 304 | + .init_dict = init_dict, | |
| 283 | 305 | .uninit = uninit, |
| 284 | 306 | .query_formats = query_formats, |
| 285 | 307 | .priv_size = sizeof(AResampleContext), |
| 308 | + .priv_class = &aresample_class, | |
| 286 | 309 | .inputs = aresample_inputs, |
| 287 | 310 | .outputs = aresample_outputs, |
| 288 | 311 | }; |
| @@ -676,7 +676,6 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 675 unmodified lines | ||
| 676 | 676 | static const char *const filters_left_to_update[] = { |
| 677 | 677 | "abuffer", |
| 678 | 678 | "aconvert", |
| 679 | − "aresample", | |
| 680 | 679 | "atempo", |
| 681 | 680 | "buffer", |
| 682 | 681 | "flite", |