History

asrc_anullsrc: extend syntax to make it accept a non positional list of arguments

The new syntax is more extensible and more user-friendly. This breaks the previous syntax, should not be an issue as possibly no-one is already using anullsrc.

Stefano Sabatini committed 15 years ago

Commit 44ab77d1 parent 07631de3 files · +61 −29Browse files

Unified · Split

3 files
  1. doc/filters.texi +17 −9
  2. libavfilter/asrc_anullsrc.c +43 −19
  3. libavfilter/avfilter.h +1 −1
doc/filters.texi+17−9
@@ -312,26 +312,34 @@ value is "-1". · 311 unmodified lines
312312 Null audio source, never return audio frames. It is mainly useful as a
313313 template and to be employed in analysis / debugging tools.
314314
315−It accepts as optional parameter a string of the form
316−@var{sample_rate}:@var{channel_layout}.
315+It accepts an optional sequence of @var{key}=@var{value} pairs,
316+separated by ":".
317+
318+The description of the accepted options follows.
317319
318−@var{sample_rate} specify the sample rate, and defaults to 44100.
320+@table @option
321+
322+@item sample_rate, s
323+Specify the sample rate, and defaults to 44100.
319324
320−@var{channel_layout} specify the channel layout, and can be either an
321−integer or a string representing a channel layout. The default value
322−of @var{channel_layout} is 3, which corresponds to CH_LAYOUT_STEREO.
325+@item channel_layout, cl
326+
327+Specify the channel layout, and can be either an integer or a string
328+representing a channel layout. The default value of @var{channel_layout}
329+is "stereo".
323330
324331 Check the channel_layout_map definition in
325332 @file{libavcodec/audioconvert.c} for the mapping between strings and
326333 channel layout values.
334+@end table
327335
328336 Follow some examples:
329337 @example
330−# set the sample rate to 48000 Hz and the channel layout to CH_LAYOUT_MONO.
331−anullsrc=48000:4
338+# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO.
339+anullsrc=r=48000:cl=4
332340
333341 # same as
334−anullsrc=48000:mono
342+anullsrc=r=48000:cl=mono
335343 @end example
336344
337345 @c man end AUDIO SOURCES
libavfilter/asrc_anullsrc.c+43−19
@@ -21,37 +21,61 @@ · 20 unmodified lines
2121 * null audio source
2222 */
2323
24−#include "avfilter.h"
2524 #include "libavutil/audioconvert.h"
25+#include "libavutil/opt.h"
26+
27+#include "avfilter.h"
28+#include "internal.h"
2629
2730 typedef struct {
31+ const AVClass *class;
32+ char *channel_layout_str;
2833 int64_t channel_layout;
29− int64_t sample_rate;
34+ char *sample_rate_str;
35+ int sample_rate;
3036 } ANullContext;
3137
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+
3259 static int init(AVFilterContext *ctx, const char *args, void *opaque)
3360 {
3461 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;
3963
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);
4266
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;
4670 }
4771
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;
5579
5680 return 0;
5781 }
@@ -68,7 +92,7 @@ static int config_props(AVFilterLink *outlink) · 10 unmodified lines
6892 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
6993 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
7094 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",
7296 priv->sample_rate, priv->channel_layout, buf);
7397
7498 return 0;
libavfilter/avfilter.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030
3131 #define LIBAVFILTER_VERSION_MAJOR 2
3232 #define LIBAVFILTER_VERSION_MINOR 43
33−#define LIBAVFILTER_VERSION_MICRO 0
33+#define LIBAVFILTER_VERSION_MICRO 1
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3636 LIBAVFILTER_VERSION_MINOR, \

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