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_INTERNAL_H
20 #define AVFILTER_INTERNAL_H
24 * internal API functions
30 #if !FF_API_AVFILTERPAD_PUBLIC
32 * A filter pad used for either input or output.
36 * Pad name. The name is unique among inputs and among outputs, but an
37 * input may have the same name as an output. This may be NULL if this
38 * pad has no need to ever be referenced by name.
45 enum AVMediaType type;
48 * Callback function to get a video buffer. If NULL, the filter system will
49 * use avfilter_default_get_video_buffer().
51 * Input video pads only.
53 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
56 * Callback function to get an audio buffer. If NULL, the filter system will
57 * use avfilter_default_get_audio_buffer().
59 * Input audio pads only.
61 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
64 * Filtering callback. This is where a filter receives a frame with
65 * audio/video data and should do its processing.
69 * @return >= 0 on success, a negative AVERROR on error. This function
70 * must ensure that samplesref is properly unreferenced on error if it
71 * hasn't been passed on to another filter.
73 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
76 * Frame poll callback. This returns the number of immediately available
77 * samples. It should return a positive value if the next request_frame()
78 * is guaranteed to return one frame (with no delay).
80 * Defaults to just calling the source poll_frame() method.
84 int (*poll_frame)(AVFilterLink *link);
87 * Frame request callback. A call to this should result in at least one
88 * frame being output over the given link. This should return zero on
89 * success, and another value on error.
93 int (*request_frame)(AVFilterLink *link);
96 * Link configuration callback.
98 * For output pads, this should set the link properties such as
99 * width/height. This should NOT set the format property - that is
100 * negotiated between filters by the filter system using the
101 * query_formats() callback before this function is called.
103 * For input pads, this should check the properties of the link, and update
104 * the filter's internal state as necessary.
106 * For both input and output filters, this should return zero on success,
107 * and another value on error.
109 int (*config_props)(AVFilterLink *link);
112 * The filter expects a fifo to be inserted on its input link,
113 * typically because it has a delay.
121 struct AVFilterGraphInternal {
123 int (*thread_execute)(AVFilterContext *ctx, action_func *func, void *arg,
124 int *ret, int nb_jobs);
127 struct AVFilterInternal {
128 int (*execute)(AVFilterContext *ctx, action_func *func, void *arg,
129 int *ret, int nb_jobs);
132 /** default handler for freeing audio/video buffer when there are no references left */
133 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
135 /** Tell is a format is contained in the provided list terminated by -1. */
136 int ff_fmt_is_in(int fmt, const int *fmts);
138 #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
140 void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
145 * @param idx Insertion point. Pad is inserted at the end if this point
146 * is beyond the end of the list of pads.
147 * @param count Pointer to the number of pads in the list
148 * @param padidx_off Offset within an AVFilterLink structure to the element
149 * to increment when inserting a new pad causes link
150 * numbering to change
151 * @param pads Pointer to the pointer to the beginning of the list of pads
152 * @param links Pointer to the pointer to the beginning of the list of links
153 * @param newpad The new pad to add. A copy is made when adding.
155 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
156 AVFilterPad **pads, AVFilterLink ***links,
157 AVFilterPad *newpad);
159 /** Insert a new input pad for the filter. */
160 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
163 ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
164 &f->input_pads, &f->inputs, p);
166 f->input_count = f->nb_inputs;
170 /** Insert a new output pad for the filter. */
171 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
174 ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
175 &f->output_pads, &f->outputs, p);
177 f->output_count = f->nb_outputs;
182 * Poll a frame from the filter chain.
184 * @param link the input link
185 * @return the number of immediately available frames, a negative
186 * number in case of error
188 int ff_poll_frame(AVFilterLink *link);
191 * Request an input frame from the filter at the other end of the link.
193 * @param link the input link
194 * @return zero on success
196 int ff_request_frame(AVFilterLink *link);
199 * Send a frame of data to the next filter.
201 * @param link the output link over which the data is being sent
202 * @param frame a reference to the buffer of data being sent. The
203 * receiving filter will free this reference when it no longer
204 * needs it or pass it on to the next filter.
206 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
207 * is responsible for unreferencing frame in case of error.
209 int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
212 * Allocate a new filter context and return it.
214 * @param filter what filter to create an instance of
215 * @param inst_name name to give to the new filter context
217 * @return newly created filter context or NULL on failure
219 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
222 * Remove a filter from a graph;
224 void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
226 #endif /* AVFILTER_INTERNAL_H */