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