00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "libavutil/audioconvert.h"
00028 #include "libavutil/opt.h"
00029
00030 #include "audio.h"
00031 #include "avfilter.h"
00032 #include "internal.h"
00033
00034 typedef struct {
00035 const AVClass *class;
00036 char *channel_layout_str;
00037 uint64_t channel_layout;
00038 char *sample_rate_str;
00039 int sample_rate;
00040 int nb_samples;
00041 int64_t pts;
00042 } ANullContext;
00043
00044 #define OFFSET(x) offsetof(ANullContext, x)
00045
00046 static const AVOption anullsrc_options[]= {
00047 { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
00048 { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
00049 { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
00050 { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
00051 { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
00052 { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
00053 { NULL },
00054 };
00055
00056 static const char *anullsrc_get_name(void *ctx)
00057 {
00058 return "anullsrc";
00059 }
00060
00061 static const AVClass anullsrc_class = {
00062 "ANullSrcContext",
00063 anullsrc_get_name,
00064 anullsrc_options
00065 };
00066
00067 static int init(AVFilterContext *ctx, const char *args, void *opaque)
00068 {
00069 ANullContext *null = ctx->priv;
00070 int ret;
00071
00072 null->class = &anullsrc_class;
00073 av_opt_set_defaults(null);
00074
00075 if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0) {
00076 av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
00077 return ret;
00078 }
00079
00080 if ((ret = ff_parse_sample_rate(&null->sample_rate,
00081 null->sample_rate_str, ctx)) < 0)
00082 return ret;
00083
00084 if ((ret = ff_parse_channel_layout(&null->channel_layout,
00085 null->channel_layout_str, ctx)) < 0)
00086 return ret;
00087
00088 return 0;
00089 }
00090
00091 static int config_props(AVFilterLink *outlink)
00092 {
00093 ANullContext *null = outlink->src->priv;
00094 char buf[128];
00095 int chans_nb;
00096
00097 outlink->sample_rate = null->sample_rate;
00098 outlink->channel_layout = null->channel_layout;
00099
00100 chans_nb = av_get_channel_layout_nb_channels(null->channel_layout);
00101 av_get_channel_layout_string(buf, sizeof(buf), chans_nb, null->channel_layout);
00102 av_log(outlink->src, AV_LOG_INFO,
00103 "sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
00104 null->sample_rate, buf, null->nb_samples);
00105
00106 return 0;
00107 }
00108
00109 static int request_frame(AVFilterLink *outlink)
00110 {
00111 ANullContext *null = outlink->src->priv;
00112 AVFilterBufferRef *samplesref;
00113
00114 samplesref =
00115 ff_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
00116 samplesref->pts = null->pts;
00117 samplesref->pos = -1;
00118 samplesref->audio->channel_layout = null->channel_layout;
00119 samplesref->audio->sample_rate = outlink->sample_rate;
00120
00121 ff_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
00122 avfilter_unref_buffer(samplesref);
00123
00124 null->pts += null->nb_samples;
00125 return 0;
00126 }
00127
00128 AVFilter avfilter_asrc_anullsrc = {
00129 .name = "anullsrc",
00130 .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
00131
00132 .init = init,
00133 .priv_size = sizeof(ANullContext),
00134
00135 .inputs = (const AVFilterPad[]) {{ .name = NULL}},
00136
00137 .outputs = (const AVFilterPad[]) {{ .name = "default",
00138 .type = AVMEDIA_TYPE_AUDIO,
00139 .config_props = config_props,
00140 .request_frame = request_frame, },
00141 { .name = NULL}},
00142 };