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
312Null audio source, never return audio frames. It is mainly useful as a312Null audio source, never return audio frames. It is mainly useful as a
313template and to be employed in analysis / debugging tools.313template and to be employed in analysis / debugging tools.
314 314
315It accepts as optional parameter a string of the form315It accepts an optional sequence of @var{key}=@var{value} pairs,
316@var{sample_rate}:@var{channel_layout}.316separated by ":".
317
318The description of the accepted options follows.
317 319
318@var{sample_rate} specify the sample rate, and defaults to 44100.320@table @option
321
322@item sample_rate, s
323Specify the sample rate, and defaults to 44100.
319 324
320@var{channel_layout} specify the channel layout, and can be either an325@item channel_layout, cl
321integer or a string representing a channel layout. The default value326
322of @var{channel_layout} is 3, which corresponds to CH_LAYOUT_STEREO.327Specify the channel layout, and can be either an integer or a string
328representing a channel layout. The default value of @var{channel_layout}
329is "stereo".
323 330
324Check the channel_layout_map definition in331Check the channel_layout_map definition in
325@file{libavcodec/audioconvert.c} for the mapping between strings and332@file{libavcodec/audioconvert.c} for the mapping between strings and
326channel layout values.333channel layout values.
334@end table
327 335
328Follow some examples:336Follow some examples:
329@example337@example
330# set the sample rate to 48000 Hz and the channel layout to CH_LAYOUT_MONO.338# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO.
331anullsrc=48000:4339anullsrc=r=48000:cl=4
332 340
333# same as341# same as
334anullsrc=48000:mono342anullsrc=r=48000:cl=mono
335@end example343@end example
336 344
337@c man end AUDIO SOURCES345@c man end AUDIO SOURCES
libavfilter/asrc_anullsrc.c+43−19
@@ -21,37 +21,61 @@ · 20 unmodified lines
21 * null audio source21 * null audio source
22 */22 */
23 23
24#include "avfilter.h"
25#include "libavutil/audioconvert.h"24#include "libavutil/audioconvert.h"
25#include "libavutil/opt.h"
26
27#include "avfilter.h"
28#include "internal.h"
26 29
27typedef struct {30typedef struct {
31 const AVClass *class;
32 char *channel_layout_str;
28 int64_t channel_layout;33 int64_t channel_layout;
29 int64_t sample_rate;34 char *sample_rate_str;
35 int sample_rate;
30} ANullContext;36} ANullContext;
31 37
38#define OFFSET(x) offsetof(ANullContext, x)
39
40static 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
48static const char *anullsrc_get_name(void *ctx)
49{
50 return "anullsrc";
51}
52
53static const AVClass anullsrc_class = {
54 "ANullSrcContext",
55 anullsrc_get_name,
56 anullsrc_options
57};
58
32static int init(AVFilterContext *ctx, const char *args, void *opaque)59static int init(AVFilterContext *ctx, const char *args, void *opaque)
33{60{
34 ANullContext *priv = ctx->priv;61 ANullContext *priv = ctx->priv;
35 char channel_layout_str[128] = "";62 int ret;
36
37 priv->sample_rate = 44100;
38 priv->channel_layout = AV_CH_LAYOUT_STEREO;
39 63
40 if (args)64 priv->class = &anullsrc_class;
41 sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str);65 av_opt_set_defaults(priv);
42 66
43 if (priv->sample_rate < 0) {67 if ((ret = (av_set_options_string(priv, args, "=", ":"))) < 0) {
44 av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate);68 av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
45 return AVERROR(EINVAL);69 return ret;
46 }70 }
47 71
48 if (*channel_layout_str)72 if ((ret = ff_parse_sample_rate(&priv->sample_rate,
49 if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str))73 priv->sample_rate_str, ctx)) < 0)
50 && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) {74 return ret;
51 av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n",75
52 channel_layout_str);76 if ((ret = ff_parse_channel_layout(&priv->channel_layout,
53 return AVERROR(EINVAL);77 priv->channel_layout_str, ctx)) < 0)
54 }78 return ret;
55 79
56 return 0;80 return 0;
57}81}
@@ -68,7 +92,7 @@ static int config_props(AVFilterLink *outlink) · 10 unmodified lines
68 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);92 chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
69 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);93 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
70 av_log(outlink->src, AV_LOG_INFO,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 priv->sample_rate, priv->channel_layout, buf);96 priv->sample_rate, priv->channel_layout, buf);
73 97
74 return 0;98 return 0;
libavfilter/avfilter.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30 30
31#define LIBAVFILTER_VERSION_MAJOR 231#define LIBAVFILTER_VERSION_MAJOR 2
32#define LIBAVFILTER_VERSION_MINOR 4332#define LIBAVFILTER_VERSION_MINOR 43
33#define LIBAVFILTER_VERSION_MICRO 033#define LIBAVFILTER_VERSION_MICRO 1
34 34
35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 LIBAVFILTER_VERSION_MINOR, \36 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