yading@10
|
1 /*
|
yading@10
|
2 * This file is part of FFmpeg.
|
yading@10
|
3 *
|
yading@10
|
4 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
5 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
6 * License as published by the Free Software Foundation; either
|
yading@10
|
7 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
8 *
|
yading@10
|
9 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
12 * Lesser General Public License for more details.
|
yading@10
|
13 *
|
yading@10
|
14 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
15 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
17 */
|
yading@10
|
18
|
yading@10
|
19 #ifndef AVFILTER_INTERNAL_H
|
yading@10
|
20 #define AVFILTER_INTERNAL_H
|
yading@10
|
21
|
yading@10
|
22 /**
|
yading@10
|
23 * @file
|
yading@10
|
24 * internal API functions
|
yading@10
|
25 */
|
yading@10
|
26
|
yading@10
|
27 #include "avfilter.h"
|
yading@10
|
28 #include "avfiltergraph.h"
|
yading@10
|
29 #include "formats.h"
|
yading@10
|
30 #include "video.h"
|
yading@10
|
31
|
yading@10
|
32 #define POOL_SIZE 32
|
yading@10
|
33 typedef struct AVFilterPool {
|
yading@10
|
34 AVFilterBufferRef *pic[POOL_SIZE];
|
yading@10
|
35 int count;
|
yading@10
|
36 int refcount;
|
yading@10
|
37 int draining;
|
yading@10
|
38 } AVFilterPool;
|
yading@10
|
39
|
yading@10
|
40 typedef struct AVFilterCommand {
|
yading@10
|
41 double time; ///< time expressed in seconds
|
yading@10
|
42 char *command; ///< command
|
yading@10
|
43 char *arg; ///< optional argument for the command
|
yading@10
|
44 int flags;
|
yading@10
|
45 struct AVFilterCommand *next;
|
yading@10
|
46 } AVFilterCommand;
|
yading@10
|
47
|
yading@10
|
48 /**
|
yading@10
|
49 * Update the position of a link in the age heap.
|
yading@10
|
50 */
|
yading@10
|
51 void ff_avfilter_graph_update_heap(AVFilterGraph *graph, AVFilterLink *link);
|
yading@10
|
52
|
yading@10
|
53 #if !FF_API_AVFILTERPAD_PUBLIC
|
yading@10
|
54 /**
|
yading@10
|
55 * A filter pad used for either input or output.
|
yading@10
|
56 */
|
yading@10
|
57 struct AVFilterPad {
|
yading@10
|
58 /**
|
yading@10
|
59 * Pad name. The name is unique among inputs and among outputs, but an
|
yading@10
|
60 * input may have the same name as an output. This may be NULL if this
|
yading@10
|
61 * pad has no need to ever be referenced by name.
|
yading@10
|
62 */
|
yading@10
|
63 const char *name;
|
yading@10
|
64
|
yading@10
|
65 /**
|
yading@10
|
66 * AVFilterPad type.
|
yading@10
|
67 */
|
yading@10
|
68 enum AVMediaType type;
|
yading@10
|
69
|
yading@10
|
70 /**
|
yading@10
|
71 * Callback function to get a video buffer. If NULL, the filter system will
|
yading@10
|
72 * use ff_default_get_video_buffer().
|
yading@10
|
73 *
|
yading@10
|
74 * Input video pads only.
|
yading@10
|
75 */
|
yading@10
|
76 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
|
yading@10
|
77
|
yading@10
|
78 /**
|
yading@10
|
79 * Callback function to get an audio buffer. If NULL, the filter system will
|
yading@10
|
80 * use ff_default_get_audio_buffer().
|
yading@10
|
81 *
|
yading@10
|
82 * Input audio pads only.
|
yading@10
|
83 */
|
yading@10
|
84 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
|
yading@10
|
85
|
yading@10
|
86 /**
|
yading@10
|
87 * Filtering callback. This is where a filter receives a frame with
|
yading@10
|
88 * audio/video data and should do its processing.
|
yading@10
|
89 *
|
yading@10
|
90 * Input pads only.
|
yading@10
|
91 *
|
yading@10
|
92 * @return >= 0 on success, a negative AVERROR on error. This function
|
yading@10
|
93 * must ensure that samplesref is properly unreferenced on error if it
|
yading@10
|
94 * hasn't been passed on to another filter.
|
yading@10
|
95 */
|
yading@10
|
96 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
|
yading@10
|
97
|
yading@10
|
98 /**
|
yading@10
|
99 * Frame poll callback. This returns the number of immediately available
|
yading@10
|
100 * samples. It should return a positive value if the next request_frame()
|
yading@10
|
101 * is guaranteed to return one frame (with no delay).
|
yading@10
|
102 *
|
yading@10
|
103 * Defaults to just calling the source poll_frame() method.
|
yading@10
|
104 *
|
yading@10
|
105 * Output pads only.
|
yading@10
|
106 */
|
yading@10
|
107 int (*poll_frame)(AVFilterLink *link);
|
yading@10
|
108
|
yading@10
|
109 /**
|
yading@10
|
110 * Frame request callback. A call to this should result in at least one
|
yading@10
|
111 * frame being output over the given link. This should return zero on
|
yading@10
|
112 * success, and another value on error.
|
yading@10
|
113 *
|
yading@10
|
114 * Output pads only.
|
yading@10
|
115 */
|
yading@10
|
116 int (*request_frame)(AVFilterLink *link);
|
yading@10
|
117
|
yading@10
|
118 /**
|
yading@10
|
119 * Link configuration callback.
|
yading@10
|
120 *
|
yading@10
|
121 * For output pads, this should set the link properties such as
|
yading@10
|
122 * width/height. This should NOT set the format property - that is
|
yading@10
|
123 * negotiated between filters by the filter system using the
|
yading@10
|
124 * query_formats() callback before this function is called.
|
yading@10
|
125 *
|
yading@10
|
126 * For input pads, this should check the properties of the link, and update
|
yading@10
|
127 * the filter's internal state as necessary.
|
yading@10
|
128 *
|
yading@10
|
129 * For both input and output filters, this should return zero on success,
|
yading@10
|
130 * and another value on error.
|
yading@10
|
131 */
|
yading@10
|
132 int (*config_props)(AVFilterLink *link);
|
yading@10
|
133
|
yading@10
|
134 /**
|
yading@10
|
135 * The filter expects a fifo to be inserted on its input link,
|
yading@10
|
136 * typically because it has a delay.
|
yading@10
|
137 *
|
yading@10
|
138 * input pads only.
|
yading@10
|
139 */
|
yading@10
|
140 int needs_fifo;
|
yading@10
|
141 };
|
yading@10
|
142 #endif
|
yading@10
|
143
|
yading@10
|
144 /** default handler for freeing audio/video buffer when there are no references left */
|
yading@10
|
145 void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
|
yading@10
|
146
|
yading@10
|
147 /** Tell is a format is contained in the provided list terminated by -1. */
|
yading@10
|
148 int ff_fmt_is_in(int fmt, const int *fmts);
|
yading@10
|
149
|
yading@10
|
150 /**
|
yading@10
|
151 * Return a copy of a list of integers terminated by -1, or NULL in
|
yading@10
|
152 * case of copy failure.
|
yading@10
|
153 */
|
yading@10
|
154 int *ff_copy_int_list(const int * const list);
|
yading@10
|
155
|
yading@10
|
156 /**
|
yading@10
|
157 * Return a copy of a list of 64-bit integers, or NULL in case of
|
yading@10
|
158 * copy failure.
|
yading@10
|
159 */
|
yading@10
|
160 int64_t *ff_copy_int64_list(const int64_t * const list);
|
yading@10
|
161
|
yading@10
|
162 /* Functions to parse audio format arguments */
|
yading@10
|
163
|
yading@10
|
164 /**
|
yading@10
|
165 * Parse a pixel format.
|
yading@10
|
166 *
|
yading@10
|
167 * @param ret pixel format pointer to where the value should be written
|
yading@10
|
168 * @param arg string to parse
|
yading@10
|
169 * @param log_ctx log context
|
yading@10
|
170 * @return 0 in case of success, a negative AVERROR code on error
|
yading@10
|
171 */
|
yading@10
|
172 int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx);
|
yading@10
|
173
|
yading@10
|
174 /**
|
yading@10
|
175 * Parse a sample rate.
|
yading@10
|
176 *
|
yading@10
|
177 * @param ret unsigned integer pointer to where the value should be written
|
yading@10
|
178 * @param arg string to parse
|
yading@10
|
179 * @param log_ctx log context
|
yading@10
|
180 * @return 0 in case of success, a negative AVERROR code on error
|
yading@10
|
181 */
|
yading@10
|
182 int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
|
yading@10
|
183
|
yading@10
|
184 /**
|
yading@10
|
185 * Parse a time base.
|
yading@10
|
186 *
|
yading@10
|
187 * @param ret unsigned AVRational pointer to where the value should be written
|
yading@10
|
188 * @param arg string to parse
|
yading@10
|
189 * @param log_ctx log context
|
yading@10
|
190 * @return 0 in case of success, a negative AVERROR code on error
|
yading@10
|
191 */
|
yading@10
|
192 int ff_parse_time_base(AVRational *ret, const char *arg, void *log_ctx);
|
yading@10
|
193
|
yading@10
|
194 /**
|
yading@10
|
195 * Parse a sample format name or a corresponding integer representation.
|
yading@10
|
196 *
|
yading@10
|
197 * @param ret integer pointer to where the value should be written
|
yading@10
|
198 * @param arg string to parse
|
yading@10
|
199 * @param log_ctx log context
|
yading@10
|
200 * @return 0 in case of success, a negative AVERROR code on error
|
yading@10
|
201 */
|
yading@10
|
202 int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx);
|
yading@10
|
203
|
yading@10
|
204 /**
|
yading@10
|
205 * Parse a channel layout or a corresponding integer representation.
|
yading@10
|
206 *
|
yading@10
|
207 * @param ret 64bit integer pointer to where the value should be written.
|
yading@10
|
208 * @param arg string to parse
|
yading@10
|
209 * @param log_ctx log context
|
yading@10
|
210 * @return 0 in case of success, a negative AVERROR code on error
|
yading@10
|
211 */
|
yading@10
|
212 int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx);
|
yading@10
|
213
|
yading@10
|
214 void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
|
yading@10
|
215
|
yading@10
|
216 void ff_command_queue_pop(AVFilterContext *filter);
|
yading@10
|
217
|
yading@10
|
218 /* misc trace functions */
|
yading@10
|
219
|
yading@10
|
220 /* #define FF_AVFILTER_TRACE */
|
yading@10
|
221
|
yading@10
|
222 #ifdef FF_AVFILTER_TRACE
|
yading@10
|
223 # define ff_tlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
|
yading@10
|
224 #else
|
yading@10
|
225 # define ff_tlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
|
yading@10
|
226 #endif
|
yading@10
|
227
|
yading@10
|
228 #define FF_TPRINTF_START(ctx, func) ff_tlog(NULL, "%-16s: ", #func)
|
yading@10
|
229
|
yading@10
|
230 char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms);
|
yading@10
|
231
|
yading@10
|
232 void ff_tlog_ref(void *ctx, AVFrame *ref, int end);
|
yading@10
|
233
|
yading@10
|
234 void ff_tlog_link(void *ctx, AVFilterLink *link, int end);
|
yading@10
|
235
|
yading@10
|
236 /**
|
yading@10
|
237 * Insert a new pad.
|
yading@10
|
238 *
|
yading@10
|
239 * @param idx Insertion point. Pad is inserted at the end if this point
|
yading@10
|
240 * is beyond the end of the list of pads.
|
yading@10
|
241 * @param count Pointer to the number of pads in the list
|
yading@10
|
242 * @param padidx_off Offset within an AVFilterLink structure to the element
|
yading@10
|
243 * to increment when inserting a new pad causes link
|
yading@10
|
244 * numbering to change
|
yading@10
|
245 * @param pads Pointer to the pointer to the beginning of the list of pads
|
yading@10
|
246 * @param links Pointer to the pointer to the beginning of the list of links
|
yading@10
|
247 * @param newpad The new pad to add. A copy is made when adding.
|
yading@10
|
248 */
|
yading@10
|
249 void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
|
yading@10
|
250 AVFilterPad **pads, AVFilterLink ***links,
|
yading@10
|
251 AVFilterPad *newpad);
|
yading@10
|
252
|
yading@10
|
253 /** Insert a new input pad for the filter. */
|
yading@10
|
254 static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
|
yading@10
|
255 AVFilterPad *p)
|
yading@10
|
256 {
|
yading@10
|
257 ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
|
yading@10
|
258 &f->input_pads, &f->inputs, p);
|
yading@10
|
259 #if FF_API_FOO_COUNT
|
yading@10
|
260 f->input_count = f->nb_inputs;
|
yading@10
|
261 #endif
|
yading@10
|
262 }
|
yading@10
|
263
|
yading@10
|
264 /** Insert a new output pad for the filter. */
|
yading@10
|
265 static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
|
yading@10
|
266 AVFilterPad *p)
|
yading@10
|
267 {
|
yading@10
|
268 ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
|
yading@10
|
269 &f->output_pads, &f->outputs, p);
|
yading@10
|
270 #if FF_API_FOO_COUNT
|
yading@10
|
271 f->output_count = f->nb_outputs;
|
yading@10
|
272 #endif
|
yading@10
|
273 }
|
yading@10
|
274
|
yading@10
|
275 /**
|
yading@10
|
276 * Poll a frame from the filter chain.
|
yading@10
|
277 *
|
yading@10
|
278 * @param link the input link
|
yading@10
|
279 * @return the number of immediately available frames, a negative
|
yading@10
|
280 * number in case of error
|
yading@10
|
281 */
|
yading@10
|
282 int ff_poll_frame(AVFilterLink *link);
|
yading@10
|
283
|
yading@10
|
284 /**
|
yading@10
|
285 * Request an input frame from the filter at the other end of the link.
|
yading@10
|
286 *
|
yading@10
|
287 * @param link the input link
|
yading@10
|
288 * @return zero on success
|
yading@10
|
289 */
|
yading@10
|
290 int ff_request_frame(AVFilterLink *link);
|
yading@10
|
291
|
yading@10
|
292 #define AVFILTER_DEFINE_CLASS(fname) \
|
yading@10
|
293 static const AVClass fname##_class = { \
|
yading@10
|
294 .class_name = #fname, \
|
yading@10
|
295 .item_name = av_default_item_name, \
|
yading@10
|
296 .option = fname##_options, \
|
yading@10
|
297 .version = LIBAVUTIL_VERSION_INT, \
|
yading@10
|
298 .category = AV_CLASS_CATEGORY_FILTER, \
|
yading@10
|
299 }
|
yading@10
|
300
|
yading@10
|
301 AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink,
|
yading@10
|
302 AVFilterBufferRef *ref);
|
yading@10
|
303
|
yading@10
|
304 /**
|
yading@10
|
305 * Find the index of a link.
|
yading@10
|
306 *
|
yading@10
|
307 * I.e. find i such that link == ctx->(in|out)puts[i]
|
yading@10
|
308 */
|
yading@10
|
309 #define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
|
yading@10
|
310 #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
|
yading@10
|
311
|
yading@10
|
312 int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf);
|
yading@10
|
313 int ff_buffersink_read_samples_compat(AVFilterContext *ctx, AVFilterBufferRef **pbuf,
|
yading@10
|
314 int nb_samples);
|
yading@10
|
315 /**
|
yading@10
|
316 * Send a frame of data to the next filter.
|
yading@10
|
317 *
|
yading@10
|
318 * @param link the output link over which the data is being sent
|
yading@10
|
319 * @param frame a reference to the buffer of data being sent. The
|
yading@10
|
320 * receiving filter will free this reference when it no longer
|
yading@10
|
321 * needs it or pass it on to the next filter.
|
yading@10
|
322 *
|
yading@10
|
323 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
|
yading@10
|
324 * is responsible for unreferencing frame in case of error.
|
yading@10
|
325 */
|
yading@10
|
326 int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
|
yading@10
|
327
|
yading@10
|
328 /**
|
yading@10
|
329 * Flags for AVFilterLink.flags.
|
yading@10
|
330 */
|
yading@10
|
331 enum {
|
yading@10
|
332
|
yading@10
|
333 /**
|
yading@10
|
334 * Frame requests may need to loop in order to be fulfilled.
|
yading@10
|
335 * A filter must set this flags on an output link if it may return 0 in
|
yading@10
|
336 * request_frame() without filtering a frame.
|
yading@10
|
337 */
|
yading@10
|
338 FF_LINK_FLAG_REQUEST_LOOP = 1,
|
yading@10
|
339
|
yading@10
|
340 };
|
yading@10
|
341
|
yading@10
|
342 /**
|
yading@10
|
343 * Allocate a new filter context and return it.
|
yading@10
|
344 *
|
yading@10
|
345 * @param filter what filter to create an instance of
|
yading@10
|
346 * @param inst_name name to give to the new filter context
|
yading@10
|
347 *
|
yading@10
|
348 * @return newly created filter context or NULL on failure
|
yading@10
|
349 */
|
yading@10
|
350 AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
|
yading@10
|
351
|
yading@10
|
352 /**
|
yading@10
|
353 * Remove a filter from a graph;
|
yading@10
|
354 */
|
yading@10
|
355 void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
|
yading@10
|
356
|
yading@10
|
357 #endif /* AVFILTER_INTERNAL_H */
|