2010-09-25 03:56:58 +02:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* null audio source
|
|
|
|
*/
|
|
|
|
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/audioconvert.h"
|
2011-09-17 12:31:21 +02:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
|
|
|
#include "avfilter.h"
|
|
|
|
#include "internal.h"
|
2010-09-25 03:56:58 +02:00
|
|
|
|
|
|
|
typedef struct {
|
2011-09-17 12:31:21 +02:00
|
|
|
const AVClass *class;
|
|
|
|
char *channel_layout_str;
|
2010-09-25 03:56:58 +02:00
|
|
|
int64_t channel_layout;
|
2011-09-17 12:31:21 +02:00
|
|
|
char *sample_rate_str;
|
|
|
|
int sample_rate;
|
2011-09-17 03:17:06 +02:00
|
|
|
int nb_samples; ///< number of samples per requested frame
|
|
|
|
int64_t pts;
|
2010-09-25 03:56:58 +02:00
|
|
|
} ANullContext;
|
|
|
|
|
2011-09-17 12:31:21 +02:00
|
|
|
#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 },
|
2011-09-17 03:17:06 +02:00
|
|
|
{ "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
|
|
|
|
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), FF_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
|
2011-09-17 12:31:21 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *anullsrc_get_name(void *ctx)
|
|
|
|
{
|
|
|
|
return "anullsrc";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const AVClass anullsrc_class = {
|
|
|
|
"ANullSrcContext",
|
|
|
|
anullsrc_get_name,
|
|
|
|
anullsrc_options
|
|
|
|
};
|
|
|
|
|
2010-09-25 03:56:58 +02:00
|
|
|
static int init(AVFilterContext *ctx, const char *args, void *opaque)
|
|
|
|
{
|
2011-09-17 12:52:54 +02:00
|
|
|
ANullContext *null = ctx->priv;
|
2011-09-17 12:31:21 +02:00
|
|
|
int ret;
|
2010-09-25 03:56:58 +02:00
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
null->class = &anullsrc_class;
|
|
|
|
av_opt_set_defaults(null);
|
2010-09-25 03:56:58 +02:00
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0) {
|
2011-09-17 12:31:21 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
|
|
|
|
return ret;
|
2010-09-25 03:56:58 +02:00
|
|
|
}
|
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
if ((ret = ff_parse_sample_rate(&null->sample_rate,
|
|
|
|
null->sample_rate_str, ctx)) < 0)
|
2011-09-17 12:31:21 +02:00
|
|
|
return ret;
|
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
if ((ret = ff_parse_channel_layout(&null->channel_layout,
|
|
|
|
null->channel_layout_str, ctx)) < 0)
|
2011-09-17 12:31:21 +02:00
|
|
|
return ret;
|
2010-09-25 03:56:58 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_props(AVFilterLink *outlink)
|
|
|
|
{
|
2011-09-17 12:52:54 +02:00
|
|
|
ANullContext *null = outlink->src->priv;
|
2010-09-25 03:56:58 +02:00
|
|
|
char buf[128];
|
|
|
|
int chans_nb;
|
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
outlink->sample_rate = null->sample_rate;
|
|
|
|
outlink->channel_layout = null->channel_layout;
|
2010-09-25 03:56:58 +02:00
|
|
|
|
2011-09-17 12:52:54 +02:00
|
|
|
chans_nb = av_get_channel_layout_nb_channels(null->channel_layout);
|
|
|
|
av_get_channel_layout_string(buf, sizeof(buf), chans_nb, null->channel_layout);
|
2010-09-25 03:56:58 +02:00
|
|
|
av_log(outlink->src, AV_LOG_INFO,
|
2011-09-17 12:50:24 +02:00
|
|
|
"sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
|
2011-09-17 12:52:54 +02:00
|
|
|
null->sample_rate, buf, null->nb_samples);
|
2010-09-25 03:56:58 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-17 03:17:06 +02:00
|
|
|
static int request_frame(AVFilterLink *outlink)
|
2010-09-25 03:56:58 +02:00
|
|
|
{
|
2011-09-17 03:17:06 +02:00
|
|
|
ANullContext *null = outlink->src->priv;
|
|
|
|
AVFilterBufferRef *samplesref;
|
|
|
|
|
|
|
|
samplesref =
|
|
|
|
avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
|
|
|
|
samplesref->pts = null->pts;
|
|
|
|
samplesref->pos = -1;
|
|
|
|
samplesref->audio->channel_layout = null->channel_layout;
|
|
|
|
samplesref->audio->sample_rate = outlink->sample_rate;
|
|
|
|
|
|
|
|
avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
|
|
|
|
avfilter_unref_buffer(samplesref);
|
|
|
|
|
|
|
|
null->pts += null->nb_samples;
|
|
|
|
return 0;
|
2010-09-25 03:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AVFilter avfilter_asrc_anullsrc = {
|
|
|
|
.name = "anullsrc",
|
2011-09-18 14:26:37 +02:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
|
2010-09-25 03:56:58 +02:00
|
|
|
|
|
|
|
.init = init,
|
|
|
|
.priv_size = sizeof(ANullContext),
|
|
|
|
|
|
|
|
.inputs = (AVFilterPad[]) {{ .name = NULL}},
|
|
|
|
|
|
|
|
.outputs = (AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame, },
|
|
|
|
{ .name = NULL}},
|
|
|
|
};
|