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-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
|
|
|
|
2011-02-07 14:37:08 +01:00
|
|
|
#include "libavutil/audioconvert.h"
|
2012-08-06 15:49:32 +02:00
|
|
|
#include "libavutil/internal.h"
|
2012-08-16 16:12:45 +02:00
|
|
|
#include "libavutil/opt.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 },
|
|
|
|
{ "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX, FLAGS },
|
|
|
|
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX, FLAGS },
|
2011-09-17 12:31:21 +02:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2012-06-22 14:33:09 +02:00
|
|
|
AVFILTER_DEFINE_CLASS(anullsrc);
|
2011-09-17 12:31:21 +02:00
|
|
|
|
2012-06-21 07:55:56 +02:00
|
|
|
static int init(AVFilterContext *ctx, const char *args)
|
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
|
|
|
null->class = &anullsrc_class;
|
|
|
|
av_opt_set_defaults(null);
|
2010-09-25 03:56:58 +02:00
|
|
|
|
2012-08-09 00:49:27 +02:00
|
|
|
if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0)
|
2011-09-17 12:31:21 +02:00
|
|
|
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);
|
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
|
|
|
{
|
2011-09-17 03:17:06 +02:00
|
|
|
ANullContext *null = outlink->src->priv;
|
|
|
|
AVFilterBufferRef *samplesref;
|
|
|
|
|
|
|
|
samplesref =
|
2012-05-10 22:41:29 +02:00
|
|
|
ff_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
|
2011-09-17 03:17:06 +02: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 22:41:29 +02:00
|
|
|
ff_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
|
2011-09-17 03:17:06 +02:00
|
|
|
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),
|
|
|
|
|
2011-11-05 14:39:24 +01:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = NULL}},
|
2010-09-25 03:56:58 +02:00
|
|
|
|
2011-11-05 14:39:24 +01:00
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
2012-07-21 18:45:52 +02:00
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_props,
|
|
|
|
.request_frame = request_frame, },
|
|
|
|
{ .name = NULL}},
|
2012-08-13 13:40:01 +02:00
|
|
|
.priv_class = &anullsrc_class,
|
2010-09-25 03:56:58 +02:00
|
|
|
};
|