2 * This file is part of Libav.
4 * Libav 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.
9 * Libav 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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVFILTER_FORMATS_H
20 #define AVFILTER_FORMATS_H
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.
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.
41 * For example, consider the filter chain:
42 * filter (a) --> (b) filter (b) --> (c) filter
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:
50 * First, the first link's lists are merged, yielding:
51 * filter (a) --> (a) filter (a) --> (c) filter
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
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.
64 #if !FF_API_FILTERS_PUBLIC
65 struct AVFilterFormats {
66 unsigned format_count; ///< number of formats
67 int *formats; ///< list of media formats
69 unsigned refcount; ///< number of references to this list
70 struct AVFilterFormats ***refs; ///< references to this list
74 typedef struct AVFilterChannelLayouts {
75 uint64_t *channel_layouts; ///< list of channel layouts
76 int nb_channel_layouts; ///< number of channel layouts
78 unsigned refcount; ///< number of references to this list
79 struct AVFilterChannelLayouts ***refs; ///< references to this list
80 } AVFilterChannelLayouts;
83 * Return a channel layouts/samplerates list which contains the intersection of
84 * the layouts/samplerates of a and b. Also, all the references of a, all the
85 * references of b, and a and b themselves will be deallocated.
87 * If a and b do not share any common elements, neither is modified, and NULL
90 AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
91 AVFilterChannelLayouts *b);
92 AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a,
96 * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
97 * representing any channel layout/sample rate.
99 AVFilterChannelLayouts *ff_all_channel_layouts(void);
100 AVFilterFormats *ff_all_samplerates(void);
103 * A helper for query_formats() which sets all links to the same list of channel
104 * layouts/sample rates. If there are no links hooked to this filter, the list
107 void ff_set_common_channel_layouts(AVFilterContext *ctx,
108 AVFilterChannelLayouts *layouts);
109 void ff_set_common_samplerates(AVFilterContext *ctx,
110 AVFilterFormats *samplerates);
113 * A helper for query_formats() which sets all links to the same list of
114 * formats. If there are no links hooked to this filter, the list of formats is
117 void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
119 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
122 * Add *ref as a new reference to f.
124 void ff_channel_layouts_ref(AVFilterChannelLayouts *f,
125 AVFilterChannelLayouts **ref);
128 * Remove a reference to a channel layouts list.
130 void ff_channel_layouts_unref(AVFilterChannelLayouts **ref);
132 void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref,
133 AVFilterChannelLayouts **newref);
135 int ff_default_query_formats(AVFilterContext *ctx);
139 * Create a list of supported formats. This is intended for use in
140 * AVFilter->query_formats().
142 * @param fmts list of media formats, terminated by -1
143 * @return the format list, with no existing references
145 AVFilterFormats *ff_make_format_list(const int *fmts);
148 * Add fmt to the list of media formats contained in *avff.
149 * If *avff is NULL the function allocates the filter formats struct
150 * and puts its pointer in *avff.
152 * @return a non negative value in case of success, or a negative
153 * value corresponding to an AVERROR code in case of error
155 int ff_add_format(AVFilterFormats **avff, int fmt);
158 * Return a list of all formats supported by Libav for the given media type.
160 AVFilterFormats *ff_all_formats(enum AVMediaType type);
163 * Return a format list which contains the intersection of the formats of
164 * a and b. Also, all the references of a, all the references of b, and
165 * a and b themselves will be deallocated.
167 * If a and b do not share any common formats, neither is modified, and NULL
170 AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
173 * Add *ref as a new reference to formats.
174 * That is the pointers will point like in the ascii art below:
176 * |formats |<--------.
177 * | ____ | ____|___________________
179 * | |* * | | | | | | AVFilterLink
180 * | |* *--------->|*ref|
181 * | |____| | | |____|
182 * |________| |________________________
184 void ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
187 * If *ref is non-NULL, remove *ref as a reference to the format list
188 * it currently points to, deallocates that list if this was the last
189 * reference, and sets *ref to NULL.
192 * ________ ________ NULL
193 * |formats |<--------. |formats | ^
194 * | ____ | ____|________________ | ____ | ____|________________
195 * | |refs| | | __|_ | |refs| | | __|_
196 * | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink
197 * | |* *--------->|*ref| | |* | | | |*ref|
198 * | |____| | | |____| | |____| | | |____|
199 * |________| |_____________________ |________| |_____________________
201 void ff_formats_unref(AVFilterFormats **ref);
207 * |formats |<---------. |formats |<---------.
208 * | ____ | ___|___ | ____ | ___|___
209 * | |refs| | | | | | |refs| | | | | NULL
210 * | |* *--------->|*oldref| | |* *--------->|*newref| ^
211 * | |* * | | |_______| | |* * | | |_______| ___|___
212 * | |____| | | |____| | | | |
213 * |________| |________| |*oldref|
216 void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref);
218 #endif // AVFILTER_FORMATS_H