2010-09-25 03:56:58 +02:00
|
|
|
/*
|
2012-05-22 21:01:07 +02:00
|
|
|
* Copyright 2010 S.N. Hemanth Meenakshisundaram <smeenaks ucsd edu>
|
|
|
|
* Copyright 2010 Stefano Sabatini <stefano.sabatini-lala poste it>
|
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
|
2012-08-06 15:49:32 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2011-09-17 12:31:21 +02:00
|
|
|
|
2012-11-10 16:00:00 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
|
|
|
#include "libavutil/internal.h"
|
2012-11-12 11:32:11 +01:00
|
|
|
#include "libavutil/opt.h"
|
2012-05-12 17:58:14 +02:00
|
|
|
#include "audio.h"
|
2011-09-17 12:31:21 +02:00
|
|
|
#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;
|
2011-11-25 13:51:57 +01:00
|
|
|
uint64_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)
|
2012-08-13 13:40:01 +02:00
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
2011-09-17 12:31:21 +02:00
|
|
|
|
|
|
|
static const AVOption anullsrc_options[]= {
|
2012-08-13 13:40:01 +02: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 14:26:01 +02: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 },
|
2013-09-07 14:13:50 +02:00
|
|
|
{ NULL }
|
2011-09-17 12:31:21 +02:00
|
|
|
};
|
|
|
|
|
2012-06-22 14:33:09 +02:00
|
|
|
AVFILTER_DEFINE_CLASS(anullsrc);
|
2011-09-17 12:31:21 +02:00
|
|
|
|
2013-09-27 20:51:49 +02:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2010-09-25 03:56:58 +02:00
|
|
|
{
|
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
|
|
|
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;
|
|
|
|
|
2013-10-25 15:07:40 +02:00
|
|
|
if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL,
|
2011-09-17 12:52:54 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:35:13 +01: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 };
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2013-03-22 01:35:13 +01:00
|
|
|
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_set_common_formats (ctx, ff_all_formats (AVMEDIA_TYPE_AUDIO))) < 0 ||
|
|
|
|
(ret = ff_set_common_channel_layouts (ctx, avfilter_make_format64_list (chlayouts ))) < 0 ||
|
|
|
|
(ret = ff_set_common_samplerates (ctx, ff_make_format_list (sample_rates ))) < 0)
|
|
|
|
return ret;
|
2013-03-22 01:35:13 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-25 03:56:58 +02:00
|
|
|
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];
|
|
|
|
|
2013-03-22 01:39:48 +01:00
|
|
|
av_get_channel_layout_string(buf, sizeof(buf), 0, null->channel_layout);
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(outlink->src, AV_LOG_VERBOSE,
|
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
|
|
|
{
|
2013-03-13 09:56:09 +01:00
|
|
|
int ret;
|
2011-09-17 03:17:06 +02:00
|
|
|
ANullContext *null = outlink->src->priv;
|
2013-03-10 01:30:30 +01:00
|
|
|
AVFrame *samplesref;
|
2011-09-17 03:17:06 +02:00
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
samplesref = ff_get_audio_buffer(outlink, null->nb_samples);
|
2013-03-22 01:43:43 +01:00
|
|
|
if (!samplesref)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2011-09-17 03:17:06 +02:00
|
|
|
samplesref->pts = null->pts;
|
2013-03-10 01:30:30 +01:00
|
|
|
samplesref->channel_layout = null->channel_layout;
|
|
|
|
samplesref->sample_rate = outlink->sample_rate;
|
2011-09-17 03:17:06 +02:00
|
|
|
|
2013-03-13 09:56:09 +01:00
|
|
|
ret = ff_filter_frame(outlink, av_frame_clone(samplesref));
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_free(&samplesref);
|
2013-03-22 01:43:43 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-09-17 03:17:06 +02:00
|
|
|
|
|
|
|
null->pts += null->nb_samples;
|
2013-03-13 09:56:09 +01:00
|
|
|
return ret;
|
2010-09-25 03:56:58 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 15:14:01 +02:00
|
|
|
static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-10-28 07:44:24 +01:00
|
|
|
AVFilter ff_asrc_anullsrc = {
|
2013-09-07 14:13:50 +02:00
|
|
|
.name = "anullsrc",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
|
|
|
|
.init = init,
|
2013-03-22 01:35:13 +01:00
|
|
|
.query_formats = query_formats,
|
2013-09-07 14:13:50 +02:00
|
|
|
.priv_size = sizeof(ANullContext),
|
|
|
|
.inputs = NULL,
|
|
|
|
.outputs = avfilter_asrc_anullsrc_outputs,
|
|
|
|
.priv_class = &anullsrc_class,
|
2010-09-25 03:56:58 +02:00
|
|
|
};
|