Parts of this commit are based on: 4fa1f52e
Unified · Split
| @@ -35,17 +35,18 @@ · 34 unmodified lines | |||
| 35 | #include "internal.h" | 35 | #include "internal.h" |
| 36 | 36 | ||
| 37 | typedef struct { | 37 | typedef 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 | ||
| 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 | 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); | ||
| 76 | end: | 71 | end: |
| 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 | ||
| 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 | static const AVFilterPad aresample_inputs[] = { | 282 | static const AVFilterPad aresample_inputs[] = { |
| 261 | { | 283 | { |
| 262 | .name = "default", | 284 | .name = "default", |
| @@ -279,10 +301,11 @@ static const AVFilterPad aresample_outputs[] = { · 16 unmodified lines | |||
| 279 | AVFilter avfilter_af_aresample = { | 301 | AVFilter 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 | }; |
| @@ -676,7 +676,6 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, · 675 unmodified lines | |||
| 676 | static const char *const filters_left_to_update[] = { | 676 | static 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", |