Commit | Line | Data |
---|---|---|
a5cbb2f4 VS |
1 | /* |
2 | * Filter layer | |
3 | * copyright (c) 2007 Bobby Bingham | |
4 | * | |
5 | * This file is part of FFmpeg. | |
6 | * | |
7 | * FFmpeg is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2.1 of the License, or (at your option) any later version. | |
11 | * | |
12 | * FFmpeg is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with FFmpeg; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #ifndef FFMPEG_AVFILTER_H | |
23 | #define FFMPEG_AVFILTER_H | |
24 | ||
a9c81431 | 25 | #include <stddef.h> |
a5cbb2f4 VS |
26 | #include "avcodec.h" |
27 | ||
28 | typedef struct AVFilterContext AVFilterContext; | |
29 | typedef struct AVFilterLink AVFilterLink; | |
30 | typedef struct AVFilterPad AVFilterPad; | |
31 | ||
32 | /* TODO: look for other flags which may be useful in this structure (interlace | |
33 | * flags, etc) | |
34 | */ | |
35 | /** | |
36 | * A reference-counted picture data type used by the filter system. Filters | |
37 | * should not store pointers to this structure directly, but instead use the | |
38 | * AVFilterPicRef structure below | |
39 | */ | |
40 | typedef struct AVFilterPic | |
41 | { | |
42 | uint8_t *data[4]; | |
43 | int linesize[4]; ///< number of bytes per line | |
44 | enum PixelFormat format; | |
45 | ||
46 | unsigned refcount; | |
47 | void *priv; | |
48 | void (*free)(struct AVFilterPic *pic); | |
49 | } AVFilterPic; | |
50 | ||
51 | /** | |
52 | * A reference to an AVFilterPic. Since filters can manipulate the origin of | |
53 | * a picture to, for example, crop image without any memcpy, the picture origin | |
bbf42679 VS |
54 | * and dimensions are per-reference properties. Linesize is also useful for |
55 | * image flipping, frame to field filters, etc, and so is also per-reference. | |
a5cbb2f4 | 56 | * |
1a18860a | 57 | * TODO: add anything necessary for frame reordering |
a5cbb2f4 VS |
58 | */ |
59 | typedef struct AVFilterPicRef | |
60 | { | |
61 | AVFilterPic *pic; | |
62 | uint8_t *data[4]; | |
bbf42679 | 63 | int linesize[4]; |
a5cbb2f4 VS |
64 | int w, h; |
65 | ||
1a18860a VS |
66 | int64_t pts; ///< presentation timestamp in milliseconds |
67 | ||
a5cbb2f4 VS |
68 | int perms; ///< permissions |
69 | #define AV_PERM_READ 0x01 ///< can read from the buffer | |
70 | #define AV_PERM_WRITE 0x02 ///< can write to the buffer | |
71 | #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer | |
72 | #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times | |
73 | } AVFilterPicRef; | |
74 | ||
75 | /** | |
76 | * Add a new reference to a picture. | |
77 | * @param ref An existing reference to the picture | |
8fb48e7c | 78 | * @param pmask A bitmask containing the allowable permissions in the new reference |
a5cbb2f4 VS |
79 | * @return A new reference to the picture with the same properties as the old |
80 | */ | |
8fb48e7c | 81 | AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask); |
a5cbb2f4 VS |
82 | |
83 | /** | |
84 | * Remove a reference to a picture. If this is the last reference to the | |
85 | * picture, the picture itself is also automatically freed. | |
86 | * @param ref Reference to the picture. | |
87 | */ | |
88 | void avfilter_unref_pic(AVFilterPicRef *ref); | |
89 | ||
90 | struct AVFilterPad | |
91 | { | |
92 | /** | |
93 | * Pad name. The name is unique among inputs and among oututs, but an | |
94 | * input may have the same name as an output. | |
95 | */ | |
96 | char *name; | |
97 | ||
98 | /** | |
99 | * AVFilterPad type. Only video supported now, hopefully someone will | |
100 | * add audio in the future. | |
101 | */ | |
102 | int type; | |
103 | #define AV_PAD_VIDEO 0 | |
104 | ||
105 | /** | |
d3e57c15 VS |
106 | * Callback to get a list of supported formats. The returned list should |
107 | * be terminated by -1. This is used for both input and output pads and | |
108 | * is required for both. | |
109 | */ | |
110 | int *(*query_formats)(AVFilterLink *link); | |
111 | ||
112 | /** | |
a5cbb2f4 VS |
113 | * Callback called before passing the first slice of a new frame. If |
114 | * NULL, the filter layer will default to storing a reference to the | |
115 | * picture inside the link structure. | |
116 | */ | |
117 | void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref); | |
118 | ||
119 | /** | |
120 | * Callback function to get a buffer. If NULL, the filter system will | |
121 | * handle buffer requests. Only required for input video pads. | |
122 | */ | |
123 | AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms); | |
124 | ||
125 | /** | |
126 | * Callback called after the slices of a frame are completely sent. If | |
127 | * NULL, the filter layer will default to releasing the reference stored | |
128 | * in the link structure during start_frame(). | |
129 | */ | |
130 | void (*end_frame)(AVFilterLink *link); | |
131 | ||
132 | /** | |
133 | * Slice drawing callback. This is where a filter receives video data | |
134 | * and should do its processing. Only required for input video pads. | |
135 | */ | |
136 | void (*draw_slice)(AVFilterLink *link, uint8_t *data[4], int y, int height); | |
137 | ||
138 | /** | |
139 | * Frame request callback. A call to this should result in at least one | |
140 | * frame being output over the given link. Video output pads only. | |
141 | */ | |
63f64e6f | 142 | int (*request_frame)(AVFilterLink *link); |
a5cbb2f4 VS |
143 | |
144 | /** | |
d3e57c15 VS |
145 | * Link configuration callback. For output pads, this should set the link |
146 | * properties such as width/height. NOTE: this should not set the format | |
147 | * property - that is negotiated between filters by the filter system using | |
148 | * the query_formats() callback. | |
149 | * | |
150 | * For input pads, this should check the properties of the link, and update | |
151 | * the filter's internal state as necessary. | |
a5cbb2f4 | 152 | */ |
d3e57c15 | 153 | int (*config_props)(AVFilterLink *link); |
a5cbb2f4 VS |
154 | }; |
155 | ||
901e6b39 | 156 | /* the default implementations of filter entry points */ |
a5cbb2f4 VS |
157 | void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref); |
158 | void avfilter_default_end_frame(AVFilterLink *link); | |
901e6b39 | 159 | int avfilter_default_config_output_link(AVFilterLink *link); |
85322466 | 160 | int avfilter_default_config_input_link (AVFilterLink *link); |
901e6b39 VS |
161 | int *avfilter_default_query_output_formats(AVFilterLink *link); |
162 | AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, | |
163 | int perms); | |
a5cbb2f4 VS |
164 | |
165 | typedef struct | |
166 | { | |
167 | char *name; | |
168 | char *author; | |
169 | ||
170 | int priv_size; | |
171 | ||
4d96a914 VS |
172 | /** |
173 | * Filter initialization function. Args contains the user-supplied | |
174 | * parameters. FIXME: maybe an AVOption-based system would be better? | |
6e365c57 VS |
175 | * opaque is data provided by the code requesting creation of the filter, |
176 | * and is used to pass data to the filter. | |
4d96a914 | 177 | */ |
95bcf498 | 178 | int (*init)(AVFilterContext *ctx, const char *args, void *opaque); |
a5cbb2f4 VS |
179 | void (*uninit)(AVFilterContext *ctx); |
180 | ||
181 | const AVFilterPad *inputs; /// NULL terminated list of inputs. NULL if none | |
182 | const AVFilterPad *outputs; /// NULL terminated list of outputs. NULL if none | |
183 | } AVFilter; | |
184 | ||
185 | struct AVFilterContext | |
186 | { | |
187 | AVClass *av_class; | |
188 | ||
189 | AVFilter *filter; | |
190 | ||
dcea2482 VS |
191 | char *name; |
192 | ||
25f8e601 | 193 | unsigned input_count; |
7c9066a3 | 194 | AVFilterPad *input_pads; |
a5cbb2f4 | 195 | AVFilterLink **inputs; |
25f8e601 VS |
196 | |
197 | unsigned output_count; | |
7c9066a3 | 198 | AVFilterPad *output_pads; |
a5cbb2f4 VS |
199 | AVFilterLink **outputs; |
200 | ||
201 | void *priv; | |
202 | }; | |
203 | ||
204 | struct AVFilterLink | |
205 | { | |
206 | AVFilterContext *src; | |
207 | unsigned int srcpad; | |
208 | ||
209 | AVFilterContext *dst; | |
210 | unsigned int dstpad; | |
211 | ||
212 | int w, h; | |
213 | enum PixelFormat format; | |
214 | ||
215 | AVFilterPicRef *cur_pic; | |
462f57db | 216 | AVFilterPicRef *outpic; |
a5cbb2f4 VS |
217 | }; |
218 | ||
219 | /** Link two filters together */ | |
220 | int avfilter_link(AVFilterContext *src, unsigned srcpad, | |
221 | AVFilterContext *dst, unsigned dstpad); | |
222 | ||
85322466 VS |
223 | /** Configure the colorspace, dimensions, etc of a link */ |
224 | int avfilter_config_link(AVFilterLink *link); | |
225 | ||
a5cbb2f4 | 226 | AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms); |
63f64e6f | 227 | int avfilter_request_frame(AVFilterLink *link); |
a5cbb2f4 VS |
228 | void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref); |
229 | void avfilter_end_frame(AVFilterLink *link); | |
230 | void avfilter_draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h); | |
231 | ||
232 | void avfilter_init(void); | |
233 | void avfilter_uninit(void); | |
234 | void avfilter_register(AVFilter *filter); | |
235 | AVFilter *avfilter_get_by_name(char *name); | |
236 | ||
dcea2482 VS |
237 | AVFilterContext *avfilter_create(AVFilter *filter, char *inst_name); |
238 | AVFilterContext *avfilter_create_by_name(char *name, char *inst_name); | |
6e365c57 | 239 | int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque); |
a5cbb2f4 VS |
240 | void avfilter_destroy(AVFilterContext *filter); |
241 | ||
d3e57c15 VS |
242 | int *avfilter_make_format_list(int len, ...); |
243 | ||
a9c81431 VS |
244 | /** |
245 | * Insert a new pad | |
246 | * @param idx Insertion point. Pad is inserted at the end if this point | |
247 | * is beyond the end of the list of pads. | |
248 | * @param count Pointer to the number of pads in the list | |
249 | * @param padidx_off Offset within an AVFilterLink structure to the element | |
250 | * to increment when inserting a new pad causes link | |
251 | * numbering to change | |
252 | * @param pads Pointer to the pointer to the beginning of the list of pads | |
253 | * @param links Pointer to the pointer to the beginning of the list of links | |
254 | * @param newpad The new pad to add. A copy is made when adding. | |
255 | */ | |
256 | void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, | |
257 | AVFilterPad **pads, AVFilterLink ***links, | |
258 | AVFilterPad *newpad); | |
259 | ||
260 | /** insert a new input pad for the filter */ | |
261 | static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index, | |
262 | AVFilterPad *p) | |
263 | { | |
264 | avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), | |
265 | &f->input_pads, &f->inputs, p); | |
266 | } | |
267 | ||
268 | /** insert a new output pad for the filter */ | |
269 | static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index, | |
270 | AVFilterPad *p) | |
271 | { | |
272 | avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), | |
273 | &f->output_pads, &f->outputs, p); | |
274 | } | |
275 | ||
a5cbb2f4 | 276 | #endif /* FFMPEG_AVFILTER_H */ |