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.
This commit is contained in:
parent
07631deeee
commit
44ab77db9e
@ -312,26 +312,34 @@ value is "-1".
|
|||||||
Null audio source, never return audio frames. It is mainly useful as a
|
Null audio source, never return audio frames. It is mainly useful as a
|
||||||
template and to be employed in analysis / debugging tools.
|
template and to be employed in analysis / debugging tools.
|
||||||
|
|
||||||
It accepts as optional parameter a string of the form
|
It accepts an optional sequence of @var{key}=@var{value} pairs,
|
||||||
@var{sample_rate}:@var{channel_layout}.
|
separated by ":".
|
||||||
|
|
||||||
@var{sample_rate} specify the sample rate, and defaults to 44100.
|
The description of the accepted options follows.
|
||||||
|
|
||||||
@var{channel_layout} specify the channel layout, and can be either an
|
@table @option
|
||||||
integer or a string representing a channel layout. The default value
|
|
||||||
of @var{channel_layout} is 3, which corresponds to CH_LAYOUT_STEREO.
|
@item sample_rate, s
|
||||||
|
Specify the sample rate, and defaults to 44100.
|
||||||
|
|
||||||
|
@item channel_layout, cl
|
||||||
|
|
||||||
|
Specify the channel layout, and can be either an integer or a string
|
||||||
|
representing a channel layout. The default value of @var{channel_layout}
|
||||||
|
is "stereo".
|
||||||
|
|
||||||
Check the channel_layout_map definition in
|
Check the channel_layout_map definition in
|
||||||
@file{libavcodec/audioconvert.c} for the mapping between strings and
|
@file{libavcodec/audioconvert.c} for the mapping between strings and
|
||||||
channel layout values.
|
channel layout values.
|
||||||
|
@end table
|
||||||
|
|
||||||
Follow some examples:
|
Follow some examples:
|
||||||
@example
|
@example
|
||||||
# set the sample rate to 48000 Hz and the channel layout to CH_LAYOUT_MONO.
|
# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO.
|
||||||
anullsrc=48000:4
|
anullsrc=r=48000:cl=4
|
||||||
|
|
||||||
# same as
|
# same as
|
||||||
anullsrc=48000:mono
|
anullsrc=r=48000:cl=mono
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@c man end AUDIO SOURCES
|
@c man end AUDIO SOURCES
|
||||||
|
@ -21,37 +21,61 @@
|
|||||||
* null audio source
|
* null audio source
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "avfilter.h"
|
|
||||||
#include "libavutil/audioconvert.h"
|
#include "libavutil/audioconvert.h"
|
||||||
|
#include "libavutil/opt.h"
|
||||||
|
|
||||||
|
#include "avfilter.h"
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
const AVClass *class;
|
||||||
|
char *channel_layout_str;
|
||||||
int64_t channel_layout;
|
int64_t channel_layout;
|
||||||
int64_t sample_rate;
|
char *sample_rate_str;
|
||||||
|
int sample_rate;
|
||||||
} ANullContext;
|
} ANullContext;
|
||||||
|
|
||||||
|
#define OFFSET(x) offsetof(ANullContext, x)
|
||||||
|
|
||||||
|
static const AVOption anullsrc_options[]= {
|
||||||
|
{ "channel_layout", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
|
||||||
|
{ "cl", "set channel_layout", OFFSET(channel_layout_str), FF_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
|
||||||
|
{ "sample_rate", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
|
||||||
|
{ "r", "set sample rate", OFFSET(sample_rate_str) , FF_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
|
||||||
|
{ NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *anullsrc_get_name(void *ctx)
|
||||||
|
{
|
||||||
|
return "anullsrc";
|
||||||
|
}
|
||||||
|
|
||||||
|
static const AVClass anullsrc_class = {
|
||||||
|
"ANullSrcContext",
|
||||||
|
anullsrc_get_name,
|
||||||
|
anullsrc_options
|
||||||
|
};
|
||||||
|
|
||||||
static int init(AVFilterContext *ctx, const char *args, void *opaque)
|
static int init(AVFilterContext *ctx, const char *args, void *opaque)
|
||||||
{
|
{
|
||||||
ANullContext *priv = ctx->priv;
|
ANullContext *priv = ctx->priv;
|
||||||
char channel_layout_str[128] = "";
|
int ret;
|
||||||
|
|
||||||
priv->sample_rate = 44100;
|
priv->class = &anullsrc_class;
|
||||||
priv->channel_layout = AV_CH_LAYOUT_STEREO;
|
av_opt_set_defaults(priv);
|
||||||
|
|
||||||
if (args)
|
if ((ret = (av_set_options_string(priv, args, "=", ":"))) < 0) {
|
||||||
sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str);
|
av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
|
||||||
|
return ret;
|
||||||
if (priv->sample_rate < 0) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate);
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*channel_layout_str)
|
if ((ret = ff_parse_sample_rate(&priv->sample_rate,
|
||||||
if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str))
|
priv->sample_rate_str, ctx)) < 0)
|
||||||
&& sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) {
|
return ret;
|
||||||
av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n",
|
|
||||||
channel_layout_str);
|
if ((ret = ff_parse_channel_layout(&priv->channel_layout,
|
||||||
return AVERROR(EINVAL);
|
priv->channel_layout_str, ctx)) < 0)
|
||||||
}
|
return ret;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -68,7 +92,7 @@ static int config_props(AVFilterLink *outlink)
|
|||||||
chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
|
chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout);
|
||||||
av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
|
av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
|
||||||
av_log(outlink->src, AV_LOG_INFO,
|
av_log(outlink->src, AV_LOG_INFO,
|
||||||
"sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
|
"sample_rate:%d channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
|
||||||
priv->sample_rate, priv->channel_layout, buf);
|
priv->sample_rate, priv->channel_layout, buf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#define LIBAVFILTER_VERSION_MAJOR 2
|
#define LIBAVFILTER_VERSION_MAJOR 2
|
||||||
#define LIBAVFILTER_VERSION_MINOR 43
|
#define LIBAVFILTER_VERSION_MINOR 43
|
||||||
#define LIBAVFILTER_VERSION_MICRO 0
|
#define LIBAVFILTER_VERSION_MICRO 1
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||||
LIBAVFILTER_VERSION_MINOR, \
|
LIBAVFILTER_VERSION_MINOR, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user