2010-09-25 04:56:58 +03:00
|
|
|
/*
|
2012-05-22 22:01:07 +03:00
|
|
|
* Copyright 2010 S.N. Hemanth Meenakshisundaram <smeenaks ucsd edu>
|
|
|
|
* Copyright 2010 Stefano Sabatini <stefano.sabatini-lala poste it>
|
|
|
|
*
|
2010-09-25 04:56:58 +03: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
|
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2011-09-17 13:31:21 +03:00
|
|
|
|
2012-11-10 18:00:00 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
|
|
|
#include "libavutil/internal.h"
|
2012-11-12 13:32:11 +03:00
|
|
|
#include "libavutil/opt.h"
|
2012-05-12 18:58:14 +03:00
|
|
|
#include "audio.h"
|
2011-09-17 13:31:21 +03:00
|
|
|
#include "avfilter.h"
|
|
|
|
#include "internal.h"
|
2010-09-25 04:56:58 +03:00
|
|
|
|
|
|
|
typedef struct {
|
2011-09-17 13:31:21 +03:00
|
|
|
const AVClass *class;
|
|
|
|
char *channel_layout_str;
|
2011-11-25 15:51:57 +03:00
|
|
|
uint64_t channel_layout;
|
2011-09-17 13:31:21 +03:00
|
|
|
char *sample_rate_str;
|
|
|
|
int sample_rate;
|
2011-09-17 04:17:06 +03:00
|
|
|
int nb_samples; ///< number of samples per requested frame
|
|
|
|
int64_t pts;
|
2010-09-25 04:56:58 +03:00
|
|
|
} ANullContext;
|
|
|
|
|
2011-09-17 13:31:21 +03:00
|
|
|
#define OFFSET(x) offsetof(ANullContext, x)
|
2012-08-13 14:40:01 +03:00
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
2011-09-17 13:31:21 +03:00
|
|
|
|
|
|
|
static const AVOption anullsrc_options[]= {
|
2012-08-13 14:40:01 +03:00
|
|
|
{ "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
|
|
|
|
{ "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
|
|
|
|
{ "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
|
|
|
|
{ "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
|
2012-09-05 15:26:01 +03:00
|
|
|
{ "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
|
|
|
|
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
|
2011-09-17 13:31:21 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2012-06-22 15:33:09 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(anullsrc);
|
2011-09-17 13:31:21 +03:00
|
|
|
|
2013-04-12 12:13:33 +03:00
|
|
|
static int init(AVFilterContext *ctx)
|
2010-09-25 04:56:58 +03:00
|
|
|
{
|
2011-09-17 13:52:54 +03:00
|
|
|
ANullContext *null = ctx->priv;
|
2011-09-17 13:31:21 +03:00
|
|
|
int ret;
|
2010-09-25 04:56:58 +03:00
|
|
|
|
2011-09-17 13:52:54 +03:00
|
|
|
if ((ret = ff_parse_sample_rate(&null->sample_rate,
|
|
|
|
null->sample_rate_str, ctx)) < 0)
|
2011-09-17 13:31:21 +03:00
|
|
|
return ret;
|
|
|
|
|
2011-09-17 13:52:54 +03:00
|
|
|
if ((ret = ff_parse_channel_layout(&null->channel_layout,
|
|
|
|
null->channel_layout_str, ctx)) < 0)
|
2011-09-17 13:31:21 +03:00
|
|
|
return ret;
|
2010-09-25 04:56:58 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 03:35:13 +03:00
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
ANullContext *null = ctx->priv;
|
|
|
|
int64_t chlayouts[] = { null->channel_layout, -1 };
|
|
|
|
int sample_rates[] = { null->sample_rate, -1 };
|
|
|
|
|
|
|
|
ff_set_common_formats (ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
|
|
|
|
ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
|
|
|
|
ff_set_common_samplerates (ctx, ff_make_format_list(sample_rates));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-25 04:56:58 +03:00
|
|
|
static int config_props(AVFilterLink *outlink)
|
|
|
|
{
|
2011-09-17 13:52:54 +03:00
|
|
|
ANullContext *null = outlink->src->priv;
|
2010-09-25 04:56:58 +03:00
|
|
|
char buf[128];
|
|
|
|
|
2013-03-22 03:39:48 +03:00
|
|
|
av_get_channel_layout_string(buf, sizeof(buf), 0, null->channel_layout);
|
2012-06-25 07:31:38 +03:00
|
|
|
av_log(outlink->src, AV_LOG_VERBOSE,
|
2011-09-17 13:50:24 +03:00
|
|
|
"sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
|
2011-09-17 13:52:54 +03:00
|
|
|
null->sample_rate, buf, null->nb_samples);
|
2010-09-25 04:56:58 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-17 04:17:06 +03:00
|
|
|
static int request_frame(AVFilterLink *outlink)
|
2010-09-25 04:56:58 +03:00
|
|
|
{
|
2013-03-13 11:56:09 +03:00
|
|
|
int ret;
|
2011-09-17 04:17:06 +03:00
|
|
|
ANullContext *null = outlink->src->priv;
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *samplesref;
|
2011-09-17 04:17:06 +03:00
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
samplesref = ff_get_audio_buffer(outlink, null->nb_samples);
|
2013-03-22 03:43:43 +03:00
|
|
|
if (!samplesref)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2011-09-17 04:17:06 +03:00
|
|
|
samplesref->pts = null->pts;
|
2013-03-10 03:30:30 +03:00
|
|
|
samplesref->channel_layout = null->channel_layout;
|
|
|
|
samplesref->sample_rate = outlink->sample_rate;
|
2011-09-17 04:17:06 +03:00
|
|
|
|
2013-03-13 11:56:09 +03:00
|
|
|
ret = ff_filter_frame(outlink, av_frame_clone(samplesref));
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&samplesref);
|
2013-03-22 03:43:43 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-09-17 04:17:06 +03:00
|
|
|
|
|
|
|
null->pts += null->nb_samples;
|
2013-03-13 11:56:09 +03:00
|
|
|
return ret;
|
2010-09-25 04:56:58 +03:00
|
|
|
}
|
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-09-25 04:56:58 +03:00
|
|
|
AVFilter avfilter_asrc_anullsrc = {
|
|
|
|
.name = "anullsrc",
|
2011-09-18 15:26:37 +03:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
|
2010-09-25 04:56:58 +03:00
|
|
|
|
|
|
|
.init = init,
|
2013-03-22 03:35:13 +03:00
|
|
|
.query_formats = query_formats,
|
2010-09-25 04:56:58 +03:00
|
|
|
.priv_size = sizeof(ANullContext),
|
|
|
|
|
2012-09-16 14:58:49 +03:00
|
|
|
.inputs = NULL,
|
2010-09-25 04:56:58 +03:00
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
.outputs = avfilter_asrc_anullsrc_outputs,
|
2012-08-13 14:40:01 +03:00
|
|
|
.priv_class = &anullsrc_class,
|
2010-09-25 04:56:58 +03:00
|
|
|
};
|