| @@ -25,6 +25,7 @@ · 24 unmodified lines |
| 25 | 25 | #include "libavutil/avassert.h" |
| 26 | 26 | #include "libavutil/avstring.h" |
| 27 | 27 | #include "libavutil/common.h" |
| 28 | +#include "libavutil/dict.h" |
| 28 | 29 | #include "libavutil/mathematics.h" |
| 29 | 30 | #include "libavutil/opt.h" |
| 30 | 31 | |
| @@ -37,6 +38,7 @@ · 6 unmodified lines |
| 37 | 38 | |
| 38 | 39 | typedef struct ResampleContext { |
| 39 | 40 | AVAudioResampleContext *avr; |
| 41 | + AVDictionary *options; |
| 40 | 42 | |
| 41 | 43 | int64_t next_pts; |
| 42 | 44 | |
| @@ -44,6 +46,29 @@ typedef struct ResampleContext { · 1 unmodified line |
| 44 | 46 | int got_output; |
| 45 | 47 | } ResampleContext; |
| 46 | 48 | |
| 49 | +static av_cold int init(AVFilterContext *ctx, const char *args) |
| 50 | +{ |
| 51 | + ResampleContext *s = ctx->priv; |
| 52 | + |
| 53 | + if (args) { |
| 54 | + int ret = av_dict_parse_string(&s->options, args, "=", ":", 0); |
| 55 | + if (ret < 0) { |
| 56 | + av_log(ctx, AV_LOG_ERROR, "error setting option string: %s\n", args); |
| 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 | + } |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
| 71 | + |
| 47 | 72 | static av_cold void uninit(AVFilterContext *ctx) |
| 48 | 73 | { |
| 49 | 74 | ResampleContext *s = ctx->priv; |
| @@ -52,6 +77,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 2 unmodified lines |
| 52 | 77 | avresample_close(s->avr); |
| 53 | 78 | avresample_free(&s->avr); |
| 54 | 79 | } |
| 80 | + av_dict_free(&s->options); |
| 55 | 81 | } |
| 56 | 82 | |
| 57 | 83 | static int query_formats(AVFilterContext *ctx) |
| @@ -103,6 +129,14 @@ static int config_output(AVFilterLink *outlink) · 45 unmodified lines |
| 103 | 129 | if (!(s->avr = avresample_alloc_context())) |
| 104 | 130 | return AVERROR(ENOMEM); |
| 105 | 131 | |
| 132 | + if (s->options) { |
| 133 | + AVDictionaryEntry *e = NULL; |
| 134 | + while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX))) |
| 135 | + av_log(ctx, AV_LOG_VERBOSE, "lavr option: %s=%s\n", e->key, e->value); |
| 136 | + |
| 137 | + av_opt_set_dict(s->avr, &s->options); |
| 138 | + } |
| 139 | + |
| 106 | 140 | av_opt_set_int(s->avr, "in_channel_layout", inlink ->channel_layout, 0); |
| 107 | 141 | av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0); |
| 108 | 142 | av_opt_set_int(s->avr, "in_sample_fmt", inlink ->format, 0); |
| @@ -264,6 +298,7 @@ AVFilter avfilter_af_resample = { · 155 unmodified lines |
| 264 | 298 | .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."), |
| 265 | 299 | .priv_size = sizeof(ResampleContext), |
| 266 | 300 | |
| 301 | + .init = init, |
| 267 | 302 | .uninit = uninit, |
| 268 | 303 | .query_formats = query_formats, |
| 269 | 304 | |