FFmpeg
Loading...
Searching...
No Matches
af_aformat.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Mina Nagy Zaki
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21/**
22 * @file
23 * format audio filter
24 */
25
26#include "libavutil/avstring.h"
28#include "libavutil/common.h"
29#include "libavutil/mem.h"
30#include "libavutil/opt.h"
31
32#include "audio.h"
33#include "avfilter.h"
34#include "filters.h"
35#include "formats.h"
36
49
50static const AVOptionArrayDef array_def = { .sep = '|' };
51
52#define OFFSET(x) offsetof(AFormatContext, x)
53#define A AV_OPT_FLAG_AUDIO_PARAM
54#define F AV_OPT_FLAG_FILTERING_PARAM
55static const AVOption aformat_options[] = {
56 { "sample_fmts", "A '|'-separated list of sample formats.", OFFSET(formats),
57 AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
58 { "f", "A '|'-separated list of sample formats.", OFFSET(formats),
59 AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
60 { "sample_rates", "A '|'-separated list of sample rates.", OFFSET(sample_rates),
61 AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .min = 1, .max = INT_MAX, .flags = A|F },
62 { "r", "A '|'-separated list of sample rates.", OFFSET(sample_rates),
63 AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .min = 1, .max = INT_MAX, .flags = A|F },
64 { "channel_layouts", "A '|'-separated list of channel layouts.", OFFSET(channel_layouts),
65 AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
66 { "cl", "A '|'-separated list of channel layouts.", OFFSET(channel_layouts),
67 AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .default_val.arr = &array_def, .flags = A|F },
68 { NULL }
69};
70
72
74{
75 AFormatContext *s = ctx->priv;
76
77 // terminate format lists for ff_set*_from_list()
78 if (s->nb_formats) {
79 void *tmp = av_realloc_array(s->formats, s->nb_formats + 1,
80 sizeof(*s->formats));
81 if (!tmp)
82 return AVERROR(ENOMEM);
83 s->formats = tmp;
84 s->formats[s->nb_formats] = AV_SAMPLE_FMT_NONE;
85
86 }
87 if (s->nb_sample_rates) {
88 void *tmp = av_realloc_array(s->sample_rates, s->nb_sample_rates + 1,
89 sizeof(*s->sample_rates));
90 if (!tmp)
91 return AVERROR(ENOMEM);
92 s->sample_rates = tmp;
93 s->sample_rates[s->nb_sample_rates] = -1;
94 }
95 if (s->nb_channel_layouts) {
96 void *tmp = av_realloc_array(s->channel_layouts, s->nb_channel_layouts + 1,
97 sizeof(*s->channel_layouts));
98 if (!tmp)
99 return AVERROR(ENOMEM);
100 s->channel_layouts = tmp;
101 s->channel_layouts[s->nb_channel_layouts] = (AVChannelLayout){ .nb_channels = 0 };
102 }
103
104 return 0;
105}
106
108 AVFilterFormatsConfig **cfg_in,
109 AVFilterFormatsConfig **cfg_out)
110{
111 const AFormatContext *s = ctx->priv;
112 int ret;
113
114 if (s->nb_formats) {
115 ret = ff_set_sample_formats_from_list2(ctx, cfg_in, cfg_out, s->formats);
116 if (ret < 0)
117 return ret;
118 }
119
120 if (s->nb_sample_rates) {
121 ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, s->sample_rates);
122 if (ret < 0)
123 return ret;
124 }
125
126 if (s->nb_channel_layouts) {
127 ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, s->channel_layouts);
128 if (ret < 0)
129 return ret;
130 }
131
132 return 0;
133}
134
136 .p.name = "aformat",
137 .p.description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
138 .p.priv_class = &aformat_class,
140 .init = init,
141 .priv_size = sizeof(AFormatContext),
145};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static const AVOptionArrayDef array_def
Definition af_aformat.c:50
static const AVOption aformat_options[]
Definition af_aformat.c:55
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition af_aformat.c:107
#define OFFSET(x)
Definition af_aformat.c:52
const FFFilter ff_af_aformat
Definition af_aformat.c:135
static AVFormatContext * ctx
#define A(x)
Definition vpx_arith.h:28
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition audio.c:34
Main libavfilter public API header.
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
common internal and external API header
#define NULL
Definition coverity.c:32
static const uint16_t channel_layouts[7]
Definition dca_lbr.c:112
static const int sample_rates[]
Definition dcaenc.h:34
#define F(x)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition formats.c:1050
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition formats.c:1026
int ff_set_sample_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVSampleFormat *fmts)
Definition formats.c:1154
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition opt.h:345
@ AV_OPT_TYPE_SAMPLE_FMT
Underlying C type is enum AVSampleFormat.
Definition opt.h:310
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
Definition opt.h:330
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
#define AVERROR(e)
Definition error.h:45
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:217
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
Memory handling functions.
AVOptions.
formats
Definition signature.h:47
unsigned nb_formats
Definition af_aformat.c:41
AVChannelLayout * channel_layouts
Definition af_aformat.c:46
enum AVSampleFormat * formats
Definition af_aformat.c:40
unsigned nb_sample_rates
Definition af_aformat.c:44
unsigned nb_channel_layouts
Definition af_aformat.c:47
int * sample_rates
Definition af_aformat.c:43
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
Definition opt.h:394
AVOption.
Definition opt.h:428
static uint8_t tmp[40]
Definition aes_ctr.c:52