OSDN Git Service

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