FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/opt.h"
30 
31 #include "audio.h"
32 #include "avfilter.h"
33 #include "formats.h"
34 #include "internal.h"
35 
36 typedef struct AFormatContext {
37  const AVClass *class;
38 
42 
43  char *formats_str;
47 
48 #define OFFSET(x) offsetof(AFormatContext, x)
49 #define A AV_OPT_FLAG_AUDIO_PARAM
50 #define F AV_OPT_FLAG_FILTERING_PARAM
51 static const AVOption aformat_options[] = {
52  { "sample_fmts", "A comma-separated list of sample formats.", OFFSET(formats_str), AV_OPT_TYPE_STRING, .flags = A|F },
53  { "sample_rates", "A comma-separated list of sample rates.", OFFSET(sample_rates_str), AV_OPT_TYPE_STRING, .flags = A|F },
54  { "channel_layouts", "A comma-separated list of channel layouts.", OFFSET(channel_layouts_str), AV_OPT_TYPE_STRING, .flags = A|F },
55  { NULL }
56 };
57 
58 AVFILTER_DEFINE_CLASS(aformat);
59 
60 #define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc) \
61 do { \
62  char *next, *cur = str, sep; \
63  \
64  if (str && strchr(str, ',')) { \
65  av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "\
66  "separate %s.\n", desc); \
67  sep = ','; \
68  } else \
69  sep = '|'; \
70  \
71  while (cur) { \
72  type fmt; \
73  next = strchr(cur, sep); \
74  if (next) \
75  *next++ = 0; \
76  \
77  if ((fmt = get_fmt(cur)) == none) { \
78  av_log(ctx, AV_LOG_ERROR, "Error parsing " desc ": %s.\n", cur);\
79  return AVERROR(EINVAL); \
80  } \
81  add_to_list(&list, fmt); \
82  \
83  cur = next; \
84  } \
85 } while (0)
86 
87 static int get_sample_rate(const char *samplerate)
88 {
89  int ret = strtol(samplerate, NULL, 0);
90  return FFMAX(ret, 0);
91 }
92 
93 static av_cold int init(AVFilterContext *ctx)
94 {
95  AFormatContext *s = ctx->priv;
96 
100  get_sample_rate, 0, "sample rate");
103  "channel layout");
104 
105  return 0;
106 }
107 
109 {
110  AFormatContext *s = ctx->priv;
111  int ret;
112 
113  ret = ff_set_common_formats(ctx, s->formats ? s->formats :
115  if (ret < 0)
116  return ret;
119  if (ret < 0)
120  return ret;
123 }
124 
126  {
127  .name = "default",
128  .type = AVMEDIA_TYPE_AUDIO,
129  },
130  { NULL }
131 };
132 
134  {
135  .name = "default",
136  .type = AVMEDIA_TYPE_AUDIO
137  },
138  { NULL }
139 };
140 
142  .name = "aformat",
143  .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."),
144  .init = init,
145  .query_formats = query_formats,
146  .priv_size = sizeof(AFormatContext),
147  .priv_class = &aformat_class,
148  .inputs = avfilter_af_aformat_inputs,
149  .outputs = avfilter_af_aformat_outputs,
150 };
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:523
const char * s
Definition: avisynth_c.h:631
AVOption.
Definition: opt.h:255
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
static const AVFilterPad avfilter_af_aformat_inputs[]
Definition: af_aformat.c:125
static int query_formats(AVFilterContext *ctx)
Definition: af_aformat.c:108
AVFilterFormats * sample_rates
Definition: af_aformat.c:40
const char * name
Pad name.
Definition: internal.h:67
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
#define av_cold
Definition: attributes.h:74
AVOptions.
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:336
#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc)
Definition: af_aformat.c:60
A filter pad used for either input or output.
Definition: internal.h:61
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:542
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:329
#define F
Definition: af_aformat.c:50
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:323
#define FFMAX(a, b)
Definition: common.h:64
static av_cold int init(AVFilterContext *ctx)
Definition: af_aformat.c:93
AVFilterFormats * formats
Definition: af_aformat.c:39
audio channel layout utility functions
ret
Definition: avfilter.c:974
#define A
Definition: af_aformat.c:49
#define OFFSET(x)
Definition: af_aformat.c:48
A list of supported channel layouts.
Definition: formats.h:85
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
AVFILTER_DEFINE_CLASS(aformat)
char * formats_str
Definition: af_aformat.c:43
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:54
const char * name
Filter name.
Definition: avfilter.h:474
char * channel_layouts_str
Definition: af_aformat.c:45
char * sample_rates_str
Definition: af_aformat.c:44
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:379
common internal and external API header
AVFilterChannelLayouts * channel_layouts
Definition: af_aformat.c:41
AVFilter ff_af_aformat
Definition: af_aformat.c:141
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:633
static const AVFilterPad avfilter_af_aformat_outputs[]
Definition: af_aformat.c:133
static const AVOption aformat_options[]
Definition: af_aformat.c:51
static int get_sample_rate(const char *samplerate)
Definition: af_aformat.c:87
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:394
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:530