yading@10
|
1 /*
|
yading@10
|
2 * Copyright 2010 S.N. Hemanth Meenakshisundaram <smeenaks ucsd edu>
|
yading@10
|
3 * Copyright 2010 Stefano Sabatini <stefano.sabatini-lala poste it>
|
yading@10
|
4 *
|
yading@10
|
5 * This file is part of FFmpeg.
|
yading@10
|
6 *
|
yading@10
|
7 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
8 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
9 * License as published by the Free Software Foundation; either
|
yading@10
|
10 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
11 *
|
yading@10
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
15 * Lesser General Public License for more details.
|
yading@10
|
16 *
|
yading@10
|
17 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
18 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
20 */
|
yading@10
|
21
|
yading@10
|
22 /**
|
yading@10
|
23 * @file
|
yading@10
|
24 * null audio source
|
yading@10
|
25 */
|
yading@10
|
26
|
yading@10
|
27 #include <inttypes.h>
|
yading@10
|
28 #include <stdio.h>
|
yading@10
|
29
|
yading@10
|
30 #include "libavutil/channel_layout.h"
|
yading@10
|
31 #include "libavutil/internal.h"
|
yading@10
|
32 #include "libavutil/opt.h"
|
yading@10
|
33 #include "audio.h"
|
yading@10
|
34 #include "avfilter.h"
|
yading@10
|
35 #include "internal.h"
|
yading@10
|
36
|
yading@10
|
37 typedef struct {
|
yading@10
|
38 const AVClass *class;
|
yading@10
|
39 char *channel_layout_str;
|
yading@10
|
40 uint64_t channel_layout;
|
yading@10
|
41 char *sample_rate_str;
|
yading@10
|
42 int sample_rate;
|
yading@10
|
43 int nb_samples; ///< number of samples per requested frame
|
yading@10
|
44 int64_t pts;
|
yading@10
|
45 } ANullContext;
|
yading@10
|
46
|
yading@10
|
47 #define OFFSET(x) offsetof(ANullContext, x)
|
yading@10
|
48 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
yading@10
|
49
|
yading@10
|
50 static const AVOption anullsrc_options[]= {
|
yading@10
|
51 { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
|
yading@10
|
52 { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
|
yading@10
|
53 { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
|
yading@10
|
54 { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
|
yading@10
|
55 { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
|
yading@10
|
56 { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX, FLAGS },
|
yading@10
|
57 { NULL },
|
yading@10
|
58 };
|
yading@10
|
59
|
yading@10
|
60 AVFILTER_DEFINE_CLASS(anullsrc);
|
yading@10
|
61
|
yading@10
|
62 static int init(AVFilterContext *ctx)
|
yading@10
|
63 {
|
yading@10
|
64 ANullContext *null = ctx->priv;
|
yading@10
|
65 int ret;
|
yading@10
|
66
|
yading@10
|
67 if ((ret = ff_parse_sample_rate(&null->sample_rate,
|
yading@10
|
68 null->sample_rate_str, ctx)) < 0)
|
yading@10
|
69 return ret;
|
yading@10
|
70
|
yading@10
|
71 if ((ret = ff_parse_channel_layout(&null->channel_layout,
|
yading@10
|
72 null->channel_layout_str, ctx)) < 0)
|
yading@10
|
73 return ret;
|
yading@10
|
74
|
yading@10
|
75 return 0;
|
yading@10
|
76 }
|
yading@10
|
77
|
yading@10
|
78 static int query_formats(AVFilterContext *ctx)
|
yading@10
|
79 {
|
yading@10
|
80 ANullContext *null = ctx->priv;
|
yading@10
|
81 int64_t chlayouts[] = { null->channel_layout, -1 };
|
yading@10
|
82 int sample_rates[] = { null->sample_rate, -1 };
|
yading@10
|
83
|
yading@10
|
84 ff_set_common_formats (ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
|
yading@10
|
85 ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
|
yading@10
|
86 ff_set_common_samplerates (ctx, ff_make_format_list(sample_rates));
|
yading@10
|
87
|
yading@10
|
88 return 0;
|
yading@10
|
89 }
|
yading@10
|
90
|
yading@10
|
91 static int config_props(AVFilterLink *outlink)
|
yading@10
|
92 {
|
yading@10
|
93 ANullContext *null = outlink->src->priv;
|
yading@10
|
94 char buf[128];
|
yading@10
|
95
|
yading@10
|
96 av_get_channel_layout_string(buf, sizeof(buf), 0, null->channel_layout);
|
yading@10
|
97 av_log(outlink->src, AV_LOG_VERBOSE,
|
yading@10
|
98 "sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
|
yading@10
|
99 null->sample_rate, buf, null->nb_samples);
|
yading@10
|
100
|
yading@10
|
101 return 0;
|
yading@10
|
102 }
|
yading@10
|
103
|
yading@10
|
104 static int request_frame(AVFilterLink *outlink)
|
yading@10
|
105 {
|
yading@10
|
106 int ret;
|
yading@10
|
107 ANullContext *null = outlink->src->priv;
|
yading@10
|
108 AVFrame *samplesref;
|
yading@10
|
109
|
yading@10
|
110 samplesref = ff_get_audio_buffer(outlink, null->nb_samples);
|
yading@10
|
111 if (!samplesref)
|
yading@10
|
112 return AVERROR(ENOMEM);
|
yading@10
|
113
|
yading@10
|
114 samplesref->pts = null->pts;
|
yading@10
|
115 samplesref->channel_layout = null->channel_layout;
|
yading@10
|
116 samplesref->sample_rate = outlink->sample_rate;
|
yading@10
|
117
|
yading@10
|
118 ret = ff_filter_frame(outlink, av_frame_clone(samplesref));
|
yading@10
|
119 av_frame_free(&samplesref);
|
yading@10
|
120 if (ret < 0)
|
yading@10
|
121 return ret;
|
yading@10
|
122
|
yading@10
|
123 null->pts += null->nb_samples;
|
yading@10
|
124 return ret;
|
yading@10
|
125 }
|
yading@10
|
126
|
yading@10
|
127 static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
|
yading@10
|
128 {
|
yading@10
|
129 .name = "default",
|
yading@10
|
130 .type = AVMEDIA_TYPE_AUDIO,
|
yading@10
|
131 .config_props = config_props,
|
yading@10
|
132 .request_frame = request_frame,
|
yading@10
|
133 },
|
yading@10
|
134 { NULL }
|
yading@10
|
135 };
|
yading@10
|
136
|
yading@10
|
137 AVFilter avfilter_asrc_anullsrc = {
|
yading@10
|
138 .name = "anullsrc",
|
yading@10
|
139 .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
|
yading@10
|
140
|
yading@10
|
141 .init = init,
|
yading@10
|
142 .query_formats = query_formats,
|
yading@10
|
143 .priv_size = sizeof(ANullContext),
|
yading@10
|
144
|
yading@10
|
145 .inputs = NULL,
|
yading@10
|
146
|
yading@10
|
147 .outputs = avfilter_asrc_anullsrc_outputs,
|
yading@10
|
148 .priv_class = &anullsrc_class,
|
yading@10
|
149 };
|