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