]> git.sesse.net Git - casparcg/blob - ffmpeg 0.8/include/libavfilter/avfilter.h
2.0. parallel_yadif: Reduced overhead.
[casparcg] / ffmpeg 0.8 / include / 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
31 #define LIBAVFILTER_VERSION_MAJOR  2
32 #define LIBAVFILTER_VERSION_MINOR 28
33 #define LIBAVFILTER_VERSION_MICRO  1
34
35 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36                                                LIBAVFILTER_VERSION_MINOR, \
37                                                LIBAVFILTER_VERSION_MICRO)
38 #define LIBAVFILTER_VERSION     AV_VERSION(LIBAVFILTER_VERSION_MAJOR,   \
39                                            LIBAVFILTER_VERSION_MINOR,   \
40                                            LIBAVFILTER_VERSION_MICRO)
41 #define LIBAVFILTER_BUILD       LIBAVFILTER_VERSION_INT
42
43 #include <stddef.h>
44
45 /**
46  * Return the LIBAVFILTER_VERSION_INT constant.
47  */
48 unsigned avfilter_version(void);
49
50 /**
51  * Return the libavfilter build-time configuration.
52  */
53 const char *avfilter_configuration(void);
54
55 /**
56  * Return the libavfilter license.
57  */
58 const char *avfilter_license(void);
59
60
61 typedef struct AVFilterContext AVFilterContext;
62 typedef struct AVFilterLink    AVFilterLink;
63 typedef struct AVFilterPad     AVFilterPad;
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 } AVFilterBuffer;
89
90 #define AV_PERM_READ     0x01   ///< can read from the buffer
91 #define AV_PERM_WRITE    0x02   ///< can write to the buffer
92 #define AV_PERM_PRESERVE 0x04   ///< nobody else can overwrite the buffer
93 #define AV_PERM_REUSE    0x08   ///< can output the buffer multiple times, with the same contents each time
94 #define AV_PERM_REUSE2   0x10   ///< can output the buffer multiple times, modified each time
95 #define AV_PERM_NEG_LINESIZES 0x20  ///< the buffer requested can have negative linesizes
96
97 /**
98  * Audio specific properties in a reference to an AVFilterBuffer. Since
99  * AVFilterBufferRef is common to different media formats, audio specific
100  * per reference properties must be separated out.
101  */
102 typedef struct AVFilterBufferRefAudioProps {
103     int64_t channel_layout;     ///< channel layout of audio buffer
104     int nb_samples;             ///< number of audio samples per channel
105     uint32_t sample_rate;       ///< audio buffer sample rate
106     int planar;                 ///< audio buffer - planar or packed
107 } AVFilterBufferRefAudioProps;
108
109 /**
110  * Video specific properties in a reference to an AVFilterBuffer. Since
111  * AVFilterBufferRef is common to different media formats, video specific
112  * per reference properties must be separated out.
113  */
114 typedef struct AVFilterBufferRefVideoProps {
115     int w;                      ///< image width
116     int h;                      ///< image height
117     AVRational sample_aspect_ratio; ///< sample aspect ratio
118     int interlaced;             ///< is frame interlaced
119     int top_field_first;        ///< field order
120     enum AVPictureType pict_type; ///< picture type of the frame
121     int key_frame;              ///< 1 -> keyframe, 0-> not
122 } AVFilterBufferRefVideoProps;
123
124 /**
125  * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
126  * a buffer to, for example, crop image without any memcpy, the buffer origin
127  * and dimensions are per-reference properties. Linesize is also useful for
128  * image flipping, frame to field filters, etc, and so is also per-reference.
129  *
130  * TODO: add anything necessary for frame reordering
131  */
132 typedef struct AVFilterBufferRef {
133     AVFilterBuffer *buf;        ///< the buffer that this is a reference to
134     uint8_t *data[8];           ///< picture/audio data for each plane
135     int linesize[8];            ///< number of bytes per line
136     int format;                 ///< media format
137
138     /**
139      * presentation timestamp. The time unit may change during
140      * filtering, as it is specified in the link and the filter code
141      * may need to rescale the PTS accordingly.
142      */
143     int64_t pts;
144     int64_t pos;                ///< byte position in stream, -1 if unknown
145
146     int perms;                  ///< permissions, see the AV_PERM_* flags
147
148     enum AVMediaType type;      ///< media type of buffer data
149     AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
150     AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
151 } AVFilterBufferRef;
152
153 /**
154  * Copy properties of src to dst, without copying the actual data
155  */
156 static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
157 {
158     // copy common properties
159     dst->pts             = src->pts;
160     dst->pos             = src->pos;
161
162     switch (src->type) {
163     case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
164     case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;
165     default: break;
166     }
167 }
168
169 /**
170  * Add a new reference to a buffer.
171  *
172  * @param ref   an existing reference to the buffer
173  * @param pmask a bitmask containing the allowable permissions in the new
174  *              reference
175  * @return      a new reference to the buffer with the same properties as the
176  *              old, excluding any permissions denied by pmask
177  */
178 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
179
180 /**
181  * Remove a reference to a buffer. If this is the last reference to the
182  * buffer, the buffer itself is also automatically freed.
183  *
184  * @param ref reference to the buffer, may be NULL
185  */
186 void avfilter_unref_buffer(AVFilterBufferRef *ref);
187
188 /**
189  * A list of supported formats for one end of a filter link. This is used
190  * during the format negotiation process to try to pick the best format to
191  * use to minimize the number of necessary conversions. Each filter gives a
192  * list of the formats supported by each input and output pad. The list
193  * given for each pad need not be distinct - they may be references to the
194  * same list of formats, as is often the case when a filter supports multiple
195  * formats, but will always output the same format as it is given in input.
196  *
197  * In this way, a list of possible input formats and a list of possible
198  * output formats are associated with each link. When a set of formats is
199  * negotiated over a link, the input and output lists are merged to form a
200  * new list containing only the common elements of each list. In the case
201  * that there were no common elements, a format conversion is necessary.
202  * Otherwise, the lists are merged, and all other links which reference
203  * either of the format lists involved in the merge are also affected.
204  *
205  * For example, consider the filter chain:
206  * filter (a) --> (b) filter (b) --> (c) filter
207  *
208  * where the letters in parenthesis indicate a list of formats supported on
209  * the input or output of the link. Suppose the lists are as follows:
210  * (a) = {A, B}
211  * (b) = {A, B, C}
212  * (c) = {B, C}
213  *
214  * First, the first link's lists are merged, yielding:
215  * filter (a) --> (a) filter (a) --> (c) filter
216  *
217  * Notice that format list (b) now refers to the same list as filter list (a).
218  * Next, the lists for the second link are merged, yielding:
219  * filter (a) --> (a) filter (a) --> (a) filter
220  *
221  * where (a) = {B}.
222  *
223  * Unfortunately, when the format lists at the two ends of a link are merged,
224  * we must ensure that all links which reference either pre-merge format list
225  * get updated as well. Therefore, we have the format list structure store a
226  * pointer to each of the pointers to itself.
227  */
228 typedef struct AVFilterFormats {
229     unsigned format_count;      ///< number of formats
230     int64_t *formats;           ///< list of media formats
231
232     unsigned refcount;          ///< number of references to this list
233     struct AVFilterFormats ***refs; ///< references to this list
234 }  AVFilterFormats;
235
236 /**
237  * Create a list of supported formats. This is intended for use in
238  * AVFilter->query_formats().
239  *
240  * @param fmts list of media formats, terminated by -1. If NULL an
241  *        empty list is created.
242  * @return the format list, with no existing references
243  */
244 AVFilterFormats *avfilter_make_format_list(const int *fmts);
245 AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts);
246
247 /**
248  * Add fmt to the list of media formats contained in *avff.
249  * If *avff is NULL the function allocates the filter formats struct
250  * and puts its pointer in *avff.
251  *
252  * @return a non negative value in case of success, or a negative
253  * value corresponding to an AVERROR code in case of error
254  */
255 int avfilter_add_format(AVFilterFormats **avff, int64_t fmt);
256
257 /**
258  * Return a list of all formats supported by FFmpeg for the given media type.
259  */
260 AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
261
262 /**
263  * Return a list of all channel layouts supported by FFmpeg.
264  */
265 AVFilterFormats *avfilter_all_channel_layouts(void);
266
267 /**
268  * Return a list of all audio packing formats.
269  */
270 AVFilterFormats *avfilter_all_packing_formats(void);
271
272 /**
273  * Return a format list which contains the intersection of the formats of
274  * a and b. Also, all the references of a, all the references of b, and
275  * a and b themselves will be deallocated.
276  *
277  * If a and b do not share any common formats, neither is modified, and NULL
278  * is returned.
279  */
280 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
281
282 /**
283  * Add *ref as a new reference to formats.
284  * That is the pointers will point like in the ascii art below:
285  *   ________
286  *  |formats |<--------.
287  *  |  ____  |     ____|___________________
288  *  | |refs| |    |  __|_
289  *  | |* * | |    | |  | |  AVFilterLink
290  *  | |* *--------->|*ref|
291  *  | |____| |    | |____|
292  *  |________|    |________________________
293  */
294 void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
295
296 /**
297  * If *ref is non-NULL, remove *ref as a reference to the format list
298  * it currently points to, deallocates that list if this was the last
299  * reference, and sets *ref to NULL.
300  *
301  *         Before                                 After
302  *   ________                               ________         NULL
303  *  |formats |<--------.                   |formats |         ^
304  *  |  ____  |     ____|________________   |  ____  |     ____|________________
305  *  | |refs| |    |  __|_                  | |refs| |    |  __|_
306  *  | |* * | |    | |  | |  AVFilterLink   | |* * | |    | |  | |  AVFilterLink
307  *  | |* *--------->|*ref|                 | |*   | |    | |*ref|
308  *  | |____| |    | |____|                 | |____| |    | |____|
309  *  |________|    |_____________________   |________|    |_____________________
310  */
311 void avfilter_formats_unref(AVFilterFormats **ref);
312
313 /**
314  *
315  *         Before                                 After
316  *   ________                         ________
317  *  |formats |<---------.            |formats |<---------.
318  *  |  ____  |       ___|___         |  ____  |       ___|___
319  *  | |refs| |      |   |   |        | |refs| |      |   |   |   NULL
320  *  | |* *--------->|*oldref|        | |* *--------->|*newref|     ^
321  *  | |* * | |      |_______|        | |* * | |      |_______|  ___|___
322  *  | |____| |                       | |____| |                |   |   |
323  *  |________|                       |________|                |*oldref|
324  *                                                             |_______|
325  */
326 void avfilter_formats_changeref(AVFilterFormats **oldref,
327                                 AVFilterFormats **newref);
328
329 /**
330  * A filter pad used for either input or output.
331  */
332 struct AVFilterPad {
333     /**
334      * Pad name. The name is unique among inputs and among outputs, but an
335      * input may have the same name as an output. This may be NULL if this
336      * pad has no need to ever be referenced by name.
337      */
338     const char *name;
339
340     /**
341      * AVFilterPad type. Only video supported now, hopefully someone will
342      * add audio in the future.
343      */
344     enum AVMediaType type;
345
346     /**
347      * Minimum required permissions on incoming buffers. Any buffer with
348      * insufficient permissions will be automatically copied by the filter
349      * system to a new buffer which provides the needed access permissions.
350      *
351      * Input pads only.
352      */
353     int min_perms;
354
355     /**
356      * Permissions which are not accepted on incoming buffers. Any buffer
357      * which has any of these permissions set will be automatically copied
358      * by the filter system to a new buffer which does not have those
359      * permissions. This can be used to easily disallow buffers with
360      * AV_PERM_REUSE.
361      *
362      * Input pads only.
363      */
364     int rej_perms;
365
366     /**
367      * Callback called before passing the first slice of a new frame. If
368      * NULL, the filter layer will default to storing a reference to the
369      * picture inside the link structure.
370      *
371      * Input video pads only.
372      */
373     void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
374
375     /**
376      * Callback function to get a video buffer. If NULL, the filter system will
377      * use avfilter_default_get_video_buffer().
378      *
379      * Input video pads only.
380      */
381     AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
382
383     /**
384      * Callback function to get an audio buffer. If NULL, the filter system will
385      * use avfilter_default_get_audio_buffer().
386      *
387      * Input audio pads only.
388      */
389     AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
390                                            enum AVSampleFormat sample_fmt, int nb_samples,
391                                            int64_t channel_layout, int planar);
392
393     /**
394      * Callback called after the slices of a frame are completely sent. If
395      * NULL, the filter layer will default to releasing the reference stored
396      * in the link structure during start_frame().
397      *
398      * Input video pads only.
399      */
400     void (*end_frame)(AVFilterLink *link);
401
402     /**
403      * Slice drawing callback. This is where a filter receives video data
404      * and should do its processing.
405      *
406      * Input video pads only.
407      */
408     void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
409
410     /**
411      * Samples filtering callback. This is where a filter receives audio data
412      * and should do its processing.
413      *
414      * Input audio pads only.
415      */
416     void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
417
418     /**
419      * Frame poll callback. This returns the number of immediately available
420      * samples. It should return a positive value if the next request_frame()
421      * is guaranteed to return one frame (with no delay).
422      *
423      * Defaults to just calling the source poll_frame() method.
424      *
425      * Output video pads only.
426      */
427     int (*poll_frame)(AVFilterLink *link);
428
429     /**
430      * Frame request callback. A call to this should result in at least one
431      * frame being output over the given link. This should return zero on
432      * success, and another value on error.
433      *
434      * Output video pads only.
435      */
436     int (*request_frame)(AVFilterLink *link);
437
438     /**
439      * Link configuration callback.
440      *
441      * For output pads, this should set the following link properties:
442      * video: width, height, sample_aspect_ratio, time_base
443      * audio: sample_rate.
444      *
445      * This should NOT set properties such as format, channel_layout, etc which
446      * are negotiated between filters by the filter system using the
447      * query_formats() callback before this function is called.
448      *
449      * For input pads, this should check the properties of the link, and update
450      * the filter's internal state as necessary.
451      *
452      * For both input and output pads, this should return zero on success,
453      * and another value on error.
454      */
455     int (*config_props)(AVFilterLink *link);
456 };
457
458 /** default handler for start_frame() for video inputs */
459 void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
460
461 /** default handler for draw_slice() for video inputs */
462 void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
463
464 /** default handler for end_frame() for video inputs */
465 void avfilter_default_end_frame(AVFilterLink *link);
466
467 /** default handler for filter_samples() for audio inputs */
468 void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
469
470 /** default handler for get_video_buffer() for video inputs */
471 AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
472                                                      int perms, int w, int h);
473
474 /** default handler for get_audio_buffer() for audio inputs */
475 AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
476                                                      enum AVSampleFormat sample_fmt, int nb_samples,
477                                                      int64_t channel_layout, int planar);
478
479 /**
480  * Helpers for query_formats() which set all links to the same list of
481  * formats/layouts. If there are no links hooked to this filter, the list
482  * of formats is freed.
483  */
484 void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats);
485 void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats);
486 void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats);
487 void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats);
488
489 /** Default handler for query_formats() */
490 int avfilter_default_query_formats(AVFilterContext *ctx);
491
492 /** start_frame() handler for filters which simply pass video along */
493 void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
494
495 /** draw_slice() handler for filters which simply pass video along */
496 void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
497
498 /** end_frame() handler for filters which simply pass video along */
499 void avfilter_null_end_frame(AVFilterLink *link);
500
501 /** filter_samples() handler for filters which simply pass audio along */
502 void avfilter_null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
503
504 /** get_video_buffer() handler for filters which simply pass video along */
505 AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
506                                                   int perms, int w, int h);
507
508 /** get_audio_buffer() handler for filters which simply pass audio along */
509 AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms,
510                                                   enum AVSampleFormat sample_fmt, int size,
511                                                   int64_t channel_layout, int planar);
512
513 /**
514  * Filter definition. This defines the pads a filter contains, and all the
515  * callback functions used to interact with the filter.
516  */
517 typedef struct AVFilter {
518     const char *name;         ///< filter name
519
520     int priv_size;      ///< size of private data to allocate for the filter
521
522     /**
523      * Filter initialization function. Args contains the user-supplied
524      * parameters. FIXME: maybe an AVOption-based system would be better?
525      * opaque is data provided by the code requesting creation of the filter,
526      * and is used to pass data to the filter.
527      */
528     int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
529
530     /**
531      * Filter uninitialization function. Should deallocate any memory held
532      * by the filter, release any buffer references, etc. This does not need
533      * to deallocate the AVFilterContext->priv memory itself.
534      */
535     void (*uninit)(AVFilterContext *ctx);
536
537     /**
538      * Queries formats/layouts supported by the filter and its pads, and sets
539      * the in_formats/in_chlayouts for links connected to its output pads,
540      * and out_formats/out_chlayouts for links connected to its input pads.
541      *
542      * @return zero on success, a negative value corresponding to an
543      * AVERROR code otherwise
544      */
545     int (*query_formats)(AVFilterContext *);
546
547     const AVFilterPad *inputs;  ///< NULL terminated list of inputs. NULL if none
548     const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
549
550     /**
551      * A description for the filter. You should use the
552      * NULL_IF_CONFIG_SMALL() macro to define it.
553      */
554     const char *description;
555 } AVFilter;
556
557 /** An instance of a filter */
558 struct AVFilterContext {
559     const AVClass *av_class;              ///< needed for av_log()
560
561     AVFilter *filter;               ///< the AVFilter of which this is an instance
562
563     char *name;                     ///< name of this filter instance
564
565     unsigned input_count;           ///< number of input pads
566     AVFilterPad   *input_pads;      ///< array of input pads
567     AVFilterLink **inputs;          ///< array of pointers to input links
568
569     unsigned output_count;          ///< number of output pads
570     AVFilterPad   *output_pads;     ///< array of output pads
571     AVFilterLink **outputs;         ///< array of pointers to output links
572
573     void *priv;                     ///< private data for use by the filter
574 };
575
576 enum AVFilterPacking {
577     AVFILTER_PACKED = 0,
578     AVFILTER_PLANAR,
579 };
580
581 /**
582  * A link between two filters. This contains pointers to the source and
583  * destination filters between which this link exists, and the indexes of
584  * the pads involved. In addition, this link also contains the parameters
585  * which have been negotiated and agreed upon between the filter, such as
586  * image dimensions, format, etc.
587  */
588 struct AVFilterLink {
589     AVFilterContext *src;       ///< source filter
590     AVFilterPad *srcpad;        ///< output pad on the source filter
591
592     AVFilterContext *dst;       ///< dest filter
593     AVFilterPad *dstpad;        ///< input pad on the dest filter
594
595     /** stage of the initialization of the link properties (dimensions, etc) */
596     enum {
597         AVLINK_UNINIT = 0,      ///< not started
598         AVLINK_STARTINIT,       ///< started, but incomplete
599         AVLINK_INIT             ///< complete
600     } init_state;
601
602     enum AVMediaType type;      ///< filter media type
603
604     /* These parameters apply only to video */
605     int w;                      ///< agreed upon image width
606     int h;                      ///< agreed upon image height
607     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
608     /* These parameters apply only to audio */
609     int64_t channel_layout;     ///< channel layout of current buffer (see libavutil/audioconvert.h)
610     int64_t sample_rate;        ///< samples per second
611     int planar;                 ///< agreed upon packing mode of audio buffers. true if planar.
612
613     int format;                 ///< agreed upon media format
614
615     /**
616      * Lists of formats and channel layouts supported by the input and output
617      * filters respectively. These lists are used for negotiating the format
618      * to actually be used, which will be loaded into the format and
619      * channel_layout members, above, when chosen.
620      *
621      */
622     AVFilterFormats *in_formats;
623     AVFilterFormats *out_formats;
624
625     AVFilterFormats *in_chlayouts;
626     AVFilterFormats *out_chlayouts;
627     AVFilterFormats *in_packing;
628     AVFilterFormats *out_packing;
629
630     /**
631      * The buffer reference currently being sent across the link by the source
632      * filter. This is used internally by the filter system to allow
633      * automatic copying of buffers which do not have sufficient permissions
634      * for the destination. This should not be accessed directly by the
635      * filters.
636      */
637     AVFilterBufferRef *src_buf;
638
639     AVFilterBufferRef *cur_buf;
640     AVFilterBufferRef *out_buf;
641
642     /**
643      * Define the time base used by the PTS of the frames/samples
644      * which will pass through this link.
645      * During the configuration stage, each filter is supposed to
646      * change only the output timebase, while the timebase of the
647      * input link is assumed to be an unchangeable property.
648      */
649     AVRational time_base;
650
651     struct AVFilterPool *pool;
652 };
653
654 /**
655  * Link two filters together.
656  *
657  * @param src    the source filter
658  * @param srcpad index of the output pad on the source filter
659  * @param dst    the destination filter
660  * @param dstpad index of the input pad on the destination filter
661  * @return       zero on success
662  */
663 int avfilter_link(AVFilterContext *src, unsigned srcpad,
664                   AVFilterContext *dst, unsigned dstpad);
665
666 /**
667  * Free the link in *link, and set its pointer to NULL.
668  */
669 void avfilter_link_free(AVFilterLink **link);
670
671 /**
672  * Negotiate the media format, dimensions, etc of all inputs to a filter.
673  *
674  * @param filter the filter to negotiate the properties for its inputs
675  * @return       zero on successful negotiation
676  */
677 int avfilter_config_links(AVFilterContext *filter);
678
679 /**
680  * Request a picture buffer with a specific set of permissions.
681  *
682  * @param link  the output link to the filter from which the buffer will
683  *              be requested
684  * @param perms the required access permissions
685  * @param w     the minimum width of the buffer to allocate
686  * @param h     the minimum height of the buffer to allocate
687  * @return      A reference to the buffer. This must be unreferenced with
688  *              avfilter_unref_buffer when you are finished with it.
689  */
690 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
691                                           int w, int h);
692
693 /**
694  * Create a buffer reference wrapped around an already allocated image
695  * buffer.
696  *
697  * @param data pointers to the planes of the image to reference
698  * @param linesize linesizes for the planes of the image to reference
699  * @param perms the required access permissions
700  * @param w the width of the image specified by the data and linesize arrays
701  * @param h the height of the image specified by the data and linesize arrays
702  * @param format the pixel format of the image specified by the data and linesize arrays
703  */
704 AVFilterBufferRef *
705 avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
706                                           int w, int h, enum PixelFormat format);
707
708 /**
709  * Request an audio samples buffer with a specific set of permissions.
710  *
711  * @param link           the output link to the filter from which the buffer will
712  *                       be requested
713  * @param perms          the required access permissions
714  * @param sample_fmt     the format of each sample in the buffer to allocate
715  * @param nb_samples     the number of samples per channel
716  * @param channel_layout the number and type of channels per sample in the buffer to allocate
717  * @param planar         audio data layout - planar or packed
718  * @return               A reference to the samples. This must be unreferenced with
719  *                       avfilter_unref_buffer when you are finished with it.
720  */
721 AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
722                                              enum AVSampleFormat sample_fmt, int nb_samples,
723                                              int64_t channel_layout, int planar);
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  * @param planar         audio data layout - planar or packed
736  */
737 AVFilterBufferRef *
738 avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms,
739                                           int nb_samples, enum AVSampleFormat sample_fmt,
740                                           int64_t channel_layout, int planar);
741
742 /**
743  * Request an input frame from the filter at the other end of the link.
744  *
745  * @param link the input link
746  * @return     zero on success
747  */
748 int avfilter_request_frame(AVFilterLink *link);
749
750 /**
751  * Poll a frame from the filter chain.
752  *
753  * @param  link the input link
754  * @return the number of immediately available frames, a negative
755  * number in case of error
756  */
757 int avfilter_poll_frame(AVFilterLink *link);
758
759 /**
760  * Notifie the next filter of the start of a frame.
761  *
762  * @param link   the output link the frame will be sent over
763  * @param picref A reference to the frame about to be sent. The data for this
764  *               frame need only be valid once draw_slice() is called for that
765  *               portion. The receiving filter will free this reference when
766  *               it no longer needs it.
767  */
768 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
769
770 /**
771  * Notifie the next filter that the current frame has finished.
772  *
773  * @param link the output link the frame was sent over
774  */
775 void avfilter_end_frame(AVFilterLink *link);
776
777 /**
778  * Send a slice to the next filter.
779  *
780  * Slices have to be provided in sequential order, either in
781  * top-bottom or bottom-top order. If slices are provided in
782  * non-sequential order the behavior of the function is undefined.
783  *
784  * @param link the output link over which the frame is being sent
785  * @param y    offset in pixels from the top of the image for this slice
786  * @param h    height of this slice in pixels
787  * @param slice_dir the assumed direction for sending slices,
788  *             from the top slice to the bottom slice if the value is 1,
789  *             from the bottom slice to the top slice if the value is -1,
790  *             for other values the behavior of the function is undefined.
791  */
792 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
793
794 /**
795  * Send a buffer of audio samples to the next filter.
796  *
797  * @param link       the output link over which the audio samples are being sent
798  * @param samplesref a reference to the buffer of audio samples being sent. The
799  *                   receiving filter will free this reference when it no longer
800  *                   needs it or pass it on to the next filter.
801  */
802 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
803
804 /** Initialize the filter system. Register all builtin filters. */
805 void avfilter_register_all(void);
806
807 /** Uninitialize the filter system. Unregister all filters. */
808 void avfilter_uninit(void);
809
810 /**
811  * Register a filter. This is only needed if you plan to use
812  * avfilter_get_by_name later to lookup the AVFilter structure by name. A
813  * filter can still by instantiated with avfilter_open even if it is not
814  * registered.
815  *
816  * @param filter the filter to register
817  * @return 0 if the registration was succesfull, a negative value
818  * otherwise
819  */
820 int avfilter_register(AVFilter *filter);
821
822 /**
823  * Get a filter definition matching the given name.
824  *
825  * @param name the filter name to find
826  * @return     the filter definition, if any matching one is registered.
827  *             NULL if none found.
828  */
829 AVFilter *avfilter_get_by_name(const char *name);
830
831 /**
832  * If filter is NULL, returns a pointer to the first registered filter pointer,
833  * if filter is non-NULL, returns the next pointer after filter.
834  * If the returned pointer points to NULL, the last registered filter
835  * was already reached.
836  */
837 AVFilter **av_filter_next(AVFilter **filter);
838
839 /**
840  * Create a filter instance.
841  *
842  * @param filter_ctx put here a pointer to the created filter context
843  * on success, NULL on failure
844  * @param filter    the filter to create an instance of
845  * @param inst_name Name to give to the new instance. Can be NULL for none.
846  * @return >= 0 in case of success, a negative error code otherwise
847  */
848 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
849
850 /**
851  * Initialize a filter.
852  *
853  * @param filter the filter to initialize
854  * @param args   A string of parameters to use when initializing the filter.
855  *               The format and meaning of this string varies by filter.
856  * @param opaque Any extra non-string data needed by the filter. The meaning
857  *               of this parameter varies by filter.
858  * @return       zero on success
859  */
860 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
861
862 /**
863  * Free a filter context.
864  *
865  * @param filter the filter to free
866  */
867 void avfilter_free(AVFilterContext *filter);
868
869 /**
870  * Insert a filter in the middle of an existing link.
871  *
872  * @param link the link into which the filter should be inserted
873  * @param filt the filter to be inserted
874  * @param filt_srcpad_idx the input pad on the filter to connect
875  * @param filt_dstpad_idx the output pad on the filter to connect
876  * @return     zero on success
877  */
878 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
879                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
880
881 /**
882  * Insert a new pad.
883  *
884  * @param idx Insertion point. Pad is inserted at the end if this point
885  *            is beyond the end of the list of pads.
886  * @param count Pointer to the number of pads in the list
887  * @param padidx_off Offset within an AVFilterLink structure to the element
888  *                   to increment when inserting a new pad causes link
889  *                   numbering to change
890  * @param pads Pointer to the pointer to the beginning of the list of pads
891  * @param links Pointer to the pointer to the beginning of the list of links
892  * @param newpad The new pad to add. A copy is made when adding.
893  */
894 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
895                          AVFilterPad **pads, AVFilterLink ***links,
896                          AVFilterPad *newpad);
897
898 /** Insert a new input pad for the filter. */
899 static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
900                                          AVFilterPad *p)
901 {
902     avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
903                         &f->input_pads, &f->inputs, p);
904 }
905
906 /** Insert a new output pad for the filter. */
907 static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
908                                           AVFilterPad *p)
909 {
910     avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
911                         &f->output_pads, &f->outputs, p);
912 }
913
914 #endif /* AVFILTER_AVFILTER_H */