]> git.sesse.net Git - ffmpeg/blob - libavfilter/avfilter.h
lavfi doxy: add buffer{src,sink}.h to the main lavfi doxy group
[ffmpeg] / libavfilter / avfilter.h
1 /*
2  * filter layer
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #ifndef AVFILTER_AVFILTER_H
23 #define AVFILTER_AVFILTER_H
24
25 /**
26  * @file
27  * @ingroup lavfi
28  * Main libavfilter public API header
29  */
30
31 /**
32  * @defgroup lavfi Libavfilter - graph-based frame editing library
33  * @{
34  */
35
36 #include "libavutil/attributes.h"
37 #include "libavutil/avutil.h"
38 #include "libavutil/frame.h"
39 #include "libavutil/log.h"
40 #include "libavutil/samplefmt.h"
41 #include "libavutil/pixfmt.h"
42 #include "libavutil/rational.h"
43 #include "libavcodec/avcodec.h"
44
45 #include <stddef.h>
46
47 #include "libavfilter/version.h"
48
49 /**
50  * Return the LIBAVFILTER_VERSION_INT constant.
51  */
52 unsigned avfilter_version(void);
53
54 /**
55  * Return the libavfilter build-time configuration.
56  */
57 const char *avfilter_configuration(void);
58
59 /**
60  * Return the libavfilter license.
61  */
62 const char *avfilter_license(void);
63
64
65 typedef struct AVFilterContext AVFilterContext;
66 typedef struct AVFilterLink    AVFilterLink;
67 typedef struct AVFilterPad     AVFilterPad;
68 typedef struct AVFilterFormats AVFilterFormats;
69
70 #if FF_API_AVFILTERBUFFER
71 /**
72  * A reference-counted buffer data type used by the filter system. Filters
73  * should not store pointers to this structure directly, but instead use the
74  * AVFilterBufferRef structure below.
75  */
76 typedef struct AVFilterBuffer {
77     uint8_t *data[8];           ///< buffer data for each plane/channel
78
79     /**
80      * pointers to the data planes/channels.
81      *
82      * For video, this should simply point to data[].
83      *
84      * For planar audio, each channel has a separate data pointer, and
85      * linesize[0] contains the size of each channel buffer.
86      * For packed audio, there is just one data pointer, and linesize[0]
87      * contains the total size of the buffer for all channels.
88      *
89      * Note: Both data and extended_data will always be set, but for planar
90      * audio with more channels that can fit in data, extended_data must be used
91      * in order to access all channels.
92      */
93     uint8_t **extended_data;
94     int linesize[8];            ///< number of bytes per line
95
96     /** private data to be used by a custom free function */
97     void *priv;
98     /**
99      * A pointer to the function to deallocate this buffer if the default
100      * function is not sufficient. This could, for example, add the memory
101      * back into a memory pool to be reused later without the overhead of
102      * reallocating it from scratch.
103      */
104     void (*free)(struct AVFilterBuffer *buf);
105
106     int format;                 ///< media format
107     int w, h;                   ///< width and height of the allocated buffer
108     unsigned refcount;          ///< number of references to this buffer
109 } AVFilterBuffer;
110
111 #define AV_PERM_READ     0x01   ///< can read from the buffer
112 #define AV_PERM_WRITE    0x02   ///< can write to the buffer
113 #define AV_PERM_PRESERVE 0x04   ///< nobody else can overwrite the buffer
114 #define AV_PERM_REUSE    0x08   ///< can output the buffer multiple times, with the same contents each time
115 #define AV_PERM_REUSE2   0x10   ///< can output the buffer multiple times, modified each time
116 #define AV_PERM_NEG_LINESIZES 0x20  ///< the buffer requested can have negative linesizes
117
118 /**
119  * Audio specific properties in a reference to an AVFilterBuffer. Since
120  * AVFilterBufferRef is common to different media formats, audio specific
121  * per reference properties must be separated out.
122  */
123 typedef struct AVFilterBufferRefAudioProps {
124     uint64_t channel_layout;    ///< channel layout of audio buffer
125     int nb_samples;             ///< number of audio samples
126     int sample_rate;            ///< audio buffer sample rate
127     int planar;                 ///< audio buffer - planar or packed
128 } AVFilterBufferRefAudioProps;
129
130 /**
131  * Video specific properties in a reference to an AVFilterBuffer. Since
132  * AVFilterBufferRef is common to different media formats, video specific
133  * per reference properties must be separated out.
134  */
135 typedef struct AVFilterBufferRefVideoProps {
136     int w;                      ///< image width
137     int h;                      ///< image height
138     AVRational pixel_aspect;    ///< pixel aspect ratio
139     int interlaced;             ///< is frame interlaced
140     int top_field_first;        ///< field order
141     enum AVPictureType pict_type; ///< picture type of the frame
142     int key_frame;              ///< 1 -> keyframe, 0-> not
143 } AVFilterBufferRefVideoProps;
144
145 /**
146  * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
147  * a buffer to, for example, crop image without any memcpy, the buffer origin
148  * and dimensions are per-reference properties. Linesize is also useful for
149  * image flipping, frame to field filters, etc, and so is also per-reference.
150  *
151  * TODO: add anything necessary for frame reordering
152  */
153 typedef struct AVFilterBufferRef {
154     AVFilterBuffer *buf;        ///< the buffer that this is a reference to
155     uint8_t *data[8];           ///< picture/audio data for each plane
156     /**
157      * pointers to the data planes/channels.
158      *
159      * For video, this should simply point to data[].
160      *
161      * For planar audio, each channel has a separate data pointer, and
162      * linesize[0] contains the size of each channel buffer.
163      * For packed audio, there is just one data pointer, and linesize[0]
164      * contains the total size of the buffer for all channels.
165      *
166      * Note: Both data and extended_data will always be set, but for planar
167      * audio with more channels that can fit in data, extended_data must be used
168      * in order to access all channels.
169      */
170     uint8_t **extended_data;
171     int linesize[8];            ///< number of bytes per line
172
173     AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
174     AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
175
176     /**
177      * presentation timestamp. The time unit may change during
178      * filtering, as it is specified in the link and the filter code
179      * may need to rescale the PTS accordingly.
180      */
181     int64_t pts;
182     int64_t pos;                ///< byte position in stream, -1 if unknown
183
184     int format;                 ///< media format
185
186     int perms;                  ///< permissions, see the AV_PERM_* flags
187
188     enum AVMediaType type;      ///< media type of buffer data
189 } AVFilterBufferRef;
190
191 /**
192  * Copy properties of src to dst, without copying the actual data
193  */
194 attribute_deprecated
195 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
196
197 /**
198  * Add a new reference to a buffer.
199  *
200  * @param ref   an existing reference to the buffer
201  * @param pmask a bitmask containing the allowable permissions in the new
202  *              reference
203  * @return      a new reference to the buffer with the same properties as the
204  *              old, excluding any permissions denied by pmask
205  */
206 attribute_deprecated
207 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
208
209 /**
210  * Remove a reference to a buffer. If this is the last reference to the
211  * buffer, the buffer itself is also automatically freed.
212  *
213  * @param ref reference to the buffer, may be NULL
214  *
215  * @note it is recommended to use avfilter_unref_bufferp() instead of this
216  * function
217  */
218 attribute_deprecated
219 void avfilter_unref_buffer(AVFilterBufferRef *ref);
220
221 /**
222  * Remove a reference to a buffer and set the pointer to NULL.
223  * If this is the last reference to the buffer, the buffer itself
224  * is also automatically freed.
225  *
226  * @param ref pointer to the buffer reference
227  */
228 attribute_deprecated
229 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
230 #endif
231
232 #if FF_API_AVFILTERPAD_PUBLIC
233 /**
234  * A filter pad used for either input or output.
235  *
236  * @warning this struct will be removed from public API.
237  * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
238  * to access the name and type fields; there should be no need to access
239  * any other fields from outside of libavfilter.
240  */
241 struct AVFilterPad {
242     /**
243      * Pad name. The name is unique among inputs and among outputs, but an
244      * input may have the same name as an output. This may be NULL if this
245      * pad has no need to ever be referenced by name.
246      */
247     const char *name;
248
249     /**
250      * AVFilterPad type.
251      */
252     enum AVMediaType type;
253
254     /**
255      * Minimum required permissions on incoming buffers. Any buffer with
256      * insufficient permissions will be automatically copied by the filter
257      * system to a new buffer which provides the needed access permissions.
258      *
259      * Input pads only.
260      */
261     attribute_deprecated int min_perms;
262
263     /**
264      * Permissions which are not accepted on incoming buffers. Any buffer
265      * which has any of these permissions set will be automatically copied
266      * by the filter system to a new buffer which does not have those
267      * permissions. This can be used to easily disallow buffers with
268      * AV_PERM_REUSE.
269      *
270      * Input pads only.
271      */
272     attribute_deprecated int rej_perms;
273
274     /**
275      * @deprecated unused
276      */
277     int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
278
279     /**
280      * Callback function to get a video buffer. If NULL, the filter system will
281      * use avfilter_default_get_video_buffer().
282      *
283      * Input video pads only.
284      */
285     AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
286
287     /**
288      * Callback function to get an audio buffer. If NULL, the filter system will
289      * use avfilter_default_get_audio_buffer().
290      *
291      * Input audio pads only.
292      */
293     AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
294
295     /**
296      * @deprecated unused
297      */
298     int (*end_frame)(AVFilterLink *link);
299
300     /**
301      * @deprecated unused
302      */
303     int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
304
305     /**
306      * Filtering callback. This is where a filter receives a frame with
307      * audio/video data and should do its processing.
308      *
309      * Input pads only.
310      *
311      * @return >= 0 on success, a negative AVERROR on error. This function
312      * must ensure that samplesref is properly unreferenced on error if it
313      * hasn't been passed on to another filter.
314      */
315     int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
316
317     /**
318      * Frame poll callback. This returns the number of immediately available
319      * samples. It should return a positive value if the next request_frame()
320      * is guaranteed to return one frame (with no delay).
321      *
322      * Defaults to just calling the source poll_frame() method.
323      *
324      * Output pads only.
325      */
326     int (*poll_frame)(AVFilterLink *link);
327
328     /**
329      * Frame request callback. A call to this should result in at least one
330      * frame being output over the given link. This should return zero on
331      * success, and another value on error.
332      *
333      * Output pads only.
334      */
335     int (*request_frame)(AVFilterLink *link);
336
337     /**
338      * Link configuration callback.
339      *
340      * For output pads, this should set the link properties such as
341      * width/height. This should NOT set the format property - that is
342      * negotiated between filters by the filter system using the
343      * query_formats() callback before this function is called.
344      *
345      * For input pads, this should check the properties of the link, and update
346      * the filter's internal state as necessary.
347      *
348      * For both input and output filters, this should return zero on success,
349      * and another value on error.
350      */
351     int (*config_props)(AVFilterLink *link);
352
353     /**
354      * The filter expects a fifo to be inserted on its input link,
355      * typically because it has a delay.
356      *
357      * input pads only.
358      */
359     int needs_fifo;
360
361     /**
362      * The filter expects writable frames from its input link,
363      * duplicating data buffers if needed.
364      *
365      * input pads only.
366      */
367     int needs_writable;
368 };
369 #endif
370
371 /**
372  * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
373  * AVFilter.inputs/outputs).
374  */
375 int avfilter_pad_count(const AVFilterPad *pads);
376
377 /**
378  * Get the name of an AVFilterPad.
379  *
380  * @param pads an array of AVFilterPads
381  * @param pad_idx index of the pad in the array it; is the caller's
382  *                responsibility to ensure the index is valid
383  *
384  * @return name of the pad_idx'th pad in pads
385  */
386 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
387
388 /**
389  * Get the type of an AVFilterPad.
390  *
391  * @param pads an array of AVFilterPads
392  * @param pad_idx index of the pad in the array; it is the caller's
393  *                responsibility to ensure the index is valid
394  *
395  * @return type of the pad_idx'th pad in pads
396  */
397 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
398
399 /**
400  * The number of the filter inputs is not determined just by AVFilter.inputs.
401  * The filter might add additional inputs during initialization depending on the
402  * options supplied to it.
403  */
404 #define AVFILTER_FLAG_DYNAMIC_INPUTS        (1 << 0)
405 /**
406  * The number of the filter outputs is not determined just by AVFilter.outputs.
407  * The filter might add additional outputs during initialization depending on
408  * the options supplied to it.
409  */
410 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS       (1 << 1)
411 /**
412  * The filter supports multithreading by splitting frames into multiple parts
413  * and processing them concurrently.
414  */
415 #define AVFILTER_FLAG_SLICE_THREADS         (1 << 2)
416
417 /**
418  * Filter definition. This defines the pads a filter contains, and all the
419  * callback functions used to interact with the filter.
420  */
421 typedef struct AVFilter {
422     /**
423      * Filter name. Must be non-NULL and unique among filters.
424      */
425     const char *name;
426
427     /**
428      * A description of the filter. May be NULL.
429      *
430      * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
431      */
432     const char *description;
433
434     /**
435      * List of inputs, terminated by a zeroed element.
436      *
437      * NULL if there are no (static) inputs. Instances of filters with
438      * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
439      * this list.
440      */
441     const AVFilterPad *inputs;
442     /**
443      * List of outputs, terminated by a zeroed element.
444      *
445      * NULL if there are no (static) outputs. Instances of filters with
446      * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
447      * this list.
448      */
449     const AVFilterPad *outputs;
450
451     /**
452      * A class for the private data, used to declare filter private AVOptions.
453      * This field is NULL for filters that do not declare any options.
454      *
455      * If this field is non-NULL, the first member of the filter private data
456      * must be a pointer to AVClass, which will be set by libavfilter generic
457      * code to this class.
458      */
459     const AVClass *priv_class;
460
461     /**
462      * A combination of AVFILTER_FLAG_*
463      */
464     int flags;
465
466     /*****************************************************************
467      * All fields below this line are not part of the public API. They
468      * may not be used outside of libavfilter and can be changed and
469      * removed at will.
470      * New public fields should be added right above.
471      *****************************************************************
472      */
473
474     /**
475      * Filter initialization function.
476      *
477      * This callback will be called only once during the filter lifetime, after
478      * all the options have been set, but before links between filters are
479      * established and format negotiation is done.
480      *
481      * Basic filter initialization should be done here. Filters with dynamic
482      * inputs and/or outputs should create those inputs/outputs here based on
483      * provided options. No more changes to this filter's inputs/outputs can be
484      * done after this callback.
485      *
486      * This callback must not assume that the filter links exist or frame
487      * parameters are known.
488      *
489      * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
490      * initialization fails, so this callback does not have to clean up on
491      * failure.
492      *
493      * @return 0 on success, a negative AVERROR on failure
494      */
495     int (*init)(AVFilterContext *ctx);
496
497     /**
498      * Should be set instead of @ref AVFilter.init "init" by the filters that
499      * want to pass a dictionary of AVOptions to nested contexts that are
500      * allocated during init.
501      *
502      * On return, the options dict should be freed and replaced with one that
503      * contains all the options which could not be processed by this filter (or
504      * with NULL if all the options were processed).
505      *
506      * Otherwise the semantics is the same as for @ref AVFilter.init "init".
507      */
508     int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
509
510     /**
511      * Filter uninitialization function.
512      *
513      * Called only once right before the filter is freed. Should deallocate any
514      * memory held by the filter, release any buffer references, etc. It does
515      * not need to deallocate the AVFilterContext.priv memory itself.
516      *
517      * This callback may be called even if @ref AVFilter.init "init" was not
518      * called or failed, so it must be prepared to handle such a situation.
519      */
520     void (*uninit)(AVFilterContext *ctx);
521
522     /**
523      * Query formats supported by the filter on its inputs and outputs.
524      *
525      * This callback is called after the filter is initialized (so the inputs
526      * and outputs are fixed), shortly before the format negotiation. This
527      * callback may be called more than once.
528      *
529      * This callback must set AVFilterLink.out_formats on every input link and
530      * AVFilterLink.in_formats on every output link to a list of pixel/sample
531      * formats that the filter supports on that link. For audio links, this
532      * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
533      * @ref AVFilterLink.out_samplerates "out_samplerates" and
534      * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
535      * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
536      *
537      * This callback may be NULL for filters with one input, in which case
538      * libavfilter assumes that it supports all input formats and preserves
539      * them on output.
540      *
541      * @return zero on success, a negative value corresponding to an
542      * AVERROR code otherwise
543      */
544     int (*query_formats)(AVFilterContext *);
545
546     int priv_size;      ///< size of private data to allocate for the filter
547
548     /**
549      * Used by the filter registration system. Must not be touched by any other
550      * code.
551      */
552     struct AVFilter *next;
553 } AVFilter;
554
555 /**
556  * Process multiple parts of the frame concurrently.
557  */
558 #define AVFILTER_THREAD_SLICE (1 << 0)
559
560 typedef struct AVFilterInternal AVFilterInternal;
561
562 /** An instance of a filter */
563 struct AVFilterContext {
564     const AVClass *av_class;              ///< needed for av_log()
565
566     const AVFilter *filter;         ///< the AVFilter of which this is an instance
567
568     char *name;                     ///< name of this filter instance
569
570     AVFilterPad   *input_pads;      ///< array of input pads
571     AVFilterLink **inputs;          ///< array of pointers to input links
572 #if FF_API_FOO_COUNT
573     attribute_deprecated unsigned input_count; ///< @deprecated use nb_inputs
574 #endif
575     unsigned    nb_inputs;          ///< number of input pads
576
577     AVFilterPad   *output_pads;     ///< array of output pads
578     AVFilterLink **outputs;         ///< array of pointers to output links
579 #if FF_API_FOO_COUNT
580     attribute_deprecated unsigned output_count; ///< @deprecated use nb_outputs
581 #endif
582     unsigned    nb_outputs;         ///< number of output pads
583
584     void *priv;                     ///< private data for use by the filter
585
586     struct AVFilterGraph *graph;    ///< filtergraph this filter belongs to
587
588     /**
589      * Type of multithreading being allowed/used. A combination of
590      * AVFILTER_THREAD_* flags.
591      *
592      * May be set by the caller before initializing the filter to forbid some
593      * or all kinds of multithreading for this filter. The default is allowing
594      * everything.
595      *
596      * When the filter is initialized, this field is combined using bit AND with
597      * AVFilterGraph.thread_type to get the final mask used for determining
598      * allowed threading types. I.e. a threading type needs to be set in both
599      * to be allowed.
600      *
601      * After the filter is initialzed, libavfilter sets this field to the
602      * threading type that is actually used (0 for no multithreading).
603      */
604     int thread_type;
605
606     /**
607      * An opaque struct for libavfilter internal use.
608      */
609     AVFilterInternal *internal;
610 };
611
612 /**
613  * A link between two filters. This contains pointers to the source and
614  * destination filters between which this link exists, and the indexes of
615  * the pads involved. In addition, this link also contains the parameters
616  * which have been negotiated and agreed upon between the filter, such as
617  * image dimensions, format, etc.
618  */
619 struct AVFilterLink {
620     AVFilterContext *src;       ///< source filter
621     AVFilterPad *srcpad;        ///< output pad on the source filter
622
623     AVFilterContext *dst;       ///< dest filter
624     AVFilterPad *dstpad;        ///< input pad on the dest filter
625
626     enum AVMediaType type;      ///< filter media type
627
628     /* These parameters apply only to video */
629     int w;                      ///< agreed upon image width
630     int h;                      ///< agreed upon image height
631     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
632     /* These two parameters apply only to audio */
633     uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
634     int sample_rate;            ///< samples per second
635
636     int format;                 ///< agreed upon media format
637
638     /**
639      * Define the time base used by the PTS of the frames/samples
640      * which will pass through this link.
641      * During the configuration stage, each filter is supposed to
642      * change only the output timebase, while the timebase of the
643      * input link is assumed to be an unchangeable property.
644      */
645     AVRational time_base;
646
647     /*****************************************************************
648      * All fields below this line are not part of the public API. They
649      * may not be used outside of libavfilter and can be changed and
650      * removed at will.
651      * New public fields should be added right above.
652      *****************************************************************
653      */
654     /**
655      * Lists of formats supported by the input and output filters respectively.
656      * These lists are used for negotiating the format to actually be used,
657      * which will be loaded into the format member, above, when chosen.
658      */
659     AVFilterFormats *in_formats;
660     AVFilterFormats *out_formats;
661
662     /**
663      * Lists of channel layouts and sample rates used for automatic
664      * negotiation.
665      */
666     AVFilterFormats  *in_samplerates;
667     AVFilterFormats *out_samplerates;
668     struct AVFilterChannelLayouts  *in_channel_layouts;
669     struct AVFilterChannelLayouts *out_channel_layouts;
670
671     /**
672      * Audio only, the destination filter sets this to a non-zero value to
673      * request that buffers with the given number of samples should be sent to
674      * it. AVFilterPad.needs_fifo must also be set on the corresponding input
675      * pad.
676      * Last buffer before EOF will be padded with silence.
677      */
678     int request_samples;
679
680     /** stage of the initialization of the link properties (dimensions, etc) */
681     enum {
682         AVLINK_UNINIT = 0,      ///< not started
683         AVLINK_STARTINIT,       ///< started, but incomplete
684         AVLINK_INIT             ///< complete
685     } init_state;
686 };
687
688 /**
689  * Link two filters together.
690  *
691  * @param src    the source filter
692  * @param srcpad index of the output pad on the source filter
693  * @param dst    the destination filter
694  * @param dstpad index of the input pad on the destination filter
695  * @return       zero on success
696  */
697 int avfilter_link(AVFilterContext *src, unsigned srcpad,
698                   AVFilterContext *dst, unsigned dstpad);
699
700 /**
701  * Negotiate the media format, dimensions, etc of all inputs to a filter.
702  *
703  * @param filter the filter to negotiate the properties for its inputs
704  * @return       zero on successful negotiation
705  */
706 int avfilter_config_links(AVFilterContext *filter);
707
708 #if FF_API_AVFILTERBUFFER
709 /**
710  * Create a buffer reference wrapped around an already allocated image
711  * buffer.
712  *
713  * @param data pointers to the planes of the image to reference
714  * @param linesize linesizes for the planes of the image to reference
715  * @param perms the required access permissions
716  * @param w the width of the image specified by the data and linesize arrays
717  * @param h the height of the image specified by the data and linesize arrays
718  * @param format the pixel format of the image specified by the data and linesize arrays
719  */
720 attribute_deprecated
721 AVFilterBufferRef *
722 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
723                                           int w, int h, enum AVPixelFormat format);
724
725 /**
726  * Create an audio buffer reference wrapped around an already
727  * allocated samples buffer.
728  *
729  * @param data           pointers to the samples plane buffers
730  * @param linesize       linesize for the samples plane buffers
731  * @param perms          the required access permissions
732  * @param nb_samples     number of samples per channel
733  * @param sample_fmt     the format of each sample in the buffer to allocate
734  * @param channel_layout the channel layout of the buffer
735  */
736 attribute_deprecated
737 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
738                                                              int linesize,
739                                                              int perms,
740                                                              int nb_samples,
741                                                              enum AVSampleFormat sample_fmt,
742                                                              uint64_t channel_layout);
743 #endif
744
745 /** Initialize the filter system. Register all builtin filters. */
746 void avfilter_register_all(void);
747
748 #if FF_API_OLD_FILTER_REGISTER
749 /** Uninitialize the filter system. Unregister all filters. */
750 attribute_deprecated
751 void avfilter_uninit(void);
752 #endif
753
754 /**
755  * Register a filter. This is only needed if you plan to use
756  * avfilter_get_by_name later to lookup the AVFilter structure by name. A
757  * filter can still by instantiated with avfilter_graph_alloc_filter even if it
758  * is not registered.
759  *
760  * @param filter the filter to register
761  * @return 0 if the registration was succesfull, a negative value
762  * otherwise
763  */
764 int avfilter_register(AVFilter *filter);
765
766 /**
767  * Get a filter definition matching the given name.
768  *
769  * @param name the filter name to find
770  * @return     the filter definition, if any matching one is registered.
771  *             NULL if none found.
772  */
773 #if !FF_API_NOCONST_GET_NAME
774 const
775 #endif
776 AVFilter *avfilter_get_by_name(const char *name);
777
778 /**
779  * Iterate over all registered filters.
780  * @return If prev is non-NULL, next registered filter after prev or NULL if
781  * prev is the last filter. If prev is NULL, return the first registered filter.
782  */
783 const AVFilter *avfilter_next(const AVFilter *prev);
784
785 #if FF_API_OLD_FILTER_REGISTER
786 /**
787  * If filter is NULL, returns a pointer to the first registered filter pointer,
788  * if filter is non-NULL, returns the next pointer after filter.
789  * If the returned pointer points to NULL, the last registered filter
790  * was already reached.
791  * @deprecated use avfilter_next()
792  */
793 attribute_deprecated
794 AVFilter **av_filter_next(AVFilter **filter);
795 #endif
796
797 #if FF_API_AVFILTER_OPEN
798 /**
799  * Create a filter instance.
800  *
801  * @param filter_ctx put here a pointer to the created filter context
802  * on success, NULL on failure
803  * @param filter    the filter to create an instance of
804  * @param inst_name Name to give to the new instance. Can be NULL for none.
805  * @return >= 0 in case of success, a negative error code otherwise
806  * @deprecated use avfilter_graph_alloc_filter() instead
807  */
808 attribute_deprecated
809 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
810 #endif
811
812
813 #if FF_API_AVFILTER_INIT_FILTER
814 /**
815  * Initialize a filter.
816  *
817  * @param filter the filter to initialize
818  * @param args   A string of parameters to use when initializing the filter.
819  *               The format and meaning of this string varies by filter.
820  * @param opaque Any extra non-string data needed by the filter. The meaning
821  *               of this parameter varies by filter.
822  * @return       zero on success
823  */
824 attribute_deprecated
825 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
826 #endif
827
828 /**
829  * Initialize a filter with the supplied parameters.
830  *
831  * @param ctx  uninitialized filter context to initialize
832  * @param args Options to initialize the filter with. This must be a
833  *             ':'-separated list of options in the 'key=value' form.
834  *             May be NULL if the options have been set directly using the
835  *             AVOptions API or there are no options that need to be set.
836  * @return 0 on success, a negative AVERROR on failure
837  */
838 int avfilter_init_str(AVFilterContext *ctx, const char *args);
839
840 /**
841  * Initialize a filter with the supplied dictionary of options.
842  *
843  * @param ctx     uninitialized filter context to initialize
844  * @param options An AVDictionary filled with options for this filter. On
845  *                return this parameter will be destroyed and replaced with
846  *                a dict containing options that were not found. This dictionary
847  *                must be freed by the caller.
848  *                May be NULL, then this function is equivalent to
849  *                avfilter_init_str() with the second parameter set to NULL.
850  * @return 0 on success, a negative AVERROR on failure
851  *
852  * @note This function and avfilter_init_str() do essentially the same thing,
853  * the difference is in manner in which the options are passed. It is up to the
854  * calling code to choose whichever is more preferable. The two functions also
855  * behave differently when some of the provided options are not declared as
856  * supported by the filter. In such a case, avfilter_init_str() will fail, but
857  * this function will leave those extra options in the options AVDictionary and
858  * continue as usual.
859  */
860 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
861
862 /**
863  * Free a filter context. This will also remove the filter from its
864  * filtergraph's list of filters.
865  *
866  * @param filter the filter to free
867  */
868 void avfilter_free(AVFilterContext *filter);
869
870 /**
871  * Insert a filter in the middle of an existing link.
872  *
873  * @param link the link into which the filter should be inserted
874  * @param filt the filter to be inserted
875  * @param filt_srcpad_idx the input pad on the filter to connect
876  * @param filt_dstpad_idx the output pad on the filter to connect
877  * @return     zero on success
878  */
879 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
880                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
881
882 #if FF_API_AVFILTERBUFFER
883 /**
884  * Copy the frame properties of src to dst, without copying the actual
885  * image data.
886  *
887  * @return 0 on success, a negative number on error.
888  */
889 attribute_deprecated
890 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
891
892 /**
893  * Copy the frame properties and data pointers of src to dst, without copying
894  * the actual data.
895  *
896  * @return 0 on success, a negative number on error.
897  */
898 attribute_deprecated
899 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
900 #endif
901
902 /**
903  * @return AVClass for AVFilterContext.
904  *
905  * @see av_opt_find().
906  */
907 const AVClass *avfilter_get_class(void);
908
909 typedef struct AVFilterGraphInternal AVFilterGraphInternal;
910
911 /**
912  * A function pointer passed to the @ref AVFilterGraph.execute callback to be
913  * executed multiple times, possibly in parallel.
914  *
915  * @param ctx the filter context the job belongs to
916  * @param arg an opaque parameter passed through from @ref
917  *            AVFilterGraph.execute
918  * @param jobnr the index of the job being executed
919  * @param nb_jobs the total number of jobs
920  *
921  * @return 0 on success, a negative AVERROR on error
922  */
923 typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
924
925 /**
926  * A function executing multiple jobs, possibly in parallel.
927  *
928  * @param ctx the filter context to which the jobs belong
929  * @param func the function to be called multiple times
930  * @param arg the argument to be passed to func
931  * @param ret a nb_jobs-sized array to be filled with return values from each
932  *            invocation of func
933  * @param nb_jobs the number of jobs to execute
934  *
935  * @return 0 on success, a negative AVERROR on error
936  */
937 typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
938                                     void *arg, int *ret, int nb_jobs);
939
940 typedef struct AVFilterGraph {
941     const AVClass *av_class;
942 #if FF_API_FOO_COUNT
943     attribute_deprecated
944     unsigned filter_count;
945 #endif
946     AVFilterContext **filters;
947 #if !FF_API_FOO_COUNT
948     unsigned nb_filters;
949 #endif
950
951     char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
952     char *resample_lavr_opts;   ///< libavresample options to use for the auto-inserted resample filters
953 #if FF_API_FOO_COUNT
954     unsigned nb_filters;
955 #endif
956
957     /**
958      * Type of multithreading allowed for filters in this graph. A combination
959      * of AVFILTER_THREAD_* flags.
960      *
961      * May be set by the caller at any point, the setting will apply to all
962      * filters initialized after that. The default is allowing everything.
963      *
964      * When a filter in this graph is initialized, this field is combined using
965      * bit AND with AVFilterContext.thread_type to get the final mask used for
966      * determining allowed threading types. I.e. a threading type needs to be
967      * set in both to be allowed.
968      */
969     int thread_type;
970
971     /**
972      * Maximum number of threads used by filters in this graph. May be set by
973      * the caller before adding any filters to the filtergraph. Zero (the
974      * default) means that the number of threads is determined automatically.
975      */
976     int nb_threads;
977
978     /**
979      * Opaque object for libavfilter internal use.
980      */
981     AVFilterGraphInternal *internal;
982
983     /**
984      * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
985      * be used from callbacks like @ref AVFilterGraph.execute.
986      * Libavfilter will not touch this field in any way.
987      */
988     void *opaque;
989
990     /**
991      * This callback may be set by the caller immediately after allocating the
992      * graph and before adding any filters to it, to provide a custom
993      * multithreading implementation.
994      *
995      * If set, filters with slice threading capability will call this callback
996      * to execute multiple jobs in parallel.
997      *
998      * If this field is left unset, libavfilter will use its internal
999      * implementation, which may or may not be multithreaded depending on the
1000      * platform and build options.
1001      */
1002     avfilter_execute_func *execute;
1003 } AVFilterGraph;
1004
1005 /**
1006  * Allocate a filter graph.
1007  */
1008 AVFilterGraph *avfilter_graph_alloc(void);
1009
1010 /**
1011  * Create a new filter instance in a filter graph.
1012  *
1013  * @param graph graph in which the new filter will be used
1014  * @param filter the filter to create an instance of
1015  * @param name Name to give to the new instance (will be copied to
1016  *             AVFilterContext.name). This may be used by the caller to identify
1017  *             different filters, libavfilter itself assigns no semantics to
1018  *             this parameter. May be NULL.
1019  *
1020  * @return the context of the newly created filter instance (note that it is
1021  *         also retrievable directly through AVFilterGraph.filters or with
1022  *         avfilter_graph_get_filter()) on success or NULL or failure.
1023  */
1024 AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
1025                                              const AVFilter *filter,
1026                                              const char *name);
1027
1028 /**
1029  * Get a filter instance with name name from graph.
1030  *
1031  * @return the pointer to the found filter instance or NULL if it
1032  * cannot be found.
1033  */
1034 AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
1035
1036 #if FF_API_AVFILTER_OPEN
1037 /**
1038  * Add an existing filter instance to a filter graph.
1039  *
1040  * @param graphctx  the filter graph
1041  * @param filter the filter to be added
1042  *
1043  * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
1044  * filter graph
1045  */
1046 attribute_deprecated
1047 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
1048 #endif
1049
1050 /**
1051  * Create and add a filter instance into an existing graph.
1052  * The filter instance is created from the filter filt and inited
1053  * with the parameters args and opaque.
1054  *
1055  * In case of success put in *filt_ctx the pointer to the created
1056  * filter instance, otherwise set *filt_ctx to NULL.
1057  *
1058  * @param name the instance name to give to the created filter instance
1059  * @param graph_ctx the filter graph
1060  * @return a negative AVERROR error code in case of failure, a non
1061  * negative value otherwise
1062  */
1063 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
1064                                  const char *name, const char *args, void *opaque,
1065                                  AVFilterGraph *graph_ctx);
1066
1067 /**
1068  * Check validity and configure all the links and formats in the graph.
1069  *
1070  * @param graphctx the filter graph
1071  * @param log_ctx context used for logging
1072  * @return 0 in case of success, a negative AVERROR code otherwise
1073  */
1074 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
1075
1076 /**
1077  * Free a graph, destroy its links, and set *graph to NULL.
1078  * If *graph is NULL, do nothing.
1079  */
1080 void avfilter_graph_free(AVFilterGraph **graph);
1081
1082 /**
1083  * A linked-list of the inputs/outputs of the filter chain.
1084  *
1085  * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
1086  * where it is used to communicate open (unlinked) inputs and outputs from and
1087  * to the caller.
1088  * This struct specifies, per each not connected pad contained in the graph, the
1089  * filter context and the pad index required for establishing a link.
1090  */
1091 typedef struct AVFilterInOut {
1092     /** unique name for this input/output in the list */
1093     char *name;
1094
1095     /** filter context associated to this input/output */
1096     AVFilterContext *filter_ctx;
1097
1098     /** index of the filt_ctx pad to use for linking */
1099     int pad_idx;
1100
1101     /** next input/input in the list, NULL if this is the last */
1102     struct AVFilterInOut *next;
1103 } AVFilterInOut;
1104
1105 /**
1106  * Allocate a single AVFilterInOut entry.
1107  * Must be freed with avfilter_inout_free().
1108  * @return allocated AVFilterInOut on success, NULL on failure.
1109  */
1110 AVFilterInOut *avfilter_inout_alloc(void);
1111
1112 /**
1113  * Free the supplied list of AVFilterInOut and set *inout to NULL.
1114  * If *inout is NULL, do nothing.
1115  */
1116 void avfilter_inout_free(AVFilterInOut **inout);
1117
1118 /**
1119  * Add a graph described by a string to a graph.
1120  *
1121  * @param graph   the filter graph where to link the parsed graph context
1122  * @param filters string to be parsed
1123  * @param inputs  linked list to the inputs of the graph
1124  * @param outputs linked list to the outputs of the graph
1125  * @return zero on success, a negative AVERROR code on error
1126  */
1127 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
1128                          AVFilterInOut *inputs, AVFilterInOut *outputs,
1129                          void *log_ctx);
1130
1131 /**
1132  * Add a graph described by a string to a graph.
1133  *
1134  * @param[in]  graph   the filter graph where to link the parsed graph context
1135  * @param[in]  filters string to be parsed
1136  * @param[out] inputs  a linked list of all free (unlinked) inputs of the
1137  *                     parsed graph will be returned here. It is to be freed
1138  *                     by the caller using avfilter_inout_free().
1139  * @param[out] outputs a linked list of all free (unlinked) outputs of the
1140  *                     parsed graph will be returned here. It is to be freed by the
1141  *                     caller using avfilter_inout_free().
1142  * @return zero on success, a negative AVERROR code on error
1143  *
1144  * @note the difference between avfilter_graph_parse2() and
1145  * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
1146  * the lists of inputs and outputs, which therefore must be known before calling
1147  * the function. On the other hand, avfilter_graph_parse2() \em returns the
1148  * inputs and outputs that are left unlinked after parsing the graph and the
1149  * caller then deals with them. Another difference is that in
1150  * avfilter_graph_parse(), the inputs parameter describes inputs of the
1151  * <em>already existing</em> part of the graph; i.e. from the point of view of
1152  * the newly created part, they are outputs. Similarly the outputs parameter
1153  * describes outputs of the already existing filters, which are provided as
1154  * inputs to the parsed filters.
1155  * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
1156  * whatsoever to already existing parts of the graph and the inputs parameter
1157  * will on return contain inputs of the newly parsed part of the graph.
1158  * Analogously the outputs parameter will contain outputs of the newly created
1159  * filters.
1160  */
1161 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1162                           AVFilterInOut **inputs,
1163                           AVFilterInOut **outputs);
1164
1165 /**
1166  * @}
1167  */
1168
1169 #endif /* AVFILTER_AVFILTER_H */