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 fmts_str = av_get_token(&args, ":");
46 if (!fmts_str || !*fmts_str)
48 if (!strcmp(fmts_str, "all")) {
49 aformat->formats = avfilter_all_formats(AVMEDIA_TYPE_AUDIO);
51 for (fmt_str = fmts_str;
52 fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
53 if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0) {
57 avfilter_add_format(&aformat->formats, fmt);
64 fmts_str = av_get_token(&args, ":");
65 if (!fmts_str || !*fmts_str)
67 if (!strcmp(fmts_str, "all")) {
68 aformat->chlayouts = avfilter_all_channel_layouts();
70 for (fmt_str = fmts_str;
71 fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
72 if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0) {
76 avfilter_add_format(&aformat->chlayouts, fmt);
83 fmts_str = av_get_token(&args, ":");
84 if (!fmts_str || !*fmts_str)
86 if (!strcmp(fmts_str, "all")) {
87 aformat->packing = avfilter_all_packing_formats();
89 for (fmt_str = fmts_str;
90 fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
91 if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0) {
95 avfilter_add_format(&aformat->packing, fmt);
103 av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form "
104 "sample_fmts:channel_layouts:packing_fmts\n");
106 return AVERROR(EINVAL);
109 static int query_formats(AVFilterContext *ctx)
111 AFormatContext * const aformat = ctx->priv;
113 avfilter_set_common_sample_formats (ctx, aformat->formats);
114 avfilter_set_common_channel_layouts(ctx, aformat->chlayouts);
115 avfilter_set_common_packing_formats(ctx, aformat->packing);
119 static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
121 avfilter_filter_samples(inlink->dst->outputs[0], insamplesref);
124 AVFilter avfilter_af_aformat = {
126 .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
128 .query_formats = query_formats,
129 .priv_size = sizeof(AFormatContext),
131 .inputs = (AVFilterPad[]) {{ .name = "default",
132 .type = AVMEDIA_TYPE_AUDIO,
133 .filter_samples = filter_samples},
135 .outputs = (AVFilterPad[]) {{ .name = "default",
136 .type = AVMEDIA_TYPE_AUDIO},