]> git.sesse.net Git - ffmpeg/blob - libavfilter/internal.h
rtsp: Support mpegts in raw udp packets
[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      * Minimum required permissions on incoming buffers. Any buffer with
48      * insufficient permissions will be automatically copied by the filter
49      * system to a new buffer which provides the needed access permissions.
50      *
51      * Input pads only.
52      */
53     int min_perms;
54
55     /**
56      * Permissions which are not accepted on incoming buffers. Any buffer
57      * which has any of these permissions set will be automatically copied
58      * by the filter system to a new buffer which does not have those
59      * permissions. This can be used to easily disallow buffers with
60      * AV_PERM_REUSE.
61      *
62      * Input pads only.
63      */
64     int rej_perms;
65
66     /**
67      * Callback called before passing the first slice of a new frame. If
68      * NULL, the filter layer will default to storing a reference to the
69      * picture inside the link structure.
70      *
71      * Input video pads only.
72      *
73      * @return >= 0 on success, a negative AVERROR on error. picref will be
74      * unreferenced by the caller in case of error.
75      */
76     void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
77
78     /**
79      * Callback function to get a video buffer. If NULL, the filter system will
80      * use avfilter_default_get_video_buffer().
81      *
82      * Input video pads only.
83      */
84     AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
85
86     /**
87      * Callback function to get an audio buffer. If NULL, the filter system will
88      * use avfilter_default_get_audio_buffer().
89      *
90      * Input audio pads only.
91      */
92     AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
93                                            int nb_samples);
94
95     /**
96      * Callback called after the slices of a frame are completely sent. If
97      * NULL, the filter layer will default to releasing the reference stored
98      * in the link structure during start_frame().
99      *
100      * Input video pads only.
101      *
102      * @return >= 0 on success, a negative AVERROR on error.
103      */
104     int (*end_frame)(AVFilterLink *link);
105
106     /**
107      * Slice drawing callback. This is where a filter receives video data
108      * and should do its processing.
109      *
110      * Input video pads only.
111      *
112      * @return >= 0 on success, a negative AVERROR on error.
113      */
114     int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
115
116     /**
117      * Samples filtering callback. This is where a filter receives audio data
118      * and should do its processing.
119      *
120      * Input audio pads only.
121      *
122      * @return >= 0 on success, a negative AVERROR on error. This function
123      * must ensure that samplesref is properly unreferenced on error if it
124      * hasn't been passed on to another filter.
125      */
126     int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
127
128     /**
129      * Frame poll callback. This returns the number of immediately available
130      * samples. It should return a positive value if the next request_frame()
131      * is guaranteed to return one frame (with no delay).
132      *
133      * Defaults to just calling the source poll_frame() method.
134      *
135      * Output pads only.
136      */
137     int (*poll_frame)(AVFilterLink *link);
138
139     /**
140      * Frame request callback. A call to this should result in at least one
141      * frame being output over the given link. This should return zero on
142      * success, and another value on error.
143      *
144      * Output pads only.
145      */
146     int (*request_frame)(AVFilterLink *link);
147
148     /**
149      * Link configuration callback.
150      *
151      * For output pads, this should set the link properties such as
152      * width/height. This should NOT set the format property - that is
153      * negotiated between filters by the filter system using the
154      * query_formats() callback before this function is called.
155      *
156      * For input pads, this should check the properties of the link, and update
157      * the filter's internal state as necessary.
158      *
159      * For both input and output filters, this should return zero on success,
160      * and another value on error.
161      */
162     int (*config_props)(AVFilterLink *link);
163
164     /**
165      * The filter expects a fifo to be inserted on its input link,
166      * typically because it has a delay.
167      *
168      * input pads only.
169      */
170     int needs_fifo;
171 };
172 #endif
173
174 /** default handler for freeing audio/video buffer when there are no references left */
175 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
176
177 /** Tell is a format is contained in the provided list terminated by -1. */
178 int ff_fmt_is_in(int fmt, const int *fmts);
179
180 #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
181
182 void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
183
184 /**
185  * Insert a new pad.
186  *
187  * @param idx Insertion point. Pad is inserted at the end if this point
188  *            is beyond the end of the list of pads.
189  * @param count Pointer to the number of pads in the list
190  * @param padidx_off Offset within an AVFilterLink structure to the element
191  *                   to increment when inserting a new pad causes link
192  *                   numbering to change
193  * @param pads Pointer to the pointer to the beginning of the list of pads
194  * @param links Pointer to the pointer to the beginning of the list of links
195  * @param newpad The new pad to add. A copy is made when adding.
196  */
197 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
198                    AVFilterPad **pads, AVFilterLink ***links,
199                    AVFilterPad *newpad);
200
201 /** Insert a new input pad for the filter. */
202 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
203                                    AVFilterPad *p)
204 {
205     ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
206                   &f->input_pads, &f->inputs, p);
207 #if FF_API_FOO_COUNT
208     f->input_count = f->nb_inputs;
209 #endif
210 }
211
212 /** Insert a new output pad for the filter. */
213 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
214                                     AVFilterPad *p)
215 {
216     ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
217                   &f->output_pads, &f->outputs, p);
218 #if FF_API_FOO_COUNT
219     f->output_count = f->nb_outputs;
220 #endif
221 }
222
223 /**
224  * Poll a frame from the filter chain.
225  *
226  * @param  link the input link
227  * @return the number of immediately available frames, a negative
228  * number in case of error
229  */
230 int ff_poll_frame(AVFilterLink *link);
231
232 /**
233  * Request an input frame from the filter at the other end of the link.
234  *
235  * @param link the input link
236  * @return     zero on success
237  */
238 int ff_request_frame(AVFilterLink *link);
239
240 #endif /* AVFILTER_INTERNAL_H */