FFmpeg
Loading...
Searching...
No Matches
asrc_anullsrc.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 S.N. Hemanth Meenakshisundaram <smeenaks ucsd edu>
3 * Copyright 2010 Stefano Sabatini <stefano.sabatini-lala poste it>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * null audio source
25 */
26
27#include <inttypes.h>
28#include <stdio.h>
29
31#include "libavutil/internal.h"
32#include "libavutil/opt.h"
33#include "audio.h"
34#include "avfilter.h"
35#include "filters.h"
36#include "formats.h"
37
38typedef struct ANullContext {
39 const AVClass *class;
43 int nb_samples; ///< number of samples per requested frame
46
47#define OFFSET(x) offsetof(ANullContext, x)
48#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
49
50static const AVOption anullsrc_options[]= {
51 { "channel_layout", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
52 { "cl", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
53 { "sample_rate", "set sample rate", OFFSET(sample_rate) , AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT_MAX, FLAGS },
54 { "r", "set sample rate", OFFSET(sample_rate) , AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT_MAX, FLAGS },
55 { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
56 { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
57 { "duration", "set the audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
58 { "d", "set the audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
59 { NULL }
60};
61
63
65 AVFilterFormatsConfig **cfg_in,
66 AVFilterFormatsConfig **cfg_out)
67{
68 const ANullContext *null = ctx->priv;
69 const AVChannelLayout chlayouts[] = { null->ch_layout, { 0 } };
70 int sample_rates[] = { null->sample_rate, -1 };
71 int ret;
72
74 if (ret < 0)
75 return ret;
76
77 return ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, chlayouts);
78}
79
80static av_cold int config_props(AVFilterLink *outlink)
81{
82 ANullContext *null = outlink->src->priv;
83
84 if (null->duration >= 0)
86
87 return 0;
88}
89
91{
92 ANullContext *null = ctx->priv;
93 AVFilterLink *outlink = ctx->outputs[0];
94
95 if (null->duration >= 0 && null->pts >= null->duration) {
96 ff_outlink_set_status(outlink, AVERROR_EOF, null->pts);
97 return 0;
98 }
99
100 if (ff_outlink_frame_wanted(outlink)) {
101 AVFrame *samplesref = ff_get_audio_buffer(outlink, null->duration >= 0 ? FFMIN(null->nb_samples, null->duration - null->pts) : null->nb_samples);
102
103 if (!samplesref)
104 return AVERROR(ENOMEM);
105
106 samplesref->pts = null->pts;
107 null->pts += samplesref->nb_samples;
108
109 return ff_filter_frame(outlink, samplesref);
110 }
111
112 return FFERROR_NOT_READY;
113}
114
116 {
117 .name = "default",
118 .type = AVMEDIA_TYPE_AUDIO,
119 .config_props = config_props,
120 },
121};
122
124 .p.name = "anullsrc",
125 .p.description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
126 .p.priv_class = &anullsrc_class,
127 .priv_size = sizeof(ANullContext),
130 .activate = activate,
131};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
const FFFilter ff_asrc_anullsrc
static const AVOption anullsrc_options[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
static const AVFilterPad avfilter_asrc_anullsrc_outputs[]
#define OFFSET(x)
static av_cold int config_props(AVFilterLink *outlink)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition audio.c:74
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition avfilter.c:1690
Main libavfilter public API header.
Public libavutil channel layout APIs header.
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const int sample_rates[]
Definition dcaenc.h:34
static int64_t duration
Definition ffplay.c:330
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition formats.c:1050
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition formats.c:1026
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition opt.h:318
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
Definition opt.h:330
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define AV_TIME_BASE
Internal time base represented as integer.
Definition avutil.h:253
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_OUTPUTS(array)
Definition filters.h:265
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition filters.h:629
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
Definition filters.h:34
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define av_cold
Definition attributes.h:117
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMIN(a, b)
Definition macros.h:49
AVOptions.
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
int64_t duration
int nb_samples
number of samples per requested frame
AVChannelLayout ch_layout
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
void * priv
private data for use by the filter
Definition avfilter.h:288
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int nb_samples
number of audio samples (per channel) described by this frame
Definition frame.h:552
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
AVOption.
Definition opt.h:428
static AVFormatContext * ctx
Definition movenc.c:49