00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 };