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) ((d) >= INT64_MIN && (d) < (double)INT64_MAX ? (int64_t)(d) : AV_NOPTS_VALUE)
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 * Longest line, in bytes, that ff_filter_log_lines() passes to a single
514 * av_log() call. It leaves room for the log prefix in fixed-size line
515 * buffers such as the 1024-byte one of ffmpeg's -report callback.
516 */
517#define FF_FILTER_LOG_LINE_MAX 896
518
519struct AVBPrint;
520
521/**
522 * Log text built in an AVBPrint with one av_log() call per line, so that
523 * output from other threads cannot land in the middle of a line and every
524 * line gets its own prefix. Lines longer than FF_FILTER_LOG_LINE_MAX bytes
525 * are split before a space if there is one near the limit; no byte is lost.
526 *
527 * If the buffer is incomplete, the text it holds is logged, followed by a
528 * warning.
529 *
530 * @param ctx logging context
531 * @param level log level of the text
532 * @param bp text to log; a missing final newline is supplied
533 */
534void ff_filter_log_lines(void *ctx, int level, const struct AVBPrint *bp);
535
536/**
537 * Get the number of frames available on the link.
538 * @return the number of frames available in the link fifo.
539 */
541
542/**
543 * Test if a frame is available on the link.
544 * @return >0 if a frame is available
545 */
547
548
549/***
550 * Get the number of samples available on the link.
551 * @return the number of samples available on the link.
552 */
554
555/**
556 * Test if enough samples are available on the link.
557 * @return >0 if enough samples are available
558 * @note on EOF and error, min becomes 1
559 */
561
562/**
563 * Take a frame from the link's FIFO and update the link's stats.
564 *
565 * If ff_inlink_check_available_frame() was previously called, the
566 * preferred way of expressing it is "av_assert1(ret);" immediately after
567 * ff_inlink_consume_frame(). Negative error codes must still be checked.
568 *
569 * @note May trigger process_command() and/or update is_disabled.
570 * @return >0 if a frame is available,
571 * 0 and set rframe to NULL if no frame available,
572 * or AVERROR code
573 */
574int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe);
575
576/**
577 * Take samples from the link's FIFO and update the link's stats.
578 *
579 * If ff_inlink_check_available_samples() was previously called, the
580 * preferred way of expressing it is "av_assert1(ret);" immediately after
581 * ff_inlink_consume_samples(). Negative error codes must still be checked.
582 *
583 * @note May trigger process_command() and/or update is_disabled.
584 * @return >0 if a frame is available,
585 * 0 and set rframe to NULL if no frame available,
586 * or AVERROR code
587 */
588int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
589 AVFrame **rframe);
590
591/**
592 * Access a frame in the link fifo without consuming it.
593 * The first frame is numbered 0; the designated frame must exist.
594 * @return the frame at idx position in the link fifo.
595 */
596AVFrame *ff_inlink_peek_frame(AVFilterLink *link, size_t idx);
597
598/**
599 * Check that a video frame has the size and pixel format its link was
600 * configured with.
601 *
602 * @param dynamic_flags FF_FILTER_FLAG_DYNAMIC_* flags of the parameters
603 * allowed to differ
604 * @return 0 if the frame matches, AVERROR(EINVAL) otherwise
605 */
607 int dynamic_flags);
608
609/**
610 * Make sure a frame is writable.
611 * This is similar to av_frame_make_writable() except it uses the link's
612 * buffer allocation callback, and therefore allows direct rendering.
613 */
615
616/**
617 * Test and acknowledge the change of status on the link.
618 *
619 * Status means EOF or an error condition; a change from the normal (0)
620 * status to a non-zero status can be queued in a filter's input link, it
621 * becomes relevant after the frames queued in the link's FIFO are
622 * processed. This function tests if frames are still queued and if a queued
623 * status change has not yet been processed. In that case it performs basic
624 * treatment (updating the link's timestamp) and returns a positive value to
625 * let the filter do its own treatments (flushing...).
626 *
627 * Filters implementing the activate callback should call this function when
628 * they think it might succeed (usually after checking unsuccessfully for a
629 * queued frame).
630 * Filters implementing the filter_frame and request_frame callbacks do not
631 * need to call that since the same treatment happens in ff_filter_frame().
632 *
633 * @param[out] rstatus new or current status
634 * @param[out] rpts current timestamp of the link in link time base
635 * @return >0 if status changed, <0 if status already acked, 0 otherwise
636 */
637int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts);
638
639/**
640 * Mark that a frame is wanted on the link.
641 * Unlike ff_filter_frame(), it must not be called when the link has a
642 * non-zero status, and thus does not acknowledge it.
643 * Also it cannot fail.
644 */
646
647/**
648 * Set the status on an input link.
649 * Also discard all frames in the link's FIFO.
650 */
651void ff_inlink_set_status(AVFilterLink *link, int status);
652
653/**
654 * Test if a frame is wanted on an output link.
655 */
657
658/**
659 * Get the status on an output link.
660 */
662
663/**
664 * Set the status field of a link from the source filter.
665 * The pts should reflect the timestamp of the status change,
666 * in link time base and relative to the frames timeline.
667 * In particular, for AVERROR_EOF, it should reflect the
668 * end time of the last frame.
669 */
671
672/**
673 * Set the status field of a link from the source filter.
674 * The pts should reflect the timestamp of the status change,
675 * in link time base and relative to the frames timeline.
676 * In particular, for AVERROR_EOF, it should reflect the
677 * end time of the last frame.
678 */
679static inline void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
680{
681 ff_avfilter_link_set_in_status(link, status, pts);
682}
683
684/**
685 * Forward the status on an output link to an input link.
686 * If the status is set, it will discard all queued frames and this macro
687 * will return immediately.
688 */
689#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink) do { \
690 int ret = ff_outlink_get_status(outlink); \
691 if (ret) { \
692 ff_inlink_set_status(inlink, ret); \
693 return 0; \
694 } \
695} while (0)
696
697/**
698 * Forward the status on an output link to all input links.
699 * If the status is set, it will discard all queued frames and this macro
700 * will return immediately.
701 */
702#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter) do { \
703 int ret = ff_outlink_get_status(outlink); \
704 if (ret) { \
705 unsigned i; \
706 for (i = 0; i < filter->nb_inputs; i++) \
707 ff_inlink_set_status(filter->inputs[i], ret); \
708 return 0; \
709 } \
710} while (0)
711
712/**
713 * Acknowledge the status on an input link and forward it to an output link.
714 * If the status is set, this macro will return immediately.
715 */
716#define FF_FILTER_FORWARD_STATUS(inlink, outlink) do { \
717 int status; \
718 int64_t pts; \
719 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
720 ff_outlink_set_status(outlink, status, pts); \
721 return 0; \
722 } \
723} while (0)
724
725/**
726 * Acknowledge the status on an input link and forward it to an output link.
727 * If the status is set, this macro will return immediately.
728 */
729#define FF_FILTER_FORWARD_STATUS_ALL(inlink, filter) do { \
730 int status; \
731 int64_t pts; \
732 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { \
733 unsigned i; \
734 for (i = 0; i < filter->nb_outputs; i++) \
735 ff_outlink_set_status(filter->outputs[i], status, pts); \
736 return 0; \
737 } \
738} while (0)
739
740/**
741 * Forward the frame_wanted_out flag from an output link to an input link.
742 * If the flag is set, this macro will return immediately.
743 */
744#define FF_FILTER_FORWARD_WANTED(outlink, inlink) do { \
745 if (ff_outlink_frame_wanted(outlink)) { \
746 ff_inlink_request_frame(inlink); \
747 return 0; \
748 } \
749} while (0)
750
751/**
752 * Forward the frame_wanted_out flag from any of the output links to an input link.
753 * If the flag is set on any of the outputs, this macro will return immediately.
754 */
755#define FF_FILTER_FORWARD_WANTED_ANY(filter, inlink) do { \
756 for (unsigned i = 0; i < filter->nb_outputs; i++) { \
757 if (ff_outlink_frame_wanted(filter->outputs[i])) { \
758 ff_inlink_request_frame(inlink); \
759 return 0; \
760 } \
761 } \
762} while (0)
763
764/**
765 * Check for flow control between input and output.
766 * This is necessary for filters that may produce several output frames for
767 * a single input event, otherwise they may produce them all at once,
768 * causing excessive memory consumption.
769 */
771
772/**
773 * Perform any additional setup required for hardware frames.
774 *
775 * link->hw_frames_ctx must be set before calling this function.
776 * Inside link->hw_frames_ctx, the fields format, sw_format, width and
777 * height must be set. If dynamically allocated pools are not supported,
778 * then initial_pool_size must also be set, to the minimum hardware frame
779 * pool size necessary for the filter to work (taking into account any
780 * frames which need to stored for use in operations as appropriate). If
781 * default_pool_size is nonzero, then it will be used as the pool size if
782 * no other modification takes place (this can be used to preserve
783 * compatibility).
784 */
786 int default_pool_size);
787
788/**
789 * Generic processing of user supplied commands that are set
790 * in the same way as the filter options.
791 * NOTE: 'enable' option is handled separately, and not by
792 * this function.
793 */
794int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
795 const char *arg, char *res, int res_len, int flags);
796
797/**
798 * Get number of threads for current filter instance.
799 * This number is always same or less than graph->nb_threads.
800 */
802
803/**
804 * Compute the boundary index for a slice when work of size total is split
805 * into nb_jobs slices. Returns the first index of slice jobnr, so the slice
806 * jobnr covers [ff_slice_pos(total, jobnr, nb_jobs),
807 * ff_slice_pos(total, jobnr + 1, nb_jobs)).
808 *
809 * The multiplication is performed in 64bit to avoid signed overflow of the
810 * total * jobnr intermediate that would occur for large dimensions and many
811 * slice threads.
812 */
813static inline int ff_slice_pos(int total, int jobnr, int nb_jobs)
814{
815 return (int)((int64_t)total * jobnr / nb_jobs);
816}
817
818/**
819 * Send a frame of data to the next filter.
820 *
821 * @param link the output link over which the data is being sent
822 * @param frame a reference to the buffer of data being sent. The
823 * receiving filter will free this reference when it no longer
824 * needs it or pass it on to the next filter.
825 *
826 * @return >= 0 on success, a negative AVERROR on error. The receiving filter
827 * is responsible for unreferencing frame in case of error.
828 */
830
831/**
832 * Request an input frame from the filter at the other end of the link.
833 *
834 * This function must not be used by filters using the activate callback,
835 * use ff_link_set_frame_wanted() instead.
836 *
837 * The input filter may pass the request on to its inputs, fulfill the
838 * request from an internal buffer or any other means specific to its function.
839 *
840 * When the end of a stream is reached AVERROR_EOF is returned and no further
841 * frames are returned after that.
842 *
843 * When a filter is unable to output a frame for example due to its sources
844 * being unable to do so or because it depends on external means pushing data
845 * into it then AVERROR(EAGAIN) is returned.
846 * It is important that a AVERROR(EAGAIN) return is returned all the way to the
847 * caller (generally eventually a user application) as this step may (but does
848 * not have to be) necessary to provide the input with the next frame.
849 *
850 * If a request is successful then some progress has been made towards
851 * providing a frame on the link (through ff_filter_frame()). A filter that
852 * needs several frames to produce one is allowed to return success if one
853 * more frame has been processed but no output has been produced yet. A
854 * filter is also allowed to simply forward a success return value.
855 *
856 * @param link the input link
857 * @return zero on success
858 * AVERROR_EOF on end of file
859 * AVERROR(EAGAIN) if the previous filter cannot output a frame
860 * currently and can neither guarantee that EOF has been reached.
861 */
863
864/**
865 * Append a new input/output pad to the filter's list of such pads.
866 *
867 * The *_free_name versions will set the AVFILTERPAD_FLAG_FREE_NAME flag
868 * ensuring that the name will be freed generically (even on insertion error).
869 */
874
875/**
876 * Tell if a pixel format is contained in the provided AV_PIX_FMT_NONE-terminated list.
877 *
878 * @param fmt provided format
879 * @param fmts AV_PIX_FMT_NONE-terminated list of pixel formats
880 * @return 1 if present, 0 if absent
881 */
882int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts);
883
885 void *arg, int *ret, int nb_jobs);
886
887#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 ret
Definition ffplay.c:391
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:67
const char * arg
Definition jacosubdec.c:66
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:1712
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:813
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:1690
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition avfilter.c:1706
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:1507
int ff_inlink_check_available_frame(AVFilterLink *link)
Test if a frame is available on the link.
Definition avfilter.c:1529
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
Definition avfilter.c:1541
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1112
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:1748
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:1726
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:950
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:286
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition avfilter.c:1523
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition avfilter.c:525
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:679
void ff_filter_log_lines(void *ctx, int level, const struct AVBPrint *bp)
Log text built in an AVBPrint with one av_log() call per line, so that output from other threads cann...
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1754
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:1580
AVFrame * ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
Access a frame in the link fifo without consuming it.
Definition avfilter.c:1601
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition avfilter.c:232
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition avfilter.c:1623
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:1607
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:1560
int ff_filter_get_nb_threads(AVFilterContext *ctx) av_pure
Get number of threads for current filter instance.
Definition avfilter.c:890
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:1535
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition avfilter.c:1681
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
uint8_t level
Definition svq3.c:208
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
static int64_t pts