2011-07-14 11:18:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Mina Nagy Zaki
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* format audio filter
|
|
|
|
*/
|
|
|
|
|
2011-08-16 00:02:44 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-10 15:00:00 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-08-06 13:49:32 +00:00
|
|
|
#include "libavutil/common.h"
|
2024-08-29 08:29:47 +00:00
|
|
|
#include "libavutil/mem.h"
|
2012-05-06 07:00:53 +00:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
|
2012-05-12 15:58:14 +00:00
|
|
|
#include "audio.h"
|
2012-05-06 07:00:53 +00:00
|
|
|
#include "avfilter.h"
|
2024-08-12 13:29:00 +00:00
|
|
|
#include "filters.h"
|
2012-05-06 07:00:53 +00:00
|
|
|
#include "formats.h"
|
2011-07-14 11:18:13 +00:00
|
|
|
|
2012-05-06 07:00:53 +00:00
|
|
|
typedef struct AFormatContext {
|
|
|
|
const AVClass *class;
|
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
enum AVSampleFormat *formats;
|
|
|
|
unsigned nb_formats;
|
2012-05-06 07:00:53 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
int *sample_rates;
|
|
|
|
unsigned nb_sample_rates;
|
|
|
|
|
|
|
|
AVChannelLayout *channel_layouts;
|
|
|
|
unsigned nb_channel_layouts;
|
2011-07-14 11:18:13 +00:00
|
|
|
} AFormatContext;
|
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
static const AVOptionArrayDef array_def = { .sep = '|' };
|
|
|
|
|
2012-05-06 07:00:53 +00:00
|
|
|
#define OFFSET(x) offsetof(AFormatContext, x)
|
|
|
|
#define A AV_OPT_FLAG_AUDIO_PARAM
|
2012-08-13 11:40:01 +00:00
|
|
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
2012-06-22 12:33:09 +00:00
|
|
|
static const AVOption aformat_options[] = {
|
2024-08-29 08:29:47 +00:00
|
|
|
{ "sample_fmts", "A '|'-separated list of sample formats.", OFFSET(formats),
|
|
|
|
AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
|
|
|
|
{ "f", "A '|'-separated list of sample formats.", OFFSET(formats),
|
|
|
|
AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
|
|
|
|
{ "sample_rates", "A '|'-separated list of sample rates.", OFFSET(sample_rates),
|
|
|
|
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .min = 1, .max = INT_MAX, .flags = A|F },
|
|
|
|
{ "r", "A '|'-separated list of sample rates.", OFFSET(sample_rates),
|
|
|
|
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .min = 1, .max = INT_MAX, .flags = A|F },
|
|
|
|
{ "channel_layouts", "A '|'-separated list of channel layouts.", OFFSET(channel_layouts),
|
|
|
|
AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
|
|
|
|
{ "cl", "A '|'-separated list of channel layouts.", OFFSET(channel_layouts),
|
|
|
|
AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
|
2013-09-07 12:13:50 +00:00
|
|
|
{ NULL }
|
2012-05-06 07:00:53 +00:00
|
|
|
};
|
|
|
|
|
2012-06-22 12:33:09 +00:00
|
|
|
AVFILTER_DEFINE_CLASS(aformat);
|
2012-05-06 07:00:53 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2021-08-31 14:03:14 +00:00
|
|
|
{
|
|
|
|
AFormatContext *s = ctx->priv;
|
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
// terminate format lists for ff_set*_from_list()
|
|
|
|
if (s->nb_formats) {
|
|
|
|
void *tmp = av_realloc_array(s->formats, s->nb_formats + 1,
|
|
|
|
sizeof(*s->formats));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
s->formats = tmp;
|
|
|
|
s->formats[s->nb_formats] = AV_SAMPLE_FMT_NONE;
|
2021-08-31 14:03:14 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
}
|
|
|
|
if (s->nb_sample_rates) {
|
|
|
|
void *tmp = av_realloc_array(s->sample_rates, s->nb_sample_rates + 1,
|
|
|
|
sizeof(*s->sample_rates));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
s->sample_rates = tmp;
|
|
|
|
s->sample_rates[s->nb_sample_rates] = -1;
|
|
|
|
}
|
|
|
|
if (s->nb_channel_layouts) {
|
|
|
|
void *tmp = av_realloc_array(s->channel_layouts, s->nb_channel_layouts + 1,
|
|
|
|
sizeof(*s->channel_layouts));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
s->channel_layouts = tmp;
|
|
|
|
s->channel_layouts[s->nb_channel_layouts] = (AVChannelLayout){ .nb_channels = 0 };
|
2021-08-31 14:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-08-29 07:10:01 +00:00
|
|
|
static int query_formats(const AVFilterContext *ctx,
|
|
|
|
AVFilterFormatsConfig **cfg_in,
|
|
|
|
AVFilterFormatsConfig **cfg_out)
|
2011-07-14 11:18:13 +00:00
|
|
|
{
|
2024-08-29 07:10:01 +00:00
|
|
|
const AFormatContext *s = ctx->priv;
|
2021-08-31 14:03:14 +00:00
|
|
|
int ret;
|
2011-07-14 11:18:13 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
if (s->nb_formats) {
|
2024-08-29 07:10:01 +00:00
|
|
|
ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, s->formats);
|
2024-08-29 08:29:47 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2020-08-09 14:42:37 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
if (s->nb_sample_rates) {
|
2024-08-29 07:10:01 +00:00
|
|
|
ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, s->sample_rates);
|
2024-08-29 08:29:47 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2020-08-09 14:42:37 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
if (s->nb_channel_layouts) {
|
2024-08-29 07:10:01 +00:00
|
|
|
ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, s->channel_layouts);
|
2024-08-29 08:29:47 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2011-07-14 11:18:13 +00:00
|
|
|
|
2024-08-29 08:29:47 +00:00
|
|
|
return 0;
|
2011-07-14 11:18:13 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 16:33:56 +00:00
|
|
|
const AVFilter ff_af_aformat = {
|
2011-07-14 11:18:13 +00:00
|
|
|
.name = "aformat",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
|
|
|
|
.init = init,
|
|
|
|
.priv_size = sizeof(AFormatContext),
|
2013-02-25 20:21:29 +00:00
|
|
|
.priv_class = &aformat_class,
|
2021-11-22 13:39:11 +00:00
|
|
|
.flags = AVFILTER_FLAG_METADATA_ONLY,
|
2023-08-02 22:59:02 +00:00
|
|
|
FILTER_INPUTS(ff_audio_default_filterpad),
|
|
|
|
FILTER_OUTPUTS(ff_audio_default_filterpad),
|
2024-08-29 07:10:01 +00:00
|
|
|
FILTER_QUERY_FUNC2(query_formats),
|
2011-07-14 11:18:13 +00:00
|
|
|
};
|