2010-09-25 01:56:58 +00:00
|
|
|
/*
|
2012-05-22 19:01:07 +00:00
|
|
|
* Copyright 2010 S.N. Hemanth Meenakshisundaram <smeenaks ucsd edu>
|
|
|
|
* Copyright 2010 Stefano Sabatini <stefano.sabatini-lala poste it>
|
|
|
|
*
|
2010-09-25 01:56:58 +00: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 13:49:32 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2011-09-17 10:31:21 +00:00
|
|
|
|
2012-05-12 15:58:14 +00:00
|
|
|
#include "audio.h"
|
2011-09-17 10:31:21 +00:00
|
|
|
#include "avfilter.h"
|
|
|
|
#include "internal.h"
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2011-02-07 13:37:08 +00:00
|
|
|
#include "libavutil/audioconvert.h"
|
2012-08-06 13:49:32 +00:00
|
|
|
#include "libavutil/internal.h"
|
2012-08-16 14:12:45 +00:00
|
|
|
#include "libavutil/opt.h"
|
2010-09-25 01:56:58 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-09-17 10:31:21 +00:00
|
|
|
const AVClass *class;
|
|
|
|
char *channel_layout_str;
|
2011-11-25 12:51:57 +00:00
|
|
|
uint64_t channel_layout;
|
2011-09-17 10:31:21 +00:00
|
|
|
char *sample_rate_str;
|
|
|
|
int sample_rate;
|
2011-09-17 01:17:06 +00:00
|
|
|
int nb_samples; ///< number of samples per requested frame
|
|
|
|
int64_t pts;
|
2010-09-25 01:56:58 +00:00
|
|
|
} ANullContext;
|
|
|
|
|
2011-09-17 10:31:21 +00:00
|
|
|
#define OFFSET(x) offsetof(ANullContext, x)
|
2012-08-13 11:40:01 +00:00
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
2011-09-17 10:31:21 +00:00
|
|
|
|
|
|
|
static const AVOption anullsrc_options[]= {
|
2012-08-13 11:40:01 +00: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 12:26:01 +00: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 10:31:21 +00:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2012-06-22 12:33:09 +00:00
|
|
|
AVFILTER_DEFINE_CLASS(anullsrc);
|
2011-09-17 10:31:21 +00:00
|
|
|
|
2012-06-21 05:55:56 +00:00
|
|
|
static int init(AVFilterContext *ctx, const char *args)
|
2010-09-25 01:56:58 +00:00
|
|
|
{
|
2011-09-17 10:52:54 +00:00
|
|
|
ANullContext *null = ctx->priv;
|
2011-09-17 10:31:21 +00:00
|
|
|
int ret;
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2011-09-17 10:52:54 +00:00
|
|
|
null->class = &anullsrc_class;
|
|
|
|
av_opt_set_defaults(null);
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2012-08-08 22:49:27 +00:00
|
|
|
if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0)
|
2011-09-17 10:31:21 +00:00
|
|
|
return ret;
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2011-09-17 10:52:54 +00:00
|
|
|
if ((ret = ff_parse_sample_rate(&null->sample_rate,
|
|
|
|
null->sample_rate_str, ctx)) < 0)
|
2011-09-17 10:31:21 +00:00
|
|
|
return ret;
|
|
|
|
|
2011-09-17 10:52:54 +00:00
|
|
|
if ((ret = ff_parse_channel_layout(&null->channel_layout,
|
|
|
|
null->channel_layout_str, ctx)) < 0)
|
2011-09-17 10:31:21 +00:00
|
|
|
return ret;
|
2010-09-25 01:56:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config_props(AVFilterLink *outlink)
|
|
|
|
{
|
2011-09-17 10:52:54 +00:00
|
|
|
ANullContext *null = outlink->src->priv;
|
2010-09-25 01:56:58 +00:00
|
|
|
char buf[128];
|
|
|
|
int chans_nb;
|
|
|
|
|
2011-09-17 10:52:54 +00:00
|
|
|
outlink->sample_rate = null->sample_rate;
|
|
|
|
outlink->channel_layout = null->channel_layout;
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2011-09-17 10:52:54 +00: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);
|
2012-06-25 04:31:38 +00:00
|
|
|
av_log(outlink->src, AV_LOG_VERBOSE,
|
2011-09-17 10:50:24 +00:00
|
|
|
"sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
|
2011-09-17 10:52:54 +00:00
|
|
|
null->sample_rate, buf, null->nb_samples);
|
2010-09-25 01:56:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-17 01:17:06 +00:00
|
|
|
static int request_frame(AVFilterLink *outlink)
|
2010-09-25 01:56:58 +00:00
|
|
|
{
|
2011-09-17 01:17:06 +00:00
|
|
|
ANullContext *null = outlink->src->priv;
|
|
|
|
AVFilterBufferRef *samplesref;
|
|
|
|
|
|
|
|
samplesref =
|
2012-05-10 20:41:29 +00:00
|
|
|
ff_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
|
2011-09-17 01:17:06 +00:00
|
|
|
samplesref->pts = null->pts;
|
|
|
|
samplesref->pos = -1;
|
|
|
|
samplesref->audio->channel_layout = null->channel_layout;
|
|
|
|
samplesref->audio->sample_rate = outlink->sample_rate;
|
|
|
|
|
2012-05-10 20:41:29 +00:00
|
|
|
ff_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
|
2011-09-17 01:17:06 +00:00
|
|
|
avfilter_unref_buffer(samplesref);
|
|
|
|
|
|
|
|
null->pts += null->nb_samples;
|
|
|
|
return 0;
|
2010-09-25 01:56:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AVFilter avfilter_asrc_anullsrc = {
|
|
|
|
.name = "anullsrc",
|
2011-09-18 12:26:37 +00:00
|
|
|
.description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
|
2010-09-25 01:56:58 +00:00
|
|
|
|
|
|
|
.init = init,
|
|
|
|
.priv_size = sizeof(ANullContext),
|
|
|
|
|
2011-11-05 13:39:24 +00:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = NULL}},
|
2010-09-25 01:56:58 +00:00
|
|
|
|
2011-11-05 13:39:24 +00:00
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
2012-07-21 16:45:52 +00:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame, },
|
|
|
|
{ .name = NULL}},
|
2012-08-13 11:40:01 +00:00
|
|
|
.priv_class = &anullsrc_class,
|
2010-09-25 01:56:58 +00:00
|
|
|
};
|