3 * copyright (c) 2007 Bobby Bingham
5 * This file is part of FFmpeg.
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.
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.
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
22 #ifndef FFMPEG_AVFILTER_H
23 #define FFMPEG_AVFILTER_H
28 typedef struct AVFilterContext AVFilterContext;
29 typedef struct AVFilterLink AVFilterLink;
30 typedef struct AVFilterPad AVFilterPad;
32 /* TODO: look for other flags which may be useful in this structure (interlace
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
40 typedef struct AVFilterPic
43 int linesize[4]; ///< number of bytes per line
44 enum PixelFormat format;
48 void (*free)(struct AVFilterPic *pic);
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
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.
57 * TODO: add anything necessary for frame reordering
59 typedef struct AVFilterPicRef
66 int64_t pts; ///< presentation timestamp in milliseconds
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
76 * Add a new reference to a picture.
77 * @param ref An existing reference to the picture
78 * @param pmask A bitmask containing the allowable permissions in the new reference
79 * @return A new reference to the picture with the same properties as the old
81 AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask);
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.
88 void avfilter_unref_pic(AVFilterPicRef *ref);
93 * Pad name. The name is unique among inputs and among oututs, but an
94 * input may have the same name as an output.
99 * AVFilterPad type. Only video supported now, hopefully someone will
100 * add audio in the future.
103 #define AV_PAD_VIDEO 0
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.
110 int *(*query_formats)(AVFilterLink *link);
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.
117 void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref);
120 * Callback function to get a buffer. If NULL, the filter system will
121 * handle buffer requests. Only required for input video pads.
123 AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms);
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().
130 void (*end_frame)(AVFilterLink *link);
133 * Slice drawing callback. This is where a filter receives video data
134 * and should do its processing. Only required for input video pads.
136 void (*draw_slice)(AVFilterLink *link, uint8_t *data[4], int y, int height);
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.
142 void (*request_frame)(AVFilterLink *link);
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.
150 * For input pads, this should check the properties of the link, and update
151 * the filter's internal state as necessary.
153 int (*config_props)(AVFilterLink *link);
156 /* the default implementations of filter entry points */
157 void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
158 void avfilter_default_end_frame(AVFilterLink *link);
159 int avfilter_default_config_output_link(AVFilterLink *link);
160 int avfilter_default_config_input_link (AVFilterLink *link);
161 int *avfilter_default_query_output_formats(AVFilterLink *link);
162 AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link,
173 * Filter initialization function. Args contains the user-supplied
174 * parameters. FIXME: maybe an AVOption-based system would be better?
175 * opaque is data provided by the code requesting creation of the filter,
176 * and is used to pass data to the filter.
178 int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
179 void (*uninit)(AVFilterContext *ctx);
181 const AVFilterPad *inputs; /// NULL terminated list of inputs. NULL if none
182 const AVFilterPad *outputs; /// NULL terminated list of outputs. NULL if none
185 struct AVFilterContext
193 unsigned input_count;
194 AVFilterPad *input_pads;
195 AVFilterLink **inputs;
197 unsigned output_count;
198 AVFilterPad *output_pads;
199 AVFilterLink **outputs;
206 AVFilterContext *src;
209 AVFilterContext *dst;
213 enum PixelFormat format;
215 AVFilterPicRef *cur_pic;
216 AVFilterPicRef *outpic;
219 /** Link two filters together */
220 int avfilter_link(AVFilterContext *src, unsigned srcpad,
221 AVFilterContext *dst, unsigned dstpad);
223 /** Configure the colorspace, dimensions, etc of a link */
224 int avfilter_config_link(AVFilterLink *link);
226 AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms);
227 void avfilter_request_frame(AVFilterLink *link);
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);
232 void avfilter_init(void);
233 void avfilter_uninit(void);
234 void avfilter_register(AVFilter *filter);
235 AVFilter *avfilter_get_by_name(char *name);
237 AVFilterContext *avfilter_create(AVFilter *filter, char *inst_name);
238 AVFilterContext *avfilter_create_by_name(char *name, char *inst_name);
239 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
240 void avfilter_destroy(AVFilterContext *filter);
242 int *avfilter_make_format_list(int len, ...);
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.
256 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
257 AVFilterPad **pads, AVFilterLink ***links,
258 AVFilterPad *newpad);
260 /** insert a new input pad for the filter */
261 static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
264 avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
265 &f->input_pads, &f->inputs, p);
268 /** insert a new output pad for the filter */
269 static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
272 avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
273 &f->output_pads, &f->outputs, p);
276 #endif /* FFMPEG_AVFILTER_H */