]> git.sesse.net Git - ffmpeg/blob - libavfilter/internal.h
FATE: add a test for the overlay filter
[ffmpeg] / libavfilter / internal.h
1 /*
2  * This file is part of Libav.
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #ifndef AVFILTER_INTERNAL_H
20 #define AVFILTER_INTERNAL_H
21
22 /**
23  * @file
24  * internal API functions
25  */
26
27 #include "avfilter.h"
28
29 #if !FF_API_AVFILTERPAD_PUBLIC
30 /**
31  * A filter pad used for either input or output.
32  */
33 struct AVFilterPad {
34     /**
35      * Pad name. The name is unique among inputs and among outputs, but an
36      * input may have the same name as an output. This may be NULL if this
37      * pad has no need to ever be referenced by name.
38      */
39     const char *name;
40
41     /**
42      * AVFilterPad type.
43      */
44     enum AVMediaType type;
45
46     /**
47      * Callback function to get a video buffer. If NULL, the filter system will
48      * use avfilter_default_get_video_buffer().
49      *
50      * Input video pads only.
51      */
52     AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
53
54     /**
55      * Callback function to get an audio buffer. If NULL, the filter system will
56      * use avfilter_default_get_audio_buffer().
57      *
58      * Input audio pads only.
59      */
60     AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
61
62     /**
63      * Filtering callback. This is where a filter receives a frame with
64      * audio/video data and should do its processing.
65      *
66      * Input pads only.
67      *
68      * @return >= 0 on success, a negative AVERROR on error. This function
69      * must ensure that samplesref is properly unreferenced on error if it
70      * hasn't been passed on to another filter.
71      */
72     int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
73
74     /**
75      * Frame poll callback. This returns the number of immediately available
76      * samples. It should return a positive value if the next request_frame()
77      * is guaranteed to return one frame (with no delay).
78      *
79      * Defaults to just calling the source poll_frame() method.
80      *
81      * Output pads only.
82      */
83     int (*poll_frame)(AVFilterLink *link);
84
85     /**
86      * Frame request callback. A call to this should result in at least one
87      * frame being output over the given link. This should return zero on
88      * success, and another value on error.
89      *
90      * Output pads only.
91      */
92     int (*request_frame)(AVFilterLink *link);
93
94     /**
95      * Link configuration callback.
96      *
97      * For output pads, this should set the link properties such as
98      * width/height. This should NOT set the format property - that is
99      * negotiated between filters by the filter system using the
100      * query_formats() callback before this function is called.
101      *
102      * For input pads, this should check the properties of the link, and update
103      * the filter's internal state as necessary.
104      *
105      * For both input and output filters, this should return zero on success,
106      * and another value on error.
107      */
108     int (*config_props)(AVFilterLink *link);
109
110     /**
111      * The filter expects a fifo to be inserted on its input link,
112      * typically because it has a delay.
113      *
114      * input pads only.
115      */
116     int needs_fifo;
117 };
118 #endif
119
120 /** default handler for freeing audio/video buffer when there are no references left */
121 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
122
123 /** Tell is a format is contained in the provided list terminated by -1. */
124 int ff_fmt_is_in(int fmt, const int *fmts);
125
126 #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
127
128 void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
129
130 /**
131  * Insert a new pad.
132  *
133  * @param idx Insertion point. Pad is inserted at the end if this point
134  *            is beyond the end of the list of pads.
135  * @param count Pointer to the number of pads in the list
136  * @param padidx_off Offset within an AVFilterLink structure to the element
137  *                   to increment when inserting a new pad causes link
138  *                   numbering to change
139  * @param pads Pointer to the pointer to the beginning of the list of pads
140  * @param links Pointer to the pointer to the beginning of the list of links
141  * @param newpad The new pad to add. A copy is made when adding.
142  */
143 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
144                    AVFilterPad **pads, AVFilterLink ***links,
145                    AVFilterPad *newpad);
146
147 /** Insert a new input pad for the filter. */
148 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
149                                    AVFilterPad *p)
150 {
151     ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
152                   &f->input_pads, &f->inputs, p);
153 #if FF_API_FOO_COUNT
154     f->input_count = f->nb_inputs;
155 #endif
156 }
157
158 /** Insert a new output pad for the filter. */
159 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
160                                     AVFilterPad *p)
161 {
162     ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
163                   &f->output_pads, &f->outputs, p);
164 #if FF_API_FOO_COUNT
165     f->output_count = f->nb_outputs;
166 #endif
167 }
168
169 /**
170  * Poll a frame from the filter chain.
171  *
172  * @param  link the input link
173  * @return the number of immediately available frames, a negative
174  * number in case of error
175  */
176 int ff_poll_frame(AVFilterLink *link);
177
178 /**
179  * Request an input frame from the filter at the other end of the link.
180  *
181  * @param link the input link
182  * @return     zero on success
183  */
184 int ff_request_frame(AVFilterLink *link);
185
186 /**
187  * Send a frame of data to the next filter.
188  *
189  * @param link   the output link over which the data is being sent
190  * @param frame a reference to the buffer of data being sent. The
191  *              receiving filter will free this reference when it no longer
192  *              needs it or pass it on to the next filter.
193  *
194  * @return >= 0 on success, a negative AVERROR on error. The receiving filter
195  * is responsible for unreferencing frame in case of error.
196  */
197 int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
198
199 #endif /* AVFILTER_INTERNAL_H */