| @@ -21,37 +21,61 @@ · 20 unmodified lines |
| 21 | 21 | * null audio source |
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | | −#include "avfilter.h" |
| 25 | 24 | #include "libavutil/audioconvert.h" |
| 25 | +#include "libavutil/opt.h" |
| 26 | + |
| 27 | +#include "avfilter.h" |
| 28 | +#include "internal.h" |
| 26 | 29 | |
| 27 | 30 | typedef struct { |
| 31 | + const AVClass *class; |
| 32 | + char *channel_layout_str; |
| 28 | 33 | int64_t channel_layout; |
| 29 | | − int64_t sample_rate; |
| 34 | + char *sample_rate_str; |
| 35 | + int sample_rate; |
| 30 | 36 | } ANullContext; |
| 31 | 37 | |
| 38 | +#define OFFSET(x) offsetof(ANullContext, x) |
| 39 | + |
| 40 | +static const AVOption anullsrc_options[]= { |
| 41 | + { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 }, |
| 42 | + { "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 }, |
| 43 | + { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 }, |
| 44 | + { "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 }, |
| 45 | + { NULL }, |
| 46 | +}; |
| 47 | + |
| 48 | +static const char *anullsrc_get_name(void *ctx) |
| 49 | +{ |
| 50 | + return "anullsrc"; |
| 51 | +} |
| 52 | + |
| 53 | +static const AVClass anullsrc_class = { |
| 54 | + "ANullSrcContext", |
| 55 | + anullsrc_get_name, |
| 56 | + anullsrc_options |
| 57 | +}; |
| 58 | + |
| 32 | 59 | static int init(AVFilterContext *ctx, const char *args, void *opaque) |
| 33 | 60 | { |
| 34 | 61 | ANullContext *priv = ctx->priv; |
| 35 | | − char channel_layout_str[128] = ""; |
| 36 | | − |
| 37 | | − priv->sample_rate = 44100; |
| 38 | | − priv->channel_layout = AV_CH_LAYOUT_STEREO; |
| 62 | + int ret; |
| 39 | 63 | |
| 40 | | − if (args) |
| 41 | | − sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str); |
| 64 | + priv->class = &anullsrc_class; |
| 65 | + av_opt_set_defaults(priv); |
| 42 | 66 | |
| 43 | | − if (priv->sample_rate < 0) { |
| 44 | | − av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate); |
| 45 | | − return AVERROR(EINVAL); |
| 67 | + if ((ret = (av_set_options_string(priv, args, "=", ":"))) < 0) { |
| 68 | + av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); |
| 69 | + return ret; |
| 46 | 70 | } |
| 47 | 71 | |
| 48 | | − if (*channel_layout_str) |
| 49 | | − if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str)) |
| 50 | | − && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) { |
| 51 | | − av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n", |
| 52 | | − channel_layout_str); |
| 53 | | − return AVERROR(EINVAL); |
| 54 | | − } |
| 72 | + if ((ret = ff_parse_sample_rate(&priv->sample_rate, |
| 73 | + priv->sample_rate_str, ctx)) < 0) |
| 74 | + return ret; |
| 75 | + |
| 76 | + if ((ret = ff_parse_channel_layout(&priv->channel_layout, |
| 77 | + priv->channel_layout_str, ctx)) < 0) |
| 78 | + return ret; |
| 55 | 79 | |
| 56 | 80 | return 0; |
| 57 | 81 | } |
| @@ -68,7 +92,7 @@ static int config_props(AVFilterLink *outlink) · 10 unmodified lines |
| 68 | 92 | chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout); |
| 69 | 93 | av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout); |
| 70 | 94 | av_log(outlink->src, AV_LOG_INFO, |
| 71 | | − "sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n", |
| 95 | + "sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s'\n", |
| 72 | 96 | priv->sample_rate, priv->channel_layout, buf); |
| 73 | 97 | |
| 74 | 98 | return 0; |