]> git.sesse.net Git - ffmpeg/blob - libavfilter/avfilter.h
lavfi/color: use AVOptions
[ffmpeg] / libavfilter / avfilter.h
1 /*
2  * filter layer
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 #include "libavutil/avutil.h"
26 #include "libavutil/log.h"
27 #include "libavutil/samplefmt.h"
28 #include "libavutil/pixfmt.h"
29 #include "libavutil/rational.h"
30 #include "libavcodec/avcodec.h"
31
32
33 #ifndef FF_API_OLD_VSINK_API
34 #define FF_API_OLD_VSINK_API        (LIBAVFILTER_VERSION_MAJOR < 3)
35 #endif
36 #ifndef FF_API_OLD_ALL_FORMATS_API
37 #define FF_API_OLD_ALL_FORMATS_API (LIBAVFILTER_VERSION_MAJOR < 3)
38 #endif
39
40 #include <stddef.h>
41
42 #include "libavfilter/version.h"
43
44 /**
45  * Return the LIBAVFILTER_VERSION_INT constant.
46  */
47 unsigned avfilter_version(void);
48
49 /**
50  * Return the libavfilter build-time configuration.
51  */
52 const char *avfilter_configuration(void);
53
54 /**
55  * Return the libavfilter license.
56  */
57 const char *avfilter_license(void);
58
59
60 typedef struct AVFilterContext AVFilterContext;
61 typedef struct AVFilterLink    AVFilterLink;
62 typedef struct AVFilterPad     AVFilterPad;
63 typedef struct AVFilterFormats AVFilterFormats;
64
65 /**
66  * A reference-counted buffer data type used by the filter system. Filters
67  * should not store pointers to this structure directly, but instead use the
68  * AVFilterBufferRef structure below.
69  */
70 typedef struct AVFilterBuffer {
71     uint8_t *data[8];           ///< buffer data for each plane/channel
72     int linesize[8];            ///< number of bytes per line
73
74     unsigned refcount;          ///< number of references to this buffer
75
76     /** private data to be used by a custom free function */
77     void *priv;
78     /**
79      * A pointer to the function to deallocate this buffer if the default
80      * function is not sufficient. This could, for example, add the memory
81      * back into a memory pool to be reused later without the overhead of
82      * reallocating it from scratch.
83      */
84     void (*free)(struct AVFilterBuffer *buf);
85
86     int format;                 ///< media format
87     int w, h;                   ///< width and height of the allocated buffer
88
89     /**
90      * pointers to the data planes/channels.
91      *
92      * For video, this should simply point to data[].
93      *
94      * For planar audio, each channel has a separate data pointer, and
95      * linesize[0] contains the size of each channel buffer.
96      * For packed audio, there is just one data pointer, and linesize[0]
97      * contains the total size of the buffer for all channels.
98      *
99      * Note: Both data and extended_data will always be set, but for planar
100      * audio with more channels that can fit in data, extended_data must be used
101      * in order to access all channels.
102      */
103     uint8_t **extended_data;
104 } AVFilterBuffer;
105
106 #define AV_PERM_READ     0x01   ///< can read from the buffer
107 #define AV_PERM_WRITE    0x02   ///< can write to the buffer
108 #define AV_PERM_PRESERVE 0x04   ///< nobody else can overwrite the buffer
109 #define AV_PERM_REUSE    0x08   ///< can output the buffer multiple times, with the same contents each time
110 #define AV_PERM_REUSE2   0x10   ///< can output the buffer multiple times, modified each time
111 #define AV_PERM_NEG_LINESIZES 0x20  ///< the buffer requested can have negative linesizes
112 #define AV_PERM_ALIGN    0x40   ///< the buffer must be aligned
113
114 #define AVFILTER_ALIGN 16 //not part of ABI
115
116 /**
117  * Audio specific properties in a reference to an AVFilterBuffer. Since
118  * AVFilterBufferRef is common to different media formats, audio specific
119  * per reference properties must be separated out.
120  */
121 typedef struct AVFilterBufferRefAudioProps {
122     uint64_t channel_layout;    ///< channel layout of audio buffer
123     int nb_samples;             ///< number of audio samples per channel
124     int sample_rate;            ///< audio buffer sample rate
125 #if FF_API_PACKING
126     int planar;                 ///< audio buffer - planar or packed
127 #endif
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 sample_aspect_ratio; ///< sample 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     int linesize[8];            ///< number of bytes per line
157     int format;                 ///< media format
158
159     /**
160      * presentation timestamp. The time unit may change during
161      * filtering, as it is specified in the link and the filter code
162      * may need to rescale the PTS accordingly.
163      */
164     int64_t pts;
165     int64_t pos;                ///< byte position in stream, -1 if unknown
166
167     int perms;                  ///< permissions, see the AV_PERM_* flags
168
169     enum AVMediaType type;      ///< media type of buffer data
170     AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
171     AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
172
173     /**
174      * pointers to the data planes/channels.
175      *
176      * For video, this should simply point to data[].
177      *
178      * For planar audio, each channel has a separate data pointer, and
179      * linesize[0] contains the size of each channel buffer.
180      * For packed audio, there is just one data pointer, and linesize[0]
181      * contains the total size of the buffer for all channels.
182      *
183      * Note: Both data and extended_data will always be set, but for planar
184      * audio with more channels that can fit in data, extended_data must be used
185      * in order to access all channels.
186      */
187     uint8_t **extended_data;
188 } AVFilterBufferRef;
189
190 /**
191  * Copy properties of src to dst, without copying the actual data
192  */
193 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
194
195 /**
196  * Add a new reference to a buffer.
197  *
198  * @param ref   an existing reference to the buffer
199  * @param pmask a bitmask containing the allowable permissions in the new
200  *              reference
201  * @return      a new reference to the buffer with the same properties as the
202  *              old, excluding any permissions denied by pmask
203  */
204 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
205
206 /**
207  * Remove a reference to a buffer. If this is the last reference to the
208  * buffer, the buffer itself is also automatically freed.
209  *
210  * @param ref reference to the buffer, may be NULL
211  */
212 void avfilter_unref_buffer(AVFilterBufferRef *ref);
213
214 #if FF_API_FILTERS_PUBLIC
215 /**
216  * Remove a reference to a buffer and set the pointer to NULL.
217  * If this is the last reference to the buffer, the buffer itself
218  * is also automatically freed.
219  *
220  * @param ref pointer to the buffer reference
221  */
222 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
223
224 /**
225  * A list of supported formats for one end of a filter link. This is used
226  * during the format negotiation process to try to pick the best format to
227  * use to minimize the number of necessary conversions. Each filter gives a
228  * list of the formats supported by each input and output pad. The list
229  * given for each pad need not be distinct - they may be references to the
230  * same list of formats, as is often the case when a filter supports multiple
231  * formats, but will always output the same format as it is given in input.
232  *
233  * In this way, a list of possible input formats and a list of possible
234  * output formats are associated with each link. When a set of formats is
235  * negotiated over a link, the input and output lists are merged to form a
236  * new list containing only the common elements of each list. In the case
237  * that there were no common elements, a format conversion is necessary.
238  * Otherwise, the lists are merged, and all other links which reference
239  * either of the format lists involved in the merge are also affected.
240  *
241  * For example, consider the filter chain:
242  * filter (a) --> (b) filter (b) --> (c) filter
243  *
244  * where the letters in parenthesis indicate a list of formats supported on
245  * the input or output of the link. Suppose the lists are as follows:
246  * (a) = {A, B}
247  * (b) = {A, B, C}
248  * (c) = {B, C}
249  *
250  * First, the first link's lists are merged, yielding:
251  * filter (a) --> (a) filter (a) --> (c) filter
252  *
253  * Notice that format list (b) now refers to the same list as filter list (a).
254  * Next, the lists for the second link are merged, yielding:
255  * filter (a) --> (a) filter (a) --> (a) filter
256  *
257  * where (a) = {B}.
258  *
259  * Unfortunately, when the format lists at the two ends of a link are merged,
260  * we must ensure that all links which reference either pre-merge format list
261  * get updated as well. Therefore, we have the format list structure store a
262  * pointer to each of the pointers to itself.
263  * @addtogroup lavfi_deprecated
264  * @deprecated Those functions are only useful inside filters and
265  * user filters are not supported at this point.
266  * @{
267  */
268 struct AVFilterFormats {
269     unsigned format_count;      ///< number of formats
270     int *formats;               ///< list of media formats
271
272     unsigned refcount;          ///< number of references to this list
273     struct AVFilterFormats ***refs; ///< references to this list
274 };
275
276 /**
277  * Create a list of supported formats. This is intended for use in
278  * AVFilter->query_formats().
279  *
280  * @param fmts list of media formats, terminated by -1. If NULL an
281  *        empty list is created.
282  * @return the format list, with no existing references
283  */
284 attribute_deprecated
285 AVFilterFormats *avfilter_make_format_list(const int *fmts);
286
287 /**
288  * Add fmt to the list of media formats contained in *avff.
289  * If *avff is NULL the function allocates the filter formats struct
290  * and puts its pointer in *avff.
291  *
292  * @return a non negative value in case of success, or a negative
293  * value corresponding to an AVERROR code in case of error
294  * @deprecated Use avfilter_make_all_formats() instead.
295  */
296 attribute_deprecated
297 int avfilter_add_format(AVFilterFormats **avff, int64_t fmt);
298 attribute_deprecated
299 AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
300
301 /**
302  * Return a list of all formats supported by FFmpeg for the given media type.
303  */
304 AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type);
305
306 /**
307  * A list of all channel layouts supported by libavfilter.
308  */
309 extern const int64_t avfilter_all_channel_layouts[];
310
311 #if FF_API_PACKING
312 /**
313  * Return a list of all audio packing formats.
314  */
315 AVFilterFormats *avfilter_make_all_packing_formats(void);
316 #endif
317
318 /**
319  * Return a format list which contains the intersection of the formats of
320  * a and b. Also, all the references of a, all the references of b, and
321  * a and b themselves will be deallocated.
322  *
323  * If a and b do not share any common formats, neither is modified, and NULL
324  * is returned.
325  */
326 attribute_deprecated
327 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
328
329 /**
330  * Add *ref as a new reference to formats.
331  * That is the pointers will point like in the ASCII art below:
332  *   ________
333  *  |formats |<--------.
334  *  |  ____  |     ____|___________________
335  *  | |refs| |    |  __|_
336  *  | |* * | |    | |  | |  AVFilterLink
337  *  | |* *--------->|*ref|
338  *  | |____| |    | |____|
339  *  |________|    |________________________
340  */
341 attribute_deprecated
342 void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
343 attribute_deprecated
344 void avfilter_formats_unref(AVFilterFormats **ref);
345 attribute_deprecated
346 void avfilter_formats_changeref(AVFilterFormats **oldref,
347                                 AVFilterFormats **newref);
348 /**
349  * Helpers for query_formats() which set all links to the same list of
350  * formats/layouts. If there are no links hooked to this filter, the list
351  * of formats is freed.
352  */
353 attribute_deprecated
354 void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
355
356 attribute_deprecated
357 void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
358 attribute_deprecated
359 void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
360 attribute_deprecated
361 void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
362 #if FF_API_PACKING
363 attribute_deprecated
364 void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
365 #endif
366
367 /**
368  * @}
369  */
370 #endif
371
372 #if FF_API_AVFILTERPAD_PUBLIC
373 /**
374  * A filter pad used for either input or output.
375  *
376  * See doc/filter_design.txt for details on how to implement the methods.
377  *
378  * @warning this struct might be removed from public API.
379  * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
380  * to access the name and type fields; there should be no need to access
381  * any other fields from outside of libavfilter.
382  */
383 struct AVFilterPad {
384     /**
385      * Pad name. The name is unique among inputs and among outputs, but an
386      * input may have the same name as an output. This may be NULL if this
387      * pad has no need to ever be referenced by name.
388      */
389     const char *name;
390
391     /**
392      * AVFilterPad type.
393      */
394     enum AVMediaType type;
395
396     /**
397      * Minimum required permissions on incoming buffers. Any buffer with
398      * insufficient permissions will be automatically copied by the filter
399      * system to a new buffer which provides the needed access permissions.
400      *
401      * Input pads only.
402      */
403     int min_perms;
404
405     /**
406      * Permissions which are not accepted on incoming buffers. Any buffer
407      * which has any of these permissions set will be automatically copied
408      * by the filter system to a new buffer which does not have those
409      * permissions. This can be used to easily disallow buffers with
410      * AV_PERM_REUSE.
411      *
412      * Input pads only.
413      */
414     int rej_perms;
415
416     /**
417      * Callback called before passing the first slice of a new frame. If
418      * NULL, the filter layer will default to storing a reference to the
419      * picture inside the link structure.
420      *
421      * Input video pads only.
422      */
423     void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
424
425     /**
426      * Callback function to get a video buffer. If NULL, the filter system will
427      * use avfilter_default_get_video_buffer().
428      *
429      * Input video pads only.
430      */
431     AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
432
433     /**
434      * Callback function to get an audio buffer. If NULL, the filter system will
435      * use avfilter_default_get_audio_buffer().
436      *
437      * Input audio pads only.
438      */
439     AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
440                                            int nb_samples);
441
442     /**
443      * Callback called after the slices of a frame are completely sent. If
444      * NULL, the filter layer will default to releasing the reference stored
445      * in the link structure during start_frame().
446      *
447      * Input video pads only.
448      */
449     void (*end_frame)(AVFilterLink *link);
450
451     /**
452      * Slice drawing callback. This is where a filter receives video data
453      * and should do its processing.
454      *
455      * Input video pads only.
456      */
457     void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
458
459     /**
460      * Samples filtering callback. This is where a filter receives audio data
461      * and should do its processing.
462      *
463      * Input audio pads only.
464      */
465     void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
466
467     /**
468      * Frame poll callback. This returns the number of immediately available
469      * samples. It should return a positive value if the next request_frame()
470      * is guaranteed to return one frame (with no delay).
471      *
472      * Defaults to just calling the source poll_frame() method.
473      *
474      * Output pads only.
475      */
476     int (*poll_frame)(AVFilterLink *link);
477
478     /**
479      * Frame request callback. A call to this should result in at least one
480      * frame being output over the given link. This should return zero on
481      * success, and another value on error.
482      * See avfilter_request_frame() for the error codes with a specific
483      * meaning.
484      *
485      * Output pads only.
486      */
487     int (*request_frame)(AVFilterLink *link);
488
489     /**
490      * Link configuration callback.
491      *
492      * For output pads, this should set the following link properties:
493      * video: width, height, sample_aspect_ratio, time_base
494      * audio: sample_rate.
495      *
496      * This should NOT set properties such as format, channel_layout, etc which
497      * are negotiated between filters by the filter system using the
498      * query_formats() callback before this function is called.
499      *
500      * For input pads, this should check the properties of the link, and update
501      * the filter's internal state as necessary.
502      *
503      * For both input and output pads, this should return zero on success,
504      * and another value on error.
505      */
506     int (*config_props)(AVFilterLink *link);
507 };
508 #endif
509
510 /**
511  * Get the name of an AVFilterPad.
512  *
513  * @param pads an array of AVFilterPads
514  * @param pad_idx index of the pad in the array it; is the caller's
515  *                responsibility to ensure the index is valid
516  *
517  * @return name of the pad_idx'th pad in pads
518  */
519 const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx);
520
521 /**
522  * Get the type of an AVFilterPad.
523  *
524  * @param pads an array of AVFilterPads
525  * @param pad_idx index of the pad in the array; it is the caller's
526  *                responsibility to ensure the index is valid
527  *
528  * @return type of the pad_idx'th pad in pads
529  */
530 enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx);
531
532 #if FF_API_FILTERS_PUBLIC
533 /** default handler for start_frame() for video inputs */
534 attribute_deprecated
535 void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
536
537 /** default handler for draw_slice() for video inputs */
538 attribute_deprecated
539 void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
540
541 /** default handler for end_frame() for video inputs */
542 attribute_deprecated
543 void avfilter_default_end_frame(AVFilterLink *link);
544
545 /** default handler for get_video_buffer() for video inputs */
546 attribute_deprecated
547 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
548                                                      int perms, int w, int h);
549
550 /** Default handler for query_formats() */
551 attribute_deprecated
552 int avfilter_default_query_formats(AVFilterContext *ctx);
553 #endif
554
555 #if FF_API_FILTERS_PUBLIC
556 /** start_frame() handler for filters which simply pass video along */
557 attribute_deprecated
558 void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
559
560 /** draw_slice() handler for filters which simply pass video along */
561 attribute_deprecated
562 void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
563
564 /** end_frame() handler for filters which simply pass video along */
565 attribute_deprecated
566 void avfilter_null_end_frame(AVFilterLink *link);
567
568 /** get_video_buffer() handler for filters which simply pass video along */
569 attribute_deprecated
570 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
571                                                   int perms, int w, int h);
572 #endif
573
574 /**
575  * Filter definition. This defines the pads a filter contains, and all the
576  * callback functions used to interact with the filter.
577  */
578 typedef struct AVFilter {
579     const char *name;         ///< filter name
580
581     int priv_size;      ///< size of private data to allocate for the filter
582
583     /**
584      * Filter initialization function. Args contains the user-supplied
585      * parameters. FIXME: maybe an AVOption-based system would be better?
586      * opaque is data provided by the code requesting creation of the filter,
587      * and is used to pass data to the filter.
588      */
589     int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
590
591     /**
592      * Filter uninitialization function. Should deallocate any memory held
593      * by the filter, release any buffer references, etc. This does not need
594      * to deallocate the AVFilterContext->priv memory itself.
595      */
596     void (*uninit)(AVFilterContext *ctx);
597
598     /**
599      * Queries formats/layouts supported by the filter and its pads, and sets
600      * the in_formats/in_chlayouts for links connected to its output pads,
601      * and out_formats/out_chlayouts for links connected to its input pads.
602      *
603      * @return zero on success, a negative value corresponding to an
604      * AVERROR code otherwise
605      */
606     int (*query_formats)(AVFilterContext *);
607
608     const AVFilterPad *inputs;  ///< NULL terminated list of inputs. NULL if none
609     const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
610
611     /**
612      * A description for the filter. You should use the
613      * NULL_IF_CONFIG_SMALL() macro to define it.
614      */
615     const char *description;
616
617     /**
618      * Make the filter instance process a command.
619      *
620      * @param cmd    the command to process, for handling simplicity all commands must be alphanumeric only
621      * @param arg    the argument for the command
622      * @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.
623      * @param flags  if AVFILTER_CMD_FLAG_FAST is set and the command would be
624      *               time consuming then a filter should treat it like an unsupported command
625      *
626      * @returns >=0 on success otherwise an error code.
627      *          AVERROR(ENOSYS) on unsupported commands
628      */
629     int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
630 } AVFilter;
631
632 /** An instance of a filter */
633 struct AVFilterContext {
634     const AVClass *av_class;        ///< needed for av_log()
635
636     AVFilter *filter;               ///< the AVFilter of which this is an instance
637
638     char *name;                     ///< name of this filter instance
639
640 #if FF_API_FOO_COUNT
641     unsigned input_count;           ///< @deprecated use nb_inputs
642 #endif
643     AVFilterPad   *input_pads;      ///< array of input pads
644     AVFilterLink **inputs;          ///< array of pointers to input links
645
646 #if FF_API_FOO_COUNT
647     unsigned output_count;          ///< @deprecated use nb_outputs
648 #endif
649     AVFilterPad   *output_pads;     ///< array of output pads
650     AVFilterLink **outputs;         ///< array of pointers to output links
651
652     void *priv;                     ///< private data for use by the filter
653
654     unsigned nb_inputs;             ///< number of input pads
655     unsigned nb_outputs;            ///< number of output pads
656
657     struct AVFilterCommand *command_queue;
658 };
659
660 #if FF_API_PACKING
661 enum AVFilterPacking {
662     AVFILTER_PACKED = 0,
663     AVFILTER_PLANAR,
664 };
665 #endif
666
667 /**
668  * A link between two filters. This contains pointers to the source and
669  * destination filters between which this link exists, and the indexes of
670  * the pads involved. In addition, this link also contains the parameters
671  * which have been negotiated and agreed upon between the filter, such as
672  * image dimensions, format, etc.
673  */
674 struct AVFilterLink {
675     AVFilterContext *src;       ///< source filter
676     AVFilterPad *srcpad;        ///< output pad on the source filter
677
678     AVFilterContext *dst;       ///< dest filter
679     AVFilterPad *dstpad;        ///< input pad on the dest filter
680
681     /** stage of the initialization of the link properties (dimensions, etc) */
682     enum {
683         AVLINK_UNINIT = 0,      ///< not started
684         AVLINK_STARTINIT,       ///< started, but incomplete
685         AVLINK_INIT             ///< complete
686     } init_state;
687
688     enum AVMediaType type;      ///< filter media type
689
690     /* These parameters apply only to video */
691     int w;                      ///< agreed upon image width
692     int h;                      ///< agreed upon image height
693     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
694     /* These parameters apply only to audio */
695     uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/audioconvert.h)
696 #if FF_API_SAMPLERATE64
697     int64_t sample_rate;        ///< samples per second
698 #else
699     int sample_rate;            ///< samples per second
700 #endif
701 #if FF_API_PACKING
702     int planar;                 ///< agreed upon packing mode of audio buffers. true if planar.
703 #endif
704
705     int format;                 ///< agreed upon media format
706
707     /**
708      * Lists of formats and channel layouts supported by the input and output
709      * filters respectively. These lists are used for negotiating the format
710      * to actually be used, which will be loaded into the format and
711      * channel_layout members, above, when chosen.
712      *
713      */
714     AVFilterFormats *in_formats;
715     AVFilterFormats *out_formats;
716
717 #if FF_API_PACKING
718     AVFilterFormats *in_packing;
719     AVFilterFormats *out_packing;
720 #endif
721
722     /**
723      * The buffer reference currently being sent across the link by the source
724      * filter. This is used internally by the filter system to allow
725      * automatic copying of buffers which do not have sufficient permissions
726      * for the destination. This should not be accessed directly by the
727      * filters.
728      */
729     AVFilterBufferRef *src_buf;
730
731     AVFilterBufferRef *cur_buf;
732     AVFilterBufferRef *out_buf;
733
734     /**
735      * Define the time base used by the PTS of the frames/samples
736      * which will pass through this link.
737      * During the configuration stage, each filter is supposed to
738      * change only the output timebase, while the timebase of the
739      * input link is assumed to be an unchangeable property.
740      */
741     AVRational time_base;
742
743     /*****************************************************************
744      * All fields below this line are not part of the public API. They
745      * may not be used outside of libavfilter and can be changed and
746      * removed at will.
747      * New public fields should be added right above.
748      *****************************************************************
749      */
750     /**
751      * Lists of channel layouts and sample rates used for automatic
752      * negotiation.
753      */
754     AVFilterFormats  *in_samplerates;
755     AVFilterFormats *out_samplerates;
756     struct AVFilterChannelLayouts  *in_channel_layouts;
757     struct AVFilterChannelLayouts *out_channel_layouts;
758
759     struct AVFilterPool *pool;
760
761     /**
762      * Graph the filter belongs to.
763      */
764     struct AVFilterGraph *graph;
765
766     /**
767      * Current timestamp of the link, as defined by the most recent
768      * frame(s), in AV_TIME_BASE units.
769      */
770     int64_t current_pts;
771
772     /**
773      * Index in the age array.
774      */
775     int age_index;
776
777     /**
778      * Frame rate of the stream on the link, or 1/0 if unknown;
779      * if left to 0/0, will be automatically be copied from the first input
780      * of the source filter if it exists.
781      *
782      * Sources should set it to the best estimation of the real frame rate.
783      * Filters should update it if necessary depending on their function.
784      * Sinks can use it to set a default output frame rate.
785      * It is similar to the r_frae_rate field in AVStream.
786      */
787     AVRational frame_rate;
788
789 };
790
791 /**
792  * Link two filters together.
793  *
794  * @param src    the source filter
795  * @param srcpad index of the output pad on the source filter
796  * @param dst    the destination filter
797  * @param dstpad index of the input pad on the destination filter
798  * @return       zero on success
799  */
800 int avfilter_link(AVFilterContext *src, unsigned srcpad,
801                   AVFilterContext *dst, unsigned dstpad);
802
803 /**
804  * Free the link in *link, and set its pointer to NULL.
805  */
806 void avfilter_link_free(AVFilterLink **link);
807
808 /**
809  * Negotiate the media format, dimensions, etc of all inputs to a filter.
810  *
811  * @param filter the filter to negotiate the properties for its inputs
812  * @return       zero on successful negotiation
813  */
814 int avfilter_config_links(AVFilterContext *filter);
815
816 #if FF_API_FILTERS_PUBLIC
817 attribute_deprecated
818 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
819                                           int w, int h);
820 #endif
821
822 /**
823  * Create a buffer reference wrapped around an already allocated image
824  * buffer.
825  *
826  * @param data pointers to the planes of the image to reference
827  * @param linesize linesizes for the planes of the image to reference
828  * @param perms the required access permissions
829  * @param w the width of the image specified by the data and linesize arrays
830  * @param h the height of the image specified by the data and linesize arrays
831  * @param format the pixel format of the image specified by the data and linesize arrays
832  */
833 AVFilterBufferRef *
834 avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
835                                           int w, int h, enum PixelFormat format);
836
837 /**
838  * Create an audio buffer reference wrapped around an already
839  * allocated samples buffer.
840  *
841  * @param data           pointers to the samples plane buffers
842  * @param linesize       linesize for the samples plane buffers
843  * @param perms          the required access permissions
844  * @param nb_samples     number of samples per channel
845  * @param sample_fmt     the format of each sample in the buffer to allocate
846  * @param channel_layout the channel layout of the buffer
847  */
848 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
849                                                              int linesize,
850                                                              int perms,
851                                                              int nb_samples,
852                                                              enum AVSampleFormat sample_fmt,
853                                                              uint64_t channel_layout);
854
855 #if FF_API_FILTERS_PUBLIC
856 /**
857  * Request an input frame from the filter at the other end of the link.
858  *
859  * @param link the input link
860  * @return     zero on success or a negative error code; in particular:
861  *             AVERROR_EOF means that the end of frames have been reached;
862  *             AVERROR(EAGAIN) means that no frame could be immediately
863  *             produced.
864  */
865 int avfilter_request_frame(AVFilterLink *link);
866
867 attribute_deprecated
868 int avfilter_poll_frame(AVFilterLink *link);
869
870 attribute_deprecated
871 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
872
873 /**
874  * Notify the next filter that the current frame has finished.
875  *
876  * @param link the output link the frame was sent over
877  */
878 attribute_deprecated
879 void avfilter_end_frame(AVFilterLink *link);
880 attribute_deprecated
881 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
882 #endif
883
884 #define AVFILTER_CMD_FLAG_ONE   1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
885 #define AVFILTER_CMD_FLAG_FAST  2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
886
887 /**
888  * Make the filter instance process a command.
889  * It is recommended to use avfilter_graph_send_command().
890  */
891 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
892
893 /** Initialize the filter system. Register all builtin filters. */
894 void avfilter_register_all(void);
895
896 /** Uninitialize the filter system. Unregister all filters. */
897 void avfilter_uninit(void);
898
899 /**
900  * Register a filter. This is only needed if you plan to use
901  * avfilter_get_by_name later to lookup the AVFilter structure by name. A
902  * filter can still by instantiated with avfilter_open even if it is not
903  * registered.
904  *
905  * @param filter the filter to register
906  * @return 0 if the registration was successful, a negative value
907  * otherwise
908  */
909 int avfilter_register(AVFilter *filter);
910
911 /**
912  * Get a filter definition matching the given name.
913  *
914  * @param name the filter name to find
915  * @return     the filter definition, if any matching one is registered.
916  *             NULL if none found.
917  */
918 AVFilter *avfilter_get_by_name(const char *name);
919
920 /**
921  * If filter is NULL, returns a pointer to the first registered filter pointer,
922  * if filter is non-NULL, returns the next pointer after filter.
923  * If the returned pointer points to NULL, the last registered filter
924  * was already reached.
925  */
926 AVFilter **av_filter_next(AVFilter **filter);
927
928 /**
929  * Create a filter instance.
930  *
931  * @param filter_ctx put here a pointer to the created filter context
932  * on success, NULL on failure
933  * @param filter    the filter to create an instance of
934  * @param inst_name Name to give to the new instance. Can be NULL for none.
935  * @return >= 0 in case of success, a negative error code otherwise
936  */
937 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
938
939 /**
940  * Initialize a filter.
941  *
942  * @param filter the filter to initialize
943  * @param args   A string of parameters to use when initializing the filter.
944  *               The format and meaning of this string varies by filter.
945  * @param opaque Any extra non-string data needed by the filter. The meaning
946  *               of this parameter varies by filter.
947  * @return       zero on success
948  */
949 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
950
951 /**
952  * Free a filter context.
953  *
954  * @param filter the filter to free
955  */
956 void avfilter_free(AVFilterContext *filter);
957
958 /**
959  * Insert a filter in the middle of an existing link.
960  *
961  * @param link the link into which the filter should be inserted
962  * @param filt the filter to be inserted
963  * @param filt_srcpad_idx the input pad on the filter to connect
964  * @param filt_dstpad_idx the output pad on the filter to connect
965  * @return     zero on success
966  */
967 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
968                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
969
970 #if FF_API_FILTERS_PUBLIC
971 attribute_deprecated
972 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
973                          AVFilterPad **pads, AVFilterLink ***links,
974                          AVFilterPad *newpad);
975
976 attribute_deprecated
977 void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
978                            AVFilterPad *p);
979 attribute_deprecated
980 void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
981                             AVFilterPad *p);
982 #endif
983
984 #endif /* AVFILTER_AVFILTER_H */