FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/filters.h
Date: 2025-01-20 09:27:23
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Filters implementation helper functions
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef AVFILTER_FILTERS_H
22 #define AVFILTER_FILTERS_H
23
24 /**
25 * Filters implementation helper functions and internal structures
26 */
27
28 #include "avfilter.h"
29
30 /**
31 * Special return code when activate() did not do anything.
32 */
33 #define FFERROR_NOT_READY FFERRTAG('N','R','D','Y')
34
35 /**
36 * A filter pad used for either input or output.
37 */
38 struct AVFilterPad {
39 /**
40 * Pad name. The name is unique among inputs and among outputs, but an
41 * input may have the same name as an output. This may be NULL if this
42 * pad has no need to ever be referenced by name.
43 */
44 const char *name;
45
46 /**
47 * AVFilterPad type.
48 */
49 enum AVMediaType type;
50
51 /**
52 * The filter expects writable frames from its input link,
53 * duplicating data buffers if needed.
54 *
55 * input pads only.
56 */
57 #define AVFILTERPAD_FLAG_NEEDS_WRITABLE (1 << 0)
58
59 /**
60 * The pad's name is allocated and should be freed generically.
61 */
62 #define AVFILTERPAD_FLAG_FREE_NAME (1 << 1)
63
64 /**
65 * A combination of AVFILTERPAD_FLAG_* flags.
66 */
67 int flags;
68
69 /**
70 * Callback functions to get a video/audio buffers. If NULL,
71 * the filter system will use ff_default_get_video_buffer() for video
72 * and ff_default_get_audio_buffer() for audio.
73 *
74 * The state of the union is determined by type.
75 *
76 * Input pads only.
77 */
78 union {
79 AVFrame *(*video)(AVFilterLink *link, int w, int h);
80 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
81 } get_buffer;
82
83 /**
84 * Filtering callback. This is where a filter receives a frame with
85 * audio/video data and should do its processing.
86 *
87 * Input pads only.
88 *
89 * @return >= 0 on success, a negative AVERROR on error. This function
90 * must ensure that frame is properly unreferenced on error if it
91 * hasn't been passed on to another filter.
92 */
93 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
94
95 /**
96 * Frame request callback. A call to this should result in some progress
97 * towards producing output over the given link. This should return zero
98 * on success, and another value on error.
99 *
100 * Output pads only.
101 */
102 int (*request_frame)(AVFilterLink *link);
103
104 /**
105 * Link configuration callback.
106 *
107 * For output pads, this should set the link properties such as
108 * width/height. This should NOT set the format property - that is
109 * negotiated between filters by the filter system using the
110 * query_formats() callback before this function is called.
111 *
112 * For input pads, this should check the properties of the link, and update
113 * the filter's internal state as necessary.
114 *
115 * For both input and output filters, this should return zero on success,
116 * and another value on error.
117 */
118 int (*config_props)(AVFilterLink *link);
119 };
120
121 /**
122 * Link properties exposed to filter code, but not external callers.
123 *
124 * Cf. AVFilterLink for public properties, FilterLinkInternal for
125 * properties private to the generic layer.
126 */
127 typedef struct FilterLink {
128 AVFilterLink pub;
129
130 /**
131 * Graph the filter belongs to.
132 */
133 struct AVFilterGraph *graph;
134
135 /**
136 * Current timestamp of the link, as defined by the most recent
137 * frame(s), in link time_base units.
138 */
139 int64_t current_pts;
140
141 /**
142 * Current timestamp of the link, as defined by the most recent
143 * frame(s), in AV_TIME_BASE units.
144 */
145 int64_t current_pts_us;
146
147 /**
148 * Minimum number of samples to filter at once.
149 *
150 * May be set by the link destination filter in its config_props().
151 * If 0, all related fields are ignored.
152 */
153 int min_samples;
154
155 /**
156 * Maximum number of samples to filter at once. If filter_frame() is
157 * called with more samples, it will split them.
158 *
159 * May be set by the link destination filter in its config_props().
160 */
161 int max_samples;
162
163 /**
164 * Number of past frames sent through the link.
165 */
166 int64_t frame_count_in, frame_count_out;
167
168 /**
169 * Number of past samples sent through the link.
170 */
171 int64_t sample_count_in, sample_count_out;
172
173 /**
174 * Frame rate of the stream on the link, or 1/0 if unknown or variable.
175 *
176 * May be set by the link source filter in its config_props(); if left to
177 * 0/0, will be automatically copied from the first input of the source
178 * filter if it exists.
179 *
180 * Sources should set it to the best estimation of the real frame rate.
181 * If the source frame rate is unknown or variable, set this to 1/0.
182 * Filters should update it if necessary depending on their function.
183 * Sinks can use it to set a default output frame rate.
184 * It is similar to the r_frame_rate field in AVStream.
185 */
186 AVRational frame_rate;
187
188 /**
189 * For hwaccel pixel formats, this should be a reference to the
190 * AVHWFramesContext describing the frames.
191 *
192 * May be set by the link source filter in its config_props().
193 */
194 AVBufferRef *hw_frames_ctx;
195 } FilterLink;
196
197 4504760 static inline FilterLink* ff_filter_link(AVFilterLink *link)
198 {
199 4504760 return (FilterLink*)link;
200 }
201
202 /**
203 * The filter is aware of hardware frames, and any hardware frame context
204 * should not be automatically propagated through it.
205 */
206 #define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0)
207
208 /**
209 * Find the index of a link.
210 *
211 * I.e. find i such that link == ctx->(in|out)puts[i]
212 */
213 #define FF_INLINK_IDX(link) ((int)((link)->dstpad - (link)->dst->input_pads))
214 #define FF_OUTLINK_IDX(link) ((int)((link)->srcpad - (link)->src->output_pads))
215
216 enum FilterFormatsState {
217 /**
218 * The default value meaning that this filter supports all formats
219 * and (for audio) sample rates and channel layouts/counts as long
220 * as these properties agree for all inputs and outputs.
221 * This state is only allowed in case all inputs and outputs actually
222 * have the same type.
223 * The union is unused in this state.
224 *
225 * This value must always be zero (for default static initialization).
226 */
227 FF_FILTER_FORMATS_PASSTHROUGH = 0,
228 FF_FILTER_FORMATS_QUERY_FUNC, ///< formats.query active.
229 FF_FILTER_FORMATS_QUERY_FUNC2, ///< formats.query_func2 active.
230 FF_FILTER_FORMATS_PIXFMT_LIST, ///< formats.pixels_list active.
231 FF_FILTER_FORMATS_SAMPLEFMTS_LIST, ///< formats.samples_list active.
232 FF_FILTER_FORMATS_SINGLE_PIXFMT, ///< formats.pix_fmt active
233 FF_FILTER_FORMATS_SINGLE_SAMPLEFMT, ///< formats.sample_fmt active.
234 };
235
236 #define FILTER_QUERY_FUNC(func) \
237 .formats.query_func = func, \
238 .formats_state = FF_FILTER_FORMATS_QUERY_FUNC
239 #define FILTER_QUERY_FUNC2(func) \
240 .formats.query_func2 = func, \
241 .formats_state = FF_FILTER_FORMATS_QUERY_FUNC2
242 #define FILTER_PIXFMTS_ARRAY(array) \
243 .formats.pixels_list = array, \
244 .formats_state = FF_FILTER_FORMATS_PIXFMT_LIST
245 #define FILTER_SAMPLEFMTS_ARRAY(array) \
246 .formats.samples_list = array, \
247 .formats_state = FF_FILTER_FORMATS_SAMPLEFMTS_LIST
248 #define FILTER_PIXFMTS(...) \
249 FILTER_PIXFMTS_ARRAY(((const enum AVPixelFormat []) { __VA_ARGS__, AV_PIX_FMT_NONE }))
250 #define FILTER_SAMPLEFMTS(...) \
251 FILTER_SAMPLEFMTS_ARRAY(((const enum AVSampleFormat[]) { __VA_ARGS__, AV_SAMPLE_FMT_NONE }))
252 #define FILTER_SINGLE_PIXFMT(pix_fmt_) \
253 .formats.pix_fmt = pix_fmt_, \
254 .formats_state = FF_FILTER_FORMATS_SINGLE_PIXFMT
255 #define FILTER_SINGLE_SAMPLEFMT(sample_fmt_) \
256 .formats.sample_fmt = sample_fmt_, \
257 .formats_state = FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
258
259 #define FILTER_INOUTPADS(inout, array) \
260 .p.inout = array, \
261 .nb_ ## inout = FF_ARRAY_ELEMS(array)
262 #define FILTER_INPUTS(array) FILTER_INOUTPADS(inputs, (array))
263 #define FILTER_OUTPUTS(array) FILTER_INOUTPADS(outputs, (array))
264
265 typedef struct FFFilter {
266 /**
267 * The public AVFilter. See avfilter.h for it.
268 */
269 AVFilter p;
270
271 /**
272 * The number of entries in the list of inputs.
273 */
274 uint8_t nb_inputs;
275
276 /**
277 * The number of entries in the list of outputs.
278 */
279 uint8_t nb_outputs;
280
281 /**
282 * This field determines the state of the formats union.
283 * It is an enum FilterFormatsState value.
284 */
285 uint8_t formats_state;
286
287 /**
288 * Filter pre-initialization function
289 *
290 * This callback will be called immediately after the filter context is
291 * allocated, to allow allocating and initing sub-objects.
292 *
293 * If this callback is not NULL, the uninit callback will be called on
294 * allocation failure.
295 *
296 * @return 0 on success,
297 * AVERROR code on failure (but the code will be
298 * dropped and treated as ENOMEM by the calling code)
299 */
300 int (*preinit)(AVFilterContext *ctx);
301
302 /**
303 * Filter initialization function.
304 *
305 * This callback will be called only once during the filter lifetime, after
306 * all the options have been set, but before links between filters are
307 * established and format negotiation is done.
308 *
309 * Basic filter initialization should be done here. Filters with dynamic
310 * inputs and/or outputs should create those inputs/outputs here based on
311 * provided options. No more changes to this filter's inputs/outputs can be
312 * done after this callback.
313 *
314 * This callback must not assume that the filter links exist or frame
315 * parameters are known.
316 *
317 * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
318 * initialization fails, so this callback does not have to clean up on
319 * failure.
320 *
321 * @return 0 on success, a negative AVERROR on failure
322 */
323 int (*init)(AVFilterContext *ctx);
324
325 /**
326 * Filter uninitialization function.
327 *
328 * Called only once right before the filter is freed. Should deallocate any
329 * memory held by the filter, release any buffer references, etc. It does
330 * not need to deallocate the AVFilterContext.priv memory itself.
331 *
332 * This callback may be called even if @ref AVFilter.init "init" was not
333 * called or failed, so it must be prepared to handle such a situation.
334 */
335 void (*uninit)(AVFilterContext *ctx);
336
337 /**
338 * The state of the following union is determined by formats_state.
339 * See the documentation of enum FilterFormatsState in internal.h.
340 */
341 union {
342 /**
343 * Query formats supported by the filter on its inputs and outputs.
344 *
345 * This callback is called after the filter is initialized (so the inputs
346 * and outputs are fixed), shortly before the format negotiation. This
347 * callback may be called more than once.
348 *
349 * This callback must set ::AVFilterLink's
350 * @ref AVFilterFormatsConfig.formats "outcfg.formats"
351 * on every input link and
352 * @ref AVFilterFormatsConfig.formats "incfg.formats"
353 * on every output link to a list of pixel/sample formats that the filter
354 * supports on that link.
355 * For video links, this filter may also set
356 * @ref AVFilterFormatsConfig.color_spaces "incfg.color_spaces"
357 * /
358 * @ref AVFilterFormatsConfig.color_spaces "outcfg.color_spaces"
359 * and @ref AVFilterFormatsConfig.color_ranges "incfg.color_ranges"
360 * /
361 * @ref AVFilterFormatsConfig.color_ranges "outcfg.color_ranges"
362 * analogously.
363 * For audio links, this filter must also set
364 * @ref AVFilterFormatsConfig.samplerates "incfg.samplerates"
365 * /
366 * @ref AVFilterFormatsConfig.samplerates "outcfg.samplerates"
367 * and @ref AVFilterFormatsConfig.channel_layouts "incfg.channel_layouts"
368 * /
369 * @ref AVFilterFormatsConfig.channel_layouts "outcfg.channel_layouts"
370 * analogously.
371 *
372 * This callback must never be NULL if the union is in this state.
373 *
374 * @return zero on success, a negative value corresponding to an
375 * AVERROR code otherwise
376 */
377 int (*query_func)(AVFilterContext *);
378
379 /**
380 * Same as query_func(), except this function writes the results into
381 * provided arrays.
382 *
383 * @param cfg_in array of input format configurations with as many
384 * members as the filters has inputs (NULL when there are
385 * no inputs);
386 * @param cfg_out array of output format configurations with as many
387 * members as the filters has outputs (NULL when there
388 * are no outputs);
389 */
390 int (*query_func2)(const AVFilterContext *,
391 struct AVFilterFormatsConfig **cfg_in,
392 struct AVFilterFormatsConfig **cfg_out);
393 /**
394 * A pointer to an array of admissible pixel formats delimited
395 * by AV_PIX_FMT_NONE. The generic code will use this list
396 * to indicate that this filter supports each of these pixel formats,
397 * provided that all inputs and outputs use the same pixel format.
398 *
399 * In addition to that the generic code will mark all inputs
400 * and all outputs as supporting all color spaces and ranges, as
401 * long as all inputs and outputs use the same color space/range.
402 *
403 * This list must never be NULL if the union is in this state.
404 * The type of all inputs and outputs of filters using this must
405 * be AVMEDIA_TYPE_VIDEO.
406 */
407 const enum AVPixelFormat *pixels_list;
408 /**
409 * Analogous to pixels, but delimited by AV_SAMPLE_FMT_NONE
410 * and restricted to filters that only have AVMEDIA_TYPE_AUDIO
411 * inputs and outputs.
412 *
413 * In addition to that the generic code will mark all inputs
414 * and all outputs as supporting all sample rates and every
415 * channel count and channel layout, as long as all inputs
416 * and outputs use the same sample rate and channel count/layout.
417 */
418 const enum AVSampleFormat *samples_list;
419 /**
420 * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
421 */
422 enum AVPixelFormat pix_fmt;
423 /**
424 * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
425 */
426 enum AVSampleFormat sample_fmt;
427 } formats;
428
429 int priv_size; ///< size of private data to allocate for the filter
430
431 int flags_internal; ///< Additional flags for avfilter internal use only.
432
433 /**
434 * Make the filter instance process a command.
435 *
436 * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
437 * @param arg the argument for the command
438 * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported.
439 * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
440 * time consuming then a filter should treat it like an unsupported command
441 *
442 * @returns >=0 on success otherwise an error code.
443 * AVERROR(ENOSYS) on unsupported commands
444 */
445 int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
446
447 /**
448 * Filter activation function.
449 *
450 * Called when any processing is needed from the filter, instead of any
451 * filter_frame and request_frame on pads.
452 *
453 * The function must examine inlinks and outlinks and perform a single
454 * step of processing. If there is nothing to do, the function must do
455 * nothing and not return an error. If more steps are or may be
456 * possible, it must use ff_filter_set_ready() to schedule another
457 * activation.
458 */
459 int (*activate)(AVFilterContext *ctx);
460 } FFFilter;
461
462 5158829 static inline const FFFilter *fffilter(const AVFilter *f)
463 {
464 5158829 return (const FFFilter*)f;
465 }
466
467
468 #define AVFILTER_DEFINE_CLASS_EXT(name, desc, options) \
469 static const AVClass name##_class = { \
470 .class_name = desc, \
471 .item_name = av_default_item_name, \
472 .option = options, \
473 .version = LIBAVUTIL_VERSION_INT, \
474 .category = AV_CLASS_CATEGORY_FILTER, \
475 }
476 #define AVFILTER_DEFINE_CLASS(fname) \
477 AVFILTER_DEFINE_CLASS_EXT(fname, #fname, fname##_options)
478
479 #define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
480 #define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
481 #define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts) * av_q2d(tb))
482
483 /**
484 * Mark a filter ready and schedule it for activation.
485 *
486 * This is automatically done when something happens to the filter (queued
487 * frame, status change, request on output).
488 * Filters implementing the activate callback can call it directly to
489 * perform one more round of processing later.
490 * It is also useful for filters reacting to external or asynchronous
491 * events.
492 */
493 void ff_filter_set_ready(AVFilterContext *filter, unsigned priority);
494
495 /**
496 * Get the number of frames available on the link.
497 * @return the number of frames available in the link fifo.
498 */
499 size_t ff_inlink_queued_frames(AVFilterLink *link);
500
501 /**
502 * Test if a frame is available on the link.
503 * @return >0 if a frame is available
504 */
505 int ff_inlink_check_available_frame(AVFilterLink *link);
506
507
508 /***
509 * Get the number of samples available on the link.
510 * @return the numer of samples available on the link.
511 */
512 int ff_inlink_queued_samples(AVFilterLink *link);
513
514 /**
515 * Test if enough samples are available on the link.
516 * @return >0 if enough samples are available
517 * @note on EOF and error, min becomes 1
518 */
519 int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min);
520
521 /**
522 * Take a frame from the link's FIFO and update the link's stats.
523 *
524 * If ff_inlink_check_available_frame() was previously called, the
525 * preferred way of expressing it is "av_assert1(ret);" immediately after
526 * ff_inlink_consume_frame(). Negative error codes must still be checked.
527 *
528 * @note May trigger process_command() and/or update is_disabled.
529 * @return >0 if a frame is available,
530 * 0 and set rframe to NULL if no frame available,
531 * or AVERROR code
532 */
533 int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe);
534
535 /**
536 * Take samples from the link's FIFO and update the link's stats.
537 *
538 * If ff_inlink_check_available_samples() was previously called, the
539 * preferred way of expressing it is "av_assert1(ret);" immediately after
540 * ff_inlink_consume_samples(). Negative error codes must still be checked.
541 *
542 * @note May trigger process_command() and/or update is_disabled.
543 * @return >0 if a frame is available,
544 * 0 and set rframe to NULL if no frame available,
545 * or AVERROR code
546 */
547 int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
548 AVFrame **rframe);
549
550 /**
551 * Access a frame in the link fifo without consuming it.
552 * The first frame is numbered 0; the designated frame must exist.
553 * @return the frame at idx position in the link fifo.
554 */
555 AVFrame *ff_inlink_peek_frame(AVFilterLink *link, size_t idx);
556
557 /**
558 * Make sure a frame is writable.
559 * This is similar to av_frame_make_writable() except it uses the link's
560 * buffer allocation callback, and therefore allows direct rendering.
561 */
562 int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe);
563
564 /**
565 * Test and acknowledge the change of status on the link.
566 *
567 * Status means EOF or an error condition; a change from the normal (0)
568 * status to a non-zero status can be queued in a filter's input link, it
569 * becomes relevant after the frames queued in the link's FIFO are
570 * processed. This function tests if frames are still queued and if a queued
571 * status change has not yet been processed. In that case it performs basic
572 * treatment (updating the link's timestamp) and returns a positive value to
573 * let the filter do its own treatments (flushing...).
574 *
575 * Filters implementing the activate callback should call this function when
576 * they think it might succeed (usually after checking unsuccessfully for a
577 * queued frame).
578 * Filters implementing the filter_frame and request_frame callbacks do not
579 * need to call that since the same treatment happens in ff_filter_frame().
580 *
581 * @param[out] rstatus new or current status
582 * @param[out] rpts current timestamp of the link in link time base
583 * @return >0 if status changed, <0 if status already acked, 0 otherwise
584 */
585 int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts);
586
587 /**
588 * Mark that a frame is wanted on the link.
589 * Unlike ff_filter_frame(), it must not be called when the link has a
590 * non-zero status, and thus does not acknowledge it.
591 * Also it cannot fail.
592 */
593 void ff_inlink_request_frame(AVFilterLink *link);
594
595 /**
596 * Set the status on an input link.
597 * Also discard all frames in the link's FIFO.
598 */
599 void ff_inlink_set_status(AVFilterLink *link, int status);
600
601 /**
602 * Test if a frame is wanted on an output link.
603 */
604 int ff_outlink_frame_wanted(AVFilterLink *link);
605
606 /**
607 * Get the status on an output link.
608 */
609 int ff_outlink_get_status(AVFilterLink *link);
610
611 /**
612 * Set the status field of a link from the source filter.
613 * The pts should reflect the timestamp of the status change,
614 * in link time base and relative to the frames timeline.
615 * In particular, for AVERROR_EOF, it should reflect the
616 * end time of the last frame.
617 */
618 void ff_avfilter_link_set_in_status(AVFilterLink *link, int status, int64_t pts);
619
620 /**
621 * Set the status field of a link from the source filter.
622 * The pts should reflect the timestamp of the status change,
623 * in link time base and relative to the frames timeline.
624 * In particular, for AVERROR_EOF, it should reflect the
625 * end time of the last frame.
626 */
627 7987 static inline void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
628 {
629 7987 ff_avfilter_link_set_in_status(link, status, pts);
630 7987 }
631
632 /**
633 * Forward the status on an output link to an input link.
634 * If the status is set, it will discard all queued frames and this macro
635 * will return immediately.
636 */
637 #define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink) do { \
638 int ret = ff_outlink_get_status(outlink); \
639 if (ret) { \
640 ff_inlink_set_status(inlink, ret); \
641 return 0; \
642 } \
643 } while (0)
644
645 /**
646 * Forward the status on an output link to all input links.
647 * If the status is set, it will discard all queued frames and this macro
648 * will return immediately.
649 */
650 #define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter) do { \
651 int ret = ff_outlink_get_status(outlink); \
652 if (ret) { \
653 unsigned i; \
654 for (i = 0; i < filter->nb_inputs; i++) \
655 ff_inlink_set_status(filter->inputs[i], ret); \
656 return 0; \
657 } \
658 } while (0)
659
660 /**
661 * Acknowledge the status on an input link and forward it to an output link.
662 * If the status is set, this macro will return immediately.
663 */
664 #define FF_FILTER_FORWARD_STATUS(inlink, outlink) do { \
665 int status; \
666 int64_t pts; \
667 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
668 ff_outlink_set_status(outlink, status, pts); \
669 return 0; \
670 } \
671 } while (0)
672
673 /**
674 * Acknowledge the status on an input link and forward it to an output link.
675 * If the status is set, this macro will return immediately.
676 */
677 #define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter) do { \
678 int status; \
679 int64_t pts; \
680 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
681 unsigned i; \
682 for (i = 0; i < filter->nb_outputs; i++) \
683 ff_outlink_set_status(filter->outputs[i], status, pts); \
684 return 0; \
685 } \
686 } while (0)
687
688 /**
689 * Forward the frame_wanted_out flag from an output link to an input link.
690 * If the flag is set, this macro will return immediately.
691 */
692 #define FF_FILTER_FORWARD_WANTED(outlink, inlink) do { \
693 if (ff_outlink_frame_wanted(outlink)) { \
694 ff_inlink_request_frame(inlink); \
695 return 0; \
696 } \
697 } while (0)
698
699 /**
700 * Check for flow control between input and output.
701 * This is necessary for filters that may produce several output frames for
702 * a single input event, otherwise they may produce them all at once,
703 * causing excessive memory consumption.
704 */
705 int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink);
706
707 /**
708 * Perform any additional setup required for hardware frames.
709 *
710 * link->hw_frames_ctx must be set before calling this function.
711 * Inside link->hw_frames_ctx, the fields format, sw_format, width and
712 * height must be set. If dynamically allocated pools are not supported,
713 * then initial_pool_size must also be set, to the minimum hardware frame
714 * pool size necessary for the filter to work (taking into account any
715 * frames which need to stored for use in operations as appropriate). If
716 * default_pool_size is nonzero, then it will be used as the pool size if
717 * no other modification takes place (this can be used to preserve
718 * compatibility).
719 */
720 int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
721 int default_pool_size);
722
723 /**
724 * Generic processing of user supplied commands that are set
725 * in the same way as the filter options.
726 * NOTE: 'enable' option is handled separately, and not by
727 * this function.
728 */
729 int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
730 const char *arg, char *res, int res_len, int flags);
731
732 /**
733 * Get number of threads for current filter instance.
734 * This number is always same or less than graph->nb_threads.
735 */
736 int ff_filter_get_nb_threads(AVFilterContext *ctx) av_pure;
737
738 /**
739 * Send a frame of data to the next filter.
740 *
741 * @param link the output link over which the data is being sent
742 * @param frame a reference to the buffer of data being sent. The
743 * receiving filter will free this reference when it no longer
744 * needs it or pass it on to the next filter.
745 *
746 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
747 * is responsible for unreferencing frame in case of error.
748 */
749 int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
750
751 /**
752 * Request an input frame from the filter at the other end of the link.
753 *
754 * This function must not be used by filters using the activate callback,
755 * use ff_link_set_frame_wanted() instead.
756 *
757 * The input filter may pass the request on to its inputs, fulfill the
758 * request from an internal buffer or any other means specific to its function.
759 *
760 * When the end of a stream is reached AVERROR_EOF is returned and no further
761 * frames are returned after that.
762 *
763 * When a filter is unable to output a frame for example due to its sources
764 * being unable to do so or because it depends on external means pushing data
765 * into it then AVERROR(EAGAIN) is returned.
766 * It is important that a AVERROR(EAGAIN) return is returned all the way to the
767 * caller (generally eventually a user application) as this step may (but does
768 * not have to be) necessary to provide the input with the next frame.
769 *
770 * If a request is successful then some progress has been made towards
771 * providing a frame on the link (through ff_filter_frame()). A filter that
772 * needs several frames to produce one is allowed to return success if one
773 * more frame has been processed but no output has been produced yet. A
774 * filter is also allowed to simply forward a success return value.
775 *
776 * @param link the input link
777 * @return zero on success
778 * AVERROR_EOF on end of file
779 * AVERROR(EAGAIN) if the previous filter cannot output a frame
780 * currently and can neither guarantee that EOF has been reached.
781 */
782 int ff_request_frame(AVFilterLink *link);
783
784 /**
785 * Append a new input/output pad to the filter's list of such pads.
786 *
787 * The *_free_name versions will set the AVFILTERPAD_FLAG_FREE_NAME flag
788 * ensuring that the name will be freed generically (even on insertion error).
789 */
790 int ff_append_inpad (AVFilterContext *f, AVFilterPad *p);
791 int ff_append_outpad(AVFilterContext *f, AVFilterPad *p);
792 int ff_append_inpad_free_name (AVFilterContext *f, AVFilterPad *p);
793 int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p);
794
795 /**
796 * Tell if an integer is contained in the provided -1-terminated list of integers.
797 * This is useful for determining (for instance) if an AVPixelFormat is in an
798 * array of supported formats.
799 *
800 * @param fmt provided format
801 * @param fmts -1-terminated list of formats
802 * @return 1 if present, 0 if absent
803 */
804 int ff_fmt_is_in(int fmt, const int *fmts);
805
806 int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func,
807 void *arg, int *ret, int nb_jobs);
808
809 #endif /* AVFILTER_FILTERS_H */
810