vf_yadif: factorize initializing the filtering callbacks
[FFMpeg-mirror/mplayer-patches.git] / libavfilter / formats.h
blob0e1628c850dc377db00d00f4662228d2117b4298
1 /*
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
22 #include "avfilter.h"
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.
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:
46 * (a) = {A, B}
47 * (b) = {A, B, C}
48 * (c) = {B, C}
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
57 * where (a) = {B}.
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 struct AVFilterFormats {
65 unsigned format_count; ///< number of formats
66 int *formats; ///< list of media formats
68 unsigned refcount; ///< number of references to this list
69 struct AVFilterFormats ***refs; ///< references to this list
72 typedef struct AVFilterChannelLayouts {
73 uint64_t *channel_layouts; ///< list of channel layouts
74 int nb_channel_layouts; ///< number of channel layouts
76 unsigned refcount; ///< number of references to this list
77 struct AVFilterChannelLayouts ***refs; ///< references to this list
78 } AVFilterChannelLayouts;
80 /**
81 * Return a channel layouts/samplerates list which contains the intersection of
82 * the layouts/samplerates of a and b. Also, all the references of a, all the
83 * references of b, and a and b themselves will be deallocated.
85 * If a and b do not share any common elements, neither is modified, and NULL
86 * is returned.
88 AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
89 AVFilterChannelLayouts *b);
90 AVFilterFormats *ff_merge_samplerates(AVFilterFormats *a,
91 AVFilterFormats *b);
93 /**
94 * Construct an empty AVFilterChannelLayouts/AVFilterFormats struct --
95 * representing any channel layout/sample rate.
97 AVFilterChannelLayouts *ff_all_channel_layouts(void);
98 AVFilterFormats *ff_all_samplerates(void);
101 * A helper for query_formats() which sets all links to the same list of channel
102 * layouts/sample rates. If there are no links hooked to this filter, the list
103 * is freed.
105 void ff_set_common_channel_layouts(AVFilterContext *ctx,
106 AVFilterChannelLayouts *layouts);
107 void ff_set_common_samplerates(AVFilterContext *ctx,
108 AVFilterFormats *samplerates);
111 * A helper for query_formats() which sets all links to the same list of
112 * formats. If there are no links hooked to this filter, the list of formats is
113 * freed.
115 void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
117 int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout);
120 * Add *ref as a new reference to f.
122 void ff_channel_layouts_ref(AVFilterChannelLayouts *f,
123 AVFilterChannelLayouts **ref);
126 * Remove a reference to a channel layouts list.
128 void ff_channel_layouts_unref(AVFilterChannelLayouts **ref);
130 void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref,
131 AVFilterChannelLayouts **newref);
133 int ff_default_query_formats(AVFilterContext *ctx);
137 * Create a list of supported formats. This is intended for use in
138 * AVFilter->query_formats().
140 * @param fmts list of media formats, terminated by -1
141 * @return the format list, with no existing references
143 AVFilterFormats *ff_make_format_list(const int *fmts);
146 * Add fmt to the list of media formats contained in *avff.
147 * If *avff is NULL the function allocates the filter formats struct
148 * and puts its pointer in *avff.
150 * @return a non negative value in case of success, or a negative
151 * value corresponding to an AVERROR code in case of error
153 int ff_add_format(AVFilterFormats **avff, int fmt);
156 * Return a list of all formats supported by Libav for the given media type.
158 AVFilterFormats *ff_all_formats(enum AVMediaType type);
161 * Construct a formats list containing all planar sample formats.
163 AVFilterFormats *ff_planar_sample_fmts(void);
166 * Return a format list which contains the intersection of the formats of
167 * a and b. Also, all the references of a, all the references of b, and
168 * a and b themselves will be deallocated.
170 * If a and b do not share any common formats, neither is modified, and NULL
171 * is returned.
173 AVFilterFormats *ff_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
176 * Add *ref as a new reference to formats.
177 * That is the pointers will point like in the ascii art below:
178 * ________
179 * |formats |<--------.
180 * | ____ | ____|___________________
181 * | |refs| | | __|_
182 * | |* * | | | | | | AVFilterLink
183 * | |* *--------->|*ref|
184 * | |____| | | |____|
185 * |________| |________________________
187 void ff_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
190 * If *ref is non-NULL, remove *ref as a reference to the format list
191 * it currently points to, deallocates that list if this was the last
192 * reference, and sets *ref to NULL.
194 * Before After
195 * ________ ________ NULL
196 * |formats |<--------. |formats | ^
197 * | ____ | ____|________________ | ____ | ____|________________
198 * | |refs| | | __|_ | |refs| | | __|_
199 * | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink
200 * | |* *--------->|*ref| | |* | | | |*ref|
201 * | |____| | | |____| | |____| | | |____|
202 * |________| |_____________________ |________| |_____________________
204 void ff_formats_unref(AVFilterFormats **ref);
208 * Before After
209 * ________ ________
210 * |formats |<---------. |formats |<---------.
211 * | ____ | ___|___ | ____ | ___|___
212 * | |refs| | | | | | |refs| | | | | NULL
213 * | |* *--------->|*oldref| | |* *--------->|*newref| ^
214 * | |* * | | |_______| | |* * | | |_______| ___|___
215 * | |____| | | |____| | | | |
216 * |________| |________| |*oldref|
217 * |_______|
219 void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref);
221 #endif /* AVFILTER_FORMATS_H */