formats.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVFILTER_FORMATS_H
20 #define AVFILTER_FORMATS_H
21 
22 #include "avfilter.h"
23 
24 /**
25  * A list of supported formats for one end of a filter link. This is used
26  * during the format negotiation process to try to pick the best format to
27  * use to minimize the number of necessary conversions. Each filter gives a
28  * list of the formats supported by each input and output pad. The list
29  * given for each pad need not be distinct - they may be references to the
30  * same list of formats, as is often the case when a filter supports multiple
31  * formats, but will always output the same format as it is given in input.
32  *
33  * In this way, a list of possible input formats and a list of possible
34  * output formats are associated with each link. When a set of formats is
35  * negotiated over a link, the input and output lists are merged to form a
36  * new list containing only the common elements of each list. In the case
37  * that there were no common elements, a format conversion is necessary.
38  * Otherwise, the lists are merged, and all other links which reference
39  * either of the format lists involved in the merge are also affected.
40  *
41  * For example, consider the filter chain:
42  * filter (a) --> (b) filter (b) --> (c) filter
43  *
44  * where the letters in parenthesis indicate a list of formats supported on
45  * the input or output of the link. Suppose the lists are as follows:
46  * (a) = {A, B}
47  * (b) = {A, B, C}
48  * (c) = {B, C}
49  *
50  * First, the first link's lists are merged, yielding:
51  * filter (a) --> (a) filter (a) --> (c) filter
52  *
53  * Notice that format list (b) now refers to the same list as filter list (a).
54  * Next, the lists for the second link are merged, yielding:
55  * filter (a) --> (a) filter (a) --> (a) filter
56  *
57  * where (a) = {B}.
58  *
59  * Unfortunately, when the format lists at the two ends of a link are merged,
60  * we must ensure that all links which reference either pre-merge format list
61  * get updated as well. Therefore, we have the format list structure store a
62  * pointer to each of the pointers to itself.
63  */
65  unsigned format_count; ///< number of formats
66  int *formats; ///< list of media formats
67 
68  unsigned refcount; ///< number of references to this list
69  struct AVFilterFormats ***refs; ///< references to this list
70 };
71 
72 /**
73  * A list of supported channel layouts.
74  *
75  * The list works the same as AVFilterFormats, except for the following
76  * differences:
77  * - A list with all_layouts = 1 means all channel layouts with a known
78  * disposition; nb_channel_layouts must then be 0.
79  * - A list with all_counts = 1 means all channel counts, with a known or
80  * unknown disposition; nb_channel_layouts must then be 0 and all_layouts 1.
81  * - The list must not contain a layout with a known disposition and a
82  * channel count with unknown disposition with the same number of channels
83  * (e.g. AV_CH_LAYOUT_STEREO and FF_COUNT2LAYOUT(2).
84  */
85 typedef struct AVFilterChannelLayouts {
86  uint64_t *channel_layouts; ///< list of channel layouts
87  int nb_channel_layouts; ///< number of channel layouts
88  char all_layouts; ///< accept any known channel layout
89  char all_counts; ///< accept any channel layout or count
90 
91  unsigned refcount; ///< number of references to this list
92  struct AVFilterChannelLayouts ***refs; ///< references to this list
94 
95 /**
96  * Encode a channel count as a channel layout.
97  * FF_COUNT2LAYOUT(c) means any channel layout with c channels, with a known
98  * or unknown disposition.
99  * The result is only valid inside AVFilterChannelLayouts and immediately
100  * related functions.
101  */
102 #define FF_COUNT2LAYOUT(c) (0x8000000000000000ULL | (c))
103 
104 /**
105  * Decode a channel count encoded as a channel layout.
106  * Return 0 if the channel layout was a real one.
107  */
108 #define FF_LAYOUT2COUNT(l) (((l) & 0x8000000000000000ULL) ? \
109  (int)((l) & 0x7FFFFFFF) : 0)
110 
111 /**
112  * Return a channel layouts/samplerates list which contains the intersection of
113  * the layouts/samplerates of a and b. Also, all the references of a, all the
114  * references of b, and a and b themselves will be deallocated.
115  *
116  * If a and b do not share any common elements, neither is modified, and NULL
117  * is returned.
118  */
122  AVFilterFormats *b);
123 
124 /**
125  * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
126  * representing any channel layout (with known disposition)/sample rate.
127  */
130 
131 /**
132  * Construct an AVFilterChannelLayouts coding for any channel layout, with
133  * known or unknown disposition.
134  */
136 
138 
139 
140 /**
141  * A helper for query_formats() which sets all links to the same list of channel
142  * layouts/sample rates. If there are no links hooked to this filter, the list
143  * is freed.
144  */
148  AVFilterFormats *samplerates);
149 
150 /**
151  * A helper for query_formats() which sets all links to the same list of
152  * formats. If there are no links hooked to this filter, the list of formats is
153  * freed.
154  */
156 
157 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
158 
159 /**
160  * Add *ref as a new reference to f.
161  */
164 
165 /**
166  * Remove a reference to a channel layouts list.
167  */
169 
171  AVFilterChannelLayouts **newref);
172 
174 
175 /**
176  * Set the formats list to all existing formats.
177  * This function behaves like ff_default_query_formats(), except it also
178  * accepts channel layouts with unknown disposition. It should only be used
179  * with audio filters.
180  */
182 
183 
184 /**
185  * Create a list of supported formats. This is intended for use in
186  * AVFilter->query_formats().
187  *
188  * @param fmts list of media formats, terminated by -1
189  * @return the format list, with no existing references
190  */
191 AVFilterFormats *ff_make_format_list(const int *fmts);
192 
193 /**
194  * Add fmt to the list of media formats contained in *avff.
195  * If *avff is NULL the function allocates the filter formats struct
196  * and puts its pointer in *avff.
197  *
198  * @return a non negative value in case of success, or a negative
199  * value corresponding to an AVERROR code in case of error
200  */
201 int ff_add_format(AVFilterFormats **avff, int64_t fmt);
202 
203 /**
204  * Return a list of all formats supported by FFmpeg for the given media type.
205  */
207 
208 /**
209  * Construct a formats list containing all planar sample formats.
210  */
212 
213 /**
214  * Return a format list which contains the intersection of the formats of
215  * a and b. Also, all the references of a, all the references of b, and
216  * a and b themselves will be deallocated.
217  *
218  * If a and b do not share any common formats, neither is modified, and NULL
219  * is returned.
220  */
222  enum AVMediaType type);
223 
224 /**
225  * Add *ref as a new reference to formats.
226  * That is the pointers will point like in the ascii art below:
227  * ________
228  * |formats |<--------.
229  * | ____ | ____|___________________
230  * | |refs| | | __|_
231  * | |* * | | | | | | AVFilterLink
232  * | |* *--------->|*ref|
233  * | |____| | | |____|
234  * |________| |________________________
235  */
237 
238 /**
239  * If *ref is non-NULL, remove *ref as a reference to the format list
240  * it currently points to, deallocates that list if this was the last
241  * reference, and sets *ref to NULL.
242  *
243  * Before After
244  * ________ ________ NULL
245  * |formats |<--------. |formats | ^
246  * | ____ | ____|________________ | ____ | ____|________________
247  * | |refs| | | __|_ | |refs| | | __|_
248  * | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink
249  * | |* *--------->|*ref| | |* | | | |*ref|
250  * | |____| | | |____| | |____| | | |____|
251  * |________| |_____________________ |________| |_____________________
252  */
254 
255 /**
256  *
257  * Before After
258  * ________ ________
259  * |formats |<---------. |formats |<---------.
260  * | ____ | ___|___ | ____ | ___|___
261  * | |refs| | | | | | |refs| | | | | NULL
262  * | |* *--------->|*oldref| | |* *--------->|*newref| ^
263  * | |* * | | |_______| | |* * | | |_______| ___|___
264  * | |____| | | |____| | | | |
265  * |________| |________| |*oldref|
266  * |_______|
267  */
268 void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref);
269 
270 #endif /* AVFILTER_FORMATS_H */
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (...
Definition: formats.c:402
FIXME Range Coding of cr are ref
Definition: snow.txt:367
AVFilterChannelLayouts * ff_merge_channel_layouts(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b)
Return a channel layouts/samplerates list which contains the intersection of the layouts/samplerates ...
Definition: formats.c:166
const char * fmt
Definition: avisynth_c.h:669
external API header
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:357
Sinusoidal phase f
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to...
Definition: formats.c:468
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:350
struct AVFilterChannelLayouts *** refs
references to this list
Definition: formats.h:92
AVFilterFormats * ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type)
Return a format list which contains the intersection of the formats of a and b.
Definition: formats.c:92
#define b
Definition: input.c:42
struct AVFilterFormats *** refs
references to this list
Definition: formats.h:69
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:491
unsigned refcount
number of references to this list
Definition: formats.h:68
void ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:533
int ff_default_query_formats(AVFilterContext *ctx)
Definition: formats.c:567
uint64_t * channel_layouts
list of channel layouts
Definition: formats.h:86
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:308
char all_counts
accept any channel layout or count
Definition: formats.h:89
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:396
void 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:526
AVFilterFormats * ff_merge_samplerates(AVFilterFormats *a, AVFilterFormats *b)
Definition: formats.c:139
struct AVFilterChannelLayouts AVFilterChannelLayouts
A list of supported channel layouts.
A list of supported channel layouts.
Definition: formats.h:85
char all_layouts
accept any known channel layout
Definition: formats.h:88
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:344
void ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:432
void ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:427
AVMediaType
Definition: avutil.h:141
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:411
void 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:545
#define type
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:384
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
AVFilterChannelLayouts * avfilter_make_format64_list(const int64_t *fmts)
Definition: formats.c:317
unsigned refcount
number of references to this list
Definition: formats.h:91
A list of supported formats for one end of a filter link.
Definition: formats.h:64
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:473
An instance of a filter.
Definition: avfilter.h:524
int ff_query_formats_all(AVFilterContext *ctx)
Set the formats list to all existing formats.
Definition: formats.c:572
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Before After |formats |<------—.
Definition: formats.c:497
unsigned format_count
number of formats
Definition: formats.h:65
int * formats
list of media formats
Definition: formats.h:66