• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavfilter/asrc_anullsrc.c

Go to the documentation of this file.
00001 /*
00002  * This file is part of FFmpeg.
00003  *
00004  * FFmpeg is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * FFmpeg is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with FFmpeg; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00024 #include "libavutil/audioconvert.h"
00025 #include "libavutil/opt.h"
00026 
00027 #include "avfilter.h"
00028 #include "internal.h"
00029 
00030 typedef struct {
00031     const AVClass *class;
00032     char   *channel_layout_str;
00033     uint64_t channel_layout;
00034     char   *sample_rate_str;
00035     int     sample_rate;
00036     int nb_samples;             
00037     int64_t pts;
00038 } ANullContext;
00039 
00040 #define OFFSET(x) offsetof(ANullContext, x)
00041 
00042 static const AVOption anullsrc_options[]= {
00043     { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
00044     { "cl",             "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 },
00045     { "sample_rate",    "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
00046     { "r",              "set sample rate",    OFFSET(sample_rate_str)   , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 },
00047     { "nb_samples",     "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
00048     { "n",              "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX },
00049     { NULL },
00050 };
00051 
00052 static const char *anullsrc_get_name(void *ctx)
00053 {
00054     return "anullsrc";
00055 }
00056 
00057 static const AVClass anullsrc_class = {
00058     "ANullSrcContext",
00059     anullsrc_get_name,
00060     anullsrc_options
00061 };
00062 
00063 static int init(AVFilterContext *ctx, const char *args, void *opaque)
00064 {
00065     ANullContext *null = ctx->priv;
00066     int ret;
00067 
00068     null->class = &anullsrc_class;
00069     av_opt_set_defaults(null);
00070 
00071     if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0) {
00072         av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args);
00073         return ret;
00074     }
00075 
00076     if ((ret = ff_parse_sample_rate(&null->sample_rate,
00077                                      null->sample_rate_str, ctx)) < 0)
00078         return ret;
00079 
00080     if ((ret = ff_parse_channel_layout(&null->channel_layout,
00081                                         null->channel_layout_str, ctx)) < 0)
00082         return ret;
00083 
00084     return 0;
00085 }
00086 
00087 static int config_props(AVFilterLink *outlink)
00088 {
00089     ANullContext *null = outlink->src->priv;
00090     char buf[128];
00091     int chans_nb;
00092 
00093     outlink->sample_rate = null->sample_rate;
00094     outlink->channel_layout = null->channel_layout;
00095 
00096     chans_nb = av_get_channel_layout_nb_channels(null->channel_layout);
00097     av_get_channel_layout_string(buf, sizeof(buf), chans_nb, null->channel_layout);
00098     av_log(outlink->src, AV_LOG_INFO,
00099            "sample_rate:%d channel_layout:'%s' nb_samples:%d\n",
00100            null->sample_rate, buf, null->nb_samples);
00101 
00102     return 0;
00103 }
00104 
00105 static int request_frame(AVFilterLink *outlink)
00106 {
00107     ANullContext *null = outlink->src->priv;
00108     AVFilterBufferRef *samplesref;
00109 
00110     samplesref =
00111         avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples);
00112     samplesref->pts = null->pts;
00113     samplesref->pos = -1;
00114     samplesref->audio->channel_layout = null->channel_layout;
00115     samplesref->audio->sample_rate = outlink->sample_rate;
00116 
00117     avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0));
00118     avfilter_unref_buffer(samplesref);
00119 
00120     null->pts += null->nb_samples;
00121     return 0;
00122 }
00123 
00124 AVFilter avfilter_asrc_anullsrc = {
00125     .name        = "anullsrc",
00126     .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
00127 
00128     .init        = init,
00129     .priv_size   = sizeof(ANullContext),
00130 
00131     .inputs      = (const AVFilterPad[]) {{ .name = NULL}},
00132 
00133     .outputs     = (const AVFilterPad[]) {{ .name = "default",
00134                                       .type = AVMEDIA_TYPE_AUDIO,
00135                                       .config_props = config_props,
00136                                       .request_frame = request_frame, },
00137                                     { .name = NULL}},
00138 };
Generated on Fri Feb 1 2013 14:34:48 for FFmpeg by doxygen 1.7.1