FFmpeg
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 
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  */
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  */
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  */
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  */
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 {
129 
130  /**
131  * Graph the filter belongs to.
132  */
134 
135  /**
136  * Current timestamp of the link, as defined by the most recent
137  * frame(s), in link time_base units.
138  */
140 
141  /**
142  * Current timestamp of the link, as defined by the most recent
143  * frame(s), in AV_TIME_BASE units.
144  */
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  */
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  */
162 
163  /**
164  * Number of past frames sent through the link.
165  */
167 
168  /**
169  * Number of past samples sent through the link.
170  */
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  */
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  */
195 } FilterLink;
196 
198 {
199  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 
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  */
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  */
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  */
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  */
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  */
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  */
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  */
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  */
419  /**
420  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
421  */
423  /**
424  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
425  */
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  */
460 } FFFilter;
461 
462 static inline const FFFilter *fffilter(const AVFilter *f)
463 {
464  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  */
500 
501 /**
502  * Test if a frame is available on the link.
503  * @return >0 if a frame is available
504  */
506 
507 
508 /***
509  * Get the number of samples available on the link.
510  * @return the numer of samples available on the link.
511  */
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  */
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  */
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  */
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  */
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  */
594 
595 /**
596  * Set the status on an input link.
597  * Also discard all frames in the link's FIFO.
598  */
600 
601 /**
602  * Test if a frame is wanted on an output link.
603  */
605 
606 /**
607  * Get the status on an output link.
608  */
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  */
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  */
628 {
630 }
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  */
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  */
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  */
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  */
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  */
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  */
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 
807  void *arg, int *ret, int nb_jobs);
808 
809 #endif /* AVFILTER_FILTERS_H */
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:68
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:475
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_inlink_make_frame_writable
int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
Make sure a frame is writable.
Definition: avfilter.c:1538
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:239
FF_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: filters.h:228
ff_inlink_check_available_samples
int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
Test if enough samples are available on the link.
Definition: avfilter.c:1472
FFFilter::process_command
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:445
ff_inoutlink_check_flow
int ff_inoutlink_check_flow(AVFilterLink *inlink, AVFilterLink *outlink)
Check for flow control between input and output.
Definition: avfilter.c:1625
avfilter_action_func
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:564
ff_filter_process_command
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:901
FFFilter::uninit
void(* uninit)(AVFilterContext *ctx)
Filter uninitialization function.
Definition: filters.h:335
int64_t
long long int64_t
Definition: coverity.c:34
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1667
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:403
w
uint8_t w
Definition: llviddspenc.c:38
FFFilter::query_func2
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:390
FFFilter::priv_size
int priv_size
size of private data to allocate for the filter
Definition: filters.h:429
FF_FILTER_FORMATS_SINGLE_PIXFMT
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
Definition: filters.h:232
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
FFFilter::init
int(* init)(AVFilterContext *ctx)
Filter initialization function.
Definition: filters.h:323
max
#define max(a, b)
Definition: cuda_runtime.h:33
av_pure
#define av_pure
Definition: attributes.h:78
FFFilter::sample_fmt
enum AVSampleFormat sample_fmt
Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
Definition: filters.h:426
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:462
FilterFormatsState
FilterFormatsState
Definition: filters.h:216
FFFilter::formats_state
uint8_t formats_state
This field determines the state of the formats union.
Definition: filters.h:285
ff_inlink_peek_frame
AVFrame * ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
Access a frame in the link fifo without consuming it.
Definition: avfilter.c:1532
pts
static int64_t pts
Definition: transcode_aac.c:644
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
ff_append_outpad
int ff_append_outpad(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:138
AVFilterPad::request_frame
int(* request_frame)(AVFilterLink *link)
Frame request callback.
Definition: filters.h:102
FFFilter
Definition: filters.h:265
ff_outlink_set_status
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:627
FFFilter::samples_list
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:418
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_avfilter_link_set_in_status
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:260
ff_fmt_is_in
int ff_fmt_is_in(int fmt, const int *fmts)
Tell if an integer is contained in the provided -1-terminated list of integers.
Definition: formats.c:406
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
FFFilter::preinit
int(* preinit)(AVFilterContext *ctx)
Filter pre-initialization function.
Definition: filters.h:300
arg
const char * arg
Definition: jacosubdec.c:67
ff_inlink_acknowledge_status
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:1438
FFFilter::formats
union FFFilter::@322 formats
The state of the following union is determined by formats_state.
FFFilter::activate
int(* activate)(AVFilterContext *ctx)
Filter activation function.
Definition: filters.h:459
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFilterPad::filter_frame
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: filters.h:93
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1466
AVFilterGraph
Definition: avfilter.h:581
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:109
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
Definition: filters.h:233
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: filters.h:118
f
f
Definition: af_crystalizer.c:122
FFFilter::nb_outputs
uint8_t nb_outputs
The number of entries in the list of outputs.
Definition: filters.h:279
AVMediaType
AVMediaType
Definition: avutil.h:199
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
ff_inlink_consume_frame
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:1491
FF_FILTER_FORMATS_PASSTHROUGH
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
Definition: filters.h:227
FFFilter::pix_fmt
enum AVPixelFormat pix_fmt
Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
Definition: filters.h:422
ff_filter_init_hw_frames
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:1639
FFFilter::nb_inputs
uint8_t nb_inputs
The number of entries in the list of inputs.
Definition: filters.h:274
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AVFilterPad::flags
int flags
A combination of AVFILTERPAD_FLAG_* flags.
Definition: filters.h:67
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
FFFilter::query_func
int(* query_func)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: filters.h:377
AVFilter
Filter definition.
Definition: avfilter.h:199
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: filters.h:49
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FFFilter::flags_internal
int flags_internal
Additional flags for avfilter internal use only.
Definition: filters.h:431
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:229
ff_append_inpad_free_name
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:132
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_inlink_check_available_frame
int ff_inlink_check_available_frame(AVFilterLink *link)
Test if a frame is available on the link.
Definition: avfilter.c:1460
ff_inlink_queued_frames
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
Definition: avfilter.c:1454
ff_outlink_get_status
int ff_outlink_get_status(AVFilterLink *link)
Get the status on an output link.
Definition: avfilter.c:1619
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1594
avfilter.h
ff_inlink_set_status
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1603
AVFilterContext
An instance of a filter.
Definition: avfilter.h:257
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:269
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_outlink_frame_wanted
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: avfilter.c:1661
FF_FILTER_FORMATS_SAMPLEFMTS_LIST
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
Definition: filters.h:231
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
FFFilter::pixels_list
enum AVPixelFormat * pixels_list
A pointer to an array of admissible pixel formats delimited by AV_PIX_FMT_NONE.
Definition: filters.h:407
ff_inlink_consume_samples
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:1511
h
h
Definition: vp9dsp_template.c:2070
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx) av_pure
Get number of threads for current filter instance.
Definition: avfilter.c:841
ff_append_outpad_free_name
int ff_append_outpad_free_name(AVFilterContext *f, AVFilterPad *p)
Definition: avfilter.c:143
AVFilterPad::get_buffer
union AVFilterPad::@321 get_buffer
Callback functions to get a video/audio buffers.
ff_append_inpad
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
FF_FILTER_FORMATS_PIXFMT_LIST
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Definition: filters.h:230
min
float min
Definition: vorbis_enc_data.h:429