Support passing parameters to filters.
[libav.git] / libavfilter / avfilter.h
CommitLineData
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
25#include "avcodec.h"
26
27typedef struct AVFilterContext AVFilterContext;
28typedef struct AVFilterLink AVFilterLink;
29typedef struct AVFilterPad AVFilterPad;
30
31/* TODO: look for other flags which may be useful in this structure (interlace
32 * flags, etc)
33 */
34/**
35 * A reference-counted picture data type used by the filter system. Filters
36 * should not store pointers to this structure directly, but instead use the
37 * AVFilterPicRef structure below
38 */
39typedef struct AVFilterPic
40{
41 uint8_t *data[4];
42 int linesize[4]; ///< number of bytes per line
43 enum PixelFormat format;
44
45 unsigned refcount;
46 void *priv;
47 void (*free)(struct AVFilterPic *pic);
48} AVFilterPic;
49
50/**
51 * A reference to an AVFilterPic. Since filters can manipulate the origin of
52 * a picture to, for example, crop image without any memcpy, the picture origin
bbf42679
VS
53 * and dimensions are per-reference properties. Linesize is also useful for
54 * image flipping, frame to field filters, etc, and so is also per-reference.
a5cbb2f4
VS
55 *
56 * TODO: add pts, and anything necessary for frame reordering
57 */
58typedef struct AVFilterPicRef
59{
60 AVFilterPic *pic;
61 uint8_t *data[4];
bbf42679 62 int linesize[4];
a5cbb2f4
VS
63 int w, h;
64
65 int perms; ///< permissions
66#define AV_PERM_READ 0x01 ///< can read from the buffer
67#define AV_PERM_WRITE 0x02 ///< can write to the buffer
68#define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
69#define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times
70} AVFilterPicRef;
71
72/**
73 * Add a new reference to a picture.
74 * @param ref An existing reference to the picture
75 * @return A new reference to the picture with the same properties as the old
76 */
77AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref);
78
79/**
80 * Remove a reference to a picture. If this is the last reference to the
81 * picture, the picture itself is also automatically freed.
82 * @param ref Reference to the picture.
83 */
84void avfilter_unref_pic(AVFilterPicRef *ref);
85
86struct AVFilterPad
87{
88 /**
89 * Pad name. The name is unique among inputs and among oututs, but an
90 * input may have the same name as an output.
91 */
92 char *name;
93
94 /**
95 * AVFilterPad type. Only video supported now, hopefully someone will
96 * add audio in the future.
97 */
98 int type;
99#define AV_PAD_VIDEO 0
100
101 /**
102 * Callback called before passing the first slice of a new frame. If
103 * NULL, the filter layer will default to storing a reference to the
104 * picture inside the link structure.
105 */
106 void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref);
107
108 /**
109 * Callback function to get a buffer. If NULL, the filter system will
110 * handle buffer requests. Only required for input video pads.
111 */
112 AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms);
113
114 /**
115 * Callback called after the slices of a frame are completely sent. If
116 * NULL, the filter layer will default to releasing the reference stored
117 * in the link structure during start_frame().
118 */
119 void (*end_frame)(AVFilterLink *link);
120
121 /**
122 * Slice drawing callback. This is where a filter receives video data
123 * and should do its processing. Only required for input video pads.
124 */
125 void (*draw_slice)(AVFilterLink *link, uint8_t *data[4], int y, int height);
126
127 /**
128 * Frame request callback. A call to this should result in at least one
129 * frame being output over the given link. Video output pads only.
130 */
131 void (*request_frame)(AVFilterLink *link);
132
133 /**
134 * Callback to set properties of the link. Only for video output pads.
135 * XXX: this is not acceptable as is. it needs reworked to allow for
136 * negotiation of colorspace, etc.
137 */
138 int (*set_video_props)(AVFilterLink *link);
139};
140
141/* the default implementations of start_frame() and end_frame() */
142void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
143void avfilter_default_end_frame(AVFilterLink *link);
144
145typedef struct
146{
147 char *name;
148 char *author;
149
150 int priv_size;
151
4d96a914
VS
152 /**
153 * Filter initialization function. Args contains the user-supplied
154 * parameters. FIXME: maybe an AVOption-based system would be better?
155 */
156 int (*init)(AVFilterContext *ctx, const char *args);
a5cbb2f4
VS
157 void (*uninit)(AVFilterContext *ctx);
158
159 const AVFilterPad *inputs; /// NULL terminated list of inputs. NULL if none
160 const AVFilterPad *outputs; /// NULL terminated list of outputs. NULL if none
161} AVFilter;
162
163struct AVFilterContext
164{
165 AVClass *av_class;
166
167 AVFilter *filter;
168
169 AVFilterLink **inputs;
170 AVFilterLink **outputs;
171
172 void *priv;
173};
174
175struct AVFilterLink
176{
177 AVFilterContext *src;
178 unsigned int srcpad;
179
180 AVFilterContext *dst;
181 unsigned int dstpad;
182
183 int w, h;
184 enum PixelFormat format;
185
186 AVFilterPicRef *cur_pic;
187};
188
189/** Link two filters together */
190int avfilter_link(AVFilterContext *src, unsigned srcpad,
191 AVFilterContext *dst, unsigned dstpad);
192
193AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms);
194void avfilter_request_frame(AVFilterLink *link);
195void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
196void avfilter_end_frame(AVFilterLink *link);
197void avfilter_draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h);
198
199void avfilter_init(void);
200void avfilter_uninit(void);
201void avfilter_register(AVFilter *filter);
202AVFilter *avfilter_get_by_name(char *name);
203
204AVFilterContext *avfilter_create(AVFilter *filter);
205AVFilterContext *avfilter_create_by_name(char *name);
4d96a914 206int avfilter_init_filter(AVFilterContext *filter, const char *args);
a5cbb2f4
VS
207void avfilter_destroy(AVFilterContext *filter);
208
209#endif /* FFMPEG_AVFILTER_H */