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

libavfilter/af_aformat.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Mina Nagy Zaki
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "libavutil/audioconvert.h"
00027 #include "libavutil/avstring.h"
00028 #include "avfilter.h"
00029 #include "internal.h"
00030 
00031 typedef struct {
00032     AVFilterFormats *formats, *chlayouts, *packing;
00033 } AFormatContext;
00034 
00035 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00036 {
00037     AFormatContext * const aformat = ctx->priv;
00038     char *fmts_str = NULL, *fmt_str, *ptr = NULL;
00039     int64_t fmt;
00040     int ret;
00041 
00042     if (!args)
00043         goto arg_fail;
00044 
00045 #define ADD_FORMATS(all_formats, fmt_name, fmt_type, fmts_list)         \
00046     fmts_str = av_get_token(&args, ":");                                \
00047     if (!fmts_str || !*fmts_str)                                        \
00048         goto arg_fail;                                                  \
00049     if (!strcmp(fmts_str, "all")) {                                     \
00050         aformat->fmts_list = all_formats;                               \
00051     } else {                                                            \
00052         for (fmt_str = fmts_str;                                        \
00053              fmt_str = av_strtok(fmt_str, ",", &ptr); fmt_str = NULL) { \
00054             if ((ret = ff_parse_##fmt_name((fmt_type *)&fmt,            \
00055                                            fmt_str, ctx)) < 0) {        \
00056                 av_freep(&fmts_str);                                    \
00057                 return ret;                                             \
00058             }                                                           \
00059             avfilter_add_format(&aformat->fmts_list, fmt);              \
00060         }                                                               \
00061     }                                                                   \
00062     av_freep(&fmts_str);                                                \
00063     if (*args)                                                          \
00064         args++;
00065 
00066     ADD_FORMATS(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), sample_format, int, formats);
00067     ADD_FORMATS(avfilter_make_all_channel_layouts(), channel_layout, int64_t, chlayouts);
00068     ADD_FORMATS(avfilter_make_all_packing_formats(), packing_format, int, packing);
00069 
00070     return 0;
00071 
00072 arg_fail:
00073     av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form "
00074                               "sample_fmts:channel_layouts:packing_fmts\n");
00075     av_freep(&fmts_str);
00076     return AVERROR(EINVAL);
00077 }
00078 
00079 static int query_formats(AVFilterContext *ctx)
00080 {
00081     AFormatContext * const aformat = ctx->priv;
00082 
00083     avfilter_set_common_sample_formats (ctx, aformat->formats);
00084     avfilter_set_common_channel_layouts(ctx, aformat->chlayouts);
00085     avfilter_set_common_packing_formats(ctx, aformat->packing);
00086     return 0;
00087 }
00088 
00089 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
00090 {
00091     avfilter_filter_samples(inlink->dst->outputs[0], insamplesref);
00092 }
00093 
00094 AVFilter avfilter_af_aformat = {
00095     .name          = "aformat",
00096     .description   = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
00097     .init          = init,
00098     .query_formats = query_formats,
00099     .priv_size     = sizeof(AFormatContext),
00100 
00101     .inputs        = (const AVFilterPad[]) {{ .name      = "default",
00102                                         .type            = AVMEDIA_TYPE_AUDIO,
00103                                         .filter_samples  = filter_samples},
00104                                       { .name = NULL}},
00105     .outputs       = (const AVFilterPad[]) {{ .name      = "default",
00106                                         .type            = AVMEDIA_TYPE_AUDIO},
00107                                       { .name = NULL}},
00108 };
Generated on Fri Feb 1 2013 14:34:48 for FFmpeg by doxygen 1.7.1