2 * Copyright (c) 2011 Mina Nagy Zaki
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "libavutil/audioconvert.h"
27 #include "libavutil/avstring.h"
32 AVFilterFormats *formats, *chlayouts, *packing;
35 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
37 AFormatContext * const aformat = ctx->priv;
38 char *fmts_str = NULL, *fmt_str, *ptr = NULL;
45 #define ADD_FORMATS(all_formats, fmt_name, fmt_type, fmts_list) do { \
46 fmts_str = av_get_token(&args, ":"); \
47 if (!fmts_str || !*fmts_str) \
49 if (!strcmp(fmts_str, "all")) { \
50 aformat->fmts_list = all_formats; \
52 for (fmt_str = fmts_str; \
53 fmt_str = av_strtok(fmt_str, ",", &ptr); fmt_str = NULL) { \
54 if ((ret = ff_parse_##fmt_name((fmt_type *)&fmt, \
55 fmt_str, ctx)) < 0) { \
56 av_freep(&fmts_str); \
59 avfilter_add_format(&aformat->fmts_list, fmt); \
62 av_freep(&fmts_str); \
67 ADD_FORMATS(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), sample_format, int, formats);
68 ADD_FORMATS(avfilter_make_all_channel_layouts(), channel_layout, int64_t, chlayouts);
69 ADD_FORMATS(avfilter_make_all_packing_formats(), packing_format, int, packing);
74 av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form "
75 "sample_fmts:channel_layouts:packing_fmts\n");
77 return AVERROR(EINVAL);
80 static int query_formats(AVFilterContext *ctx)
82 AFormatContext * const aformat = ctx->priv;
84 avfilter_set_common_sample_formats (ctx, aformat->formats);
85 avfilter_set_common_channel_layouts(ctx, aformat->chlayouts);
86 avfilter_set_common_packing_formats(ctx, aformat->packing);
90 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
92 ff_filter_samples(inlink->dst->outputs[0], insamplesref);
95 AVFilter avfilter_af_aformat = {
97 .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
99 .query_formats = query_formats,
100 .priv_size = sizeof(AFormatContext),
102 .inputs = (const AVFilterPad[]) {{ .name = "default",
103 .type = AVMEDIA_TYPE_AUDIO,
104 .filter_samples = filter_samples},
106 .outputs = (const AVFilterPad[]) {{ .name = "default",
107 .type = AVMEDIA_TYPE_AUDIO},