lavfi: make avfilter_get_video_buffer() private on next bump.
[libav.git] / libavfilter / avfilter.h
CommitLineData
a5cbb2f4 1/*
664f6595 2 * filter layer
3fa77bde 3 * Copyright (c) 2007 Bobby Bingham
a5cbb2f4 4 *
2912e87a 5 * This file is part of Libav.
a5cbb2f4 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
a5cbb2f4
VS
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
a5cbb2f4
VS
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
a5cbb2f4
VS
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
98790382
SS
22#ifndef AVFILTER_AVFILTER_H
23#define AVFILTER_AVFILTER_H
a5cbb2f4 24
1f20782c 25#include "libavutil/avutil.h"
abc78a5a 26#include "libavutil/log.h"
737eb597 27#include "libavutil/samplefmt.h"
d49ea4af 28#include "libavutil/pixfmt.h"
e91709ca 29#include "libavutil/rational.h"
1c9e340d 30#include "libavcodec/avcodec.h"
1f20782c 31
a9c81431 32#include <stddef.h>
a5cbb2f4 33
3167dc95
AK
34#include "libavfilter/version.h"
35
540f1c7b 36/**
49bd8e4b 37 * Return the LIBAVFILTER_VERSION_INT constant.
540f1c7b
SS
38 */
39unsigned avfilter_version(void);
40
c1736936 41/**
49bd8e4b 42 * Return the libavfilter build-time configuration.
c1736936 43 */
41600690 44const char *avfilter_configuration(void);
c1736936
DB
45
46/**
49bd8e4b 47 * Return the libavfilter license.
c1736936 48 */
41600690 49const char *avfilter_license(void);
c1736936
DB
50
51
a5cbb2f4
VS
52typedef struct AVFilterContext AVFilterContext;
53typedef struct AVFilterLink AVFilterLink;
54typedef struct AVFilterPad AVFilterPad;
b74a1da4 55typedef struct AVFilterFormats AVFilterFormats;
a5cbb2f4 56
a5cbb2f4 57/**
32d7bcd4 58 * A reference-counted buffer data type used by the filter system. Filters
a5cbb2f4 59 * should not store pointers to this structure directly, but instead use the
ecc8dada 60 * AVFilterBufferRef structure below.
a5cbb2f4 61 */
f607cc18 62typedef struct AVFilterBuffer {
56b5e9d5
HM
63 uint8_t *data[8]; ///< buffer data for each plane/channel
64 int linesize[8]; ///< number of bytes per line
a5cbb2f4 65
32d7bcd4 66 unsigned refcount; ///< number of references to this buffer
13ff8fd0
VS
67
68 /** private data to be used by a custom free function */
a5cbb2f4 69 void *priv;
13ff8fd0 70 /**
32d7bcd4 71 * A pointer to the function to deallocate this buffer if the default
38efe768 72 * function is not sufficient. This could, for example, add the memory
13ff8fd0
VS
73 * back into a memory pool to be reused later without the overhead of
74 * reallocating it from scratch.
75 */
32d7bcd4 76 void (*free)(struct AVFilterBuffer *buf);
36dc00de
MN
77
78 int format; ///< media format
79 int w, h; ///< width and height of the allocated buffer
9453c9e1
AK
80
81 /**
82 * pointers to the data planes/channels.
83 *
84 * For video, this should simply point to data[].
85 *
86 * For planar audio, each channel has a separate data pointer, and
87 * linesize[0] contains the size of each channel buffer.
88 * For packed audio, there is just one data pointer, and linesize[0]
89 * contains the total size of the buffer for all channels.
90 *
91 * Note: Both data and extended_data will always be set, but for planar
92 * audio with more channels that can fit in data, extended_data must be used
93 * in order to access all channels.
94 */
95 uint8_t **extended_data;
f0d77b20 96} AVFilterBuffer;
a5cbb2f4 97
ff5f1be0
HM
98#define AV_PERM_READ 0x01 ///< can read from the buffer
99#define AV_PERM_WRITE 0x02 ///< can write to the buffer
100#define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
101#define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
102#define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
0ccabeea 103#define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
ff5f1be0 104
a5cbb2f4 105/**
ad2c9501
HM
106 * Audio specific properties in a reference to an AVFilterBuffer. Since
107 * AVFilterBufferRef is common to different media formats, audio specific
108 * per reference properties must be separated out.
109 */
110typedef struct AVFilterBufferRefAudioProps {
cc276c85 111 uint64_t channel_layout; ///< channel layout of audio buffer
a242ac36 112 int nb_samples; ///< number of audio samples
a6bdfc2a 113 int sample_rate; ///< audio buffer sample rate
ad2c9501
HM
114 int planar; ///< audio buffer - planar or packed
115} AVFilterBufferRefAudioProps;
116
117/**
cc80caff
HM
118 * Video specific properties in a reference to an AVFilterBuffer. Since
119 * AVFilterBufferRef is common to different media formats, video specific
120 * per reference properties must be separated out.
121 */
f607cc18 122typedef struct AVFilterBufferRefVideoProps {
cc80caff
HM
123 int w; ///< image width
124 int h; ///< image height
125 AVRational pixel_aspect; ///< pixel aspect ratio
126 int interlaced; ///< is frame interlaced
127 int top_field_first; ///< field order
bebe72f4 128 enum AVPictureType pict_type; ///< picture type of the frame
10d39405 129 int key_frame; ///< 1 -> keyframe, 0-> not
cc80caff
HM
130} AVFilterBufferRefVideoProps;
131
132/**
f0d77b20 133 * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
7fce481a 134 * a buffer to, for example, crop image without any memcpy, the buffer origin
38efe768 135 * and dimensions are per-reference properties. Linesize is also useful for
bbf42679 136 * image flipping, frame to field filters, etc, and so is also per-reference.
a5cbb2f4 137 *
1a18860a 138 * TODO: add anything necessary for frame reordering
a5cbb2f4 139 */
f607cc18 140typedef struct AVFilterBufferRef {
7fce481a 141 AVFilterBuffer *buf; ///< the buffer that this is a reference to
ad2c9501 142 uint8_t *data[8]; ///< picture/audio data for each plane
c1db7bff 143 int linesize[8]; ///< number of bytes per line
d54e0948 144 int format; ///< media format
a5cbb2f4 145
867ae7aa
SS
146 /**
147 * presentation timestamp. The time unit may change during
148 * filtering, as it is specified in the link and the filter code
149 * may need to rescale the PTS accordingly.
150 */
151 int64_t pts;
5bb5c1dc 152 int64_t pos; ///< byte position in stream, -1 if unknown
1a18860a 153
ff5f1be0 154 int perms; ///< permissions, see the AV_PERM_* flags
efdc74ef 155
cc80caff
HM
156 enum AVMediaType type; ///< media type of buffer data
157 AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
ad2c9501 158 AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
9453c9e1
AK
159
160 /**
161 * pointers to the data planes/channels.
162 *
163 * For video, this should simply point to data[].
164 *
165 * For planar audio, each channel has a separate data pointer, and
166 * linesize[0] contains the size of each channel buffer.
167 * For packed audio, there is just one data pointer, and linesize[0]
168 * contains the total size of the buffer for all channels.
169 *
170 * Note: Both data and extended_data will always be set, but for planar
171 * audio with more channels that can fit in data, extended_data must be used
172 * in order to access all channels.
173 */
174 uint8_t **extended_data;
ecc8dada 175} AVFilterBufferRef;
a5cbb2f4
VS
176
177/**
ad2c9501 178 * Copy properties of src to dst, without copying the actual data
4d508e4d 179 */
8134fafe 180void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
4d508e4d
SS
181
182/**
7fce481a 183 * Add a new reference to a buffer.
3fa3e4f4 184 *
7fce481a 185 * @param ref an existing reference to the buffer
664f6595 186 * @param pmask a bitmask containing the allowable permissions in the new
13ff8fd0 187 * reference
7fce481a 188 * @return a new reference to the buffer with the same properties as the
13ff8fd0 189 * old, excluding any permissions denied by pmask
a5cbb2f4 190 */
7fce481a 191AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
a5cbb2f4
VS
192
193/**
7fce481a
HM
194 * Remove a reference to a buffer. If this is the last reference to the
195 * buffer, the buffer itself is also automatically freed.
3fa3e4f4 196 *
6baf4afa 197 * @param ref reference to the buffer, may be NULL
a5cbb2f4 198 */
7fce481a 199void avfilter_unref_buffer(AVFilterBufferRef *ref);
a5cbb2f4 200
b74a1da4 201#if FF_API_FILTERS_PUBLIC
13ff8fd0 202/**
b74a1da4
AK
203 * @addtogroup lavfi_deprecated
204 * @deprecated Those functions are only useful inside filters and
205 * user filters are not supported at this point.
206 * @{
35f3fdf4 207 */
b74a1da4 208struct AVFilterFormats {
35f3fdf4 209 unsigned format_count; ///< number of formats
bdab614b 210 int *formats; ///< list of media formats
35f3fdf4
VS
211
212 unsigned refcount; ///< number of references to this list
f607cc18 213 struct AVFilterFormats ***refs; ///< references to this list
b74a1da4 214};
35f3fdf4 215
b74a1da4 216attribute_deprecated
bdab614b 217AVFilterFormats *avfilter_make_format_list(const int *fmts);
b74a1da4 218attribute_deprecated
bdab614b 219int avfilter_add_format(AVFilterFormats **avff, int fmt);
b74a1da4 220attribute_deprecated
bdab614b 221AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
b74a1da4 222attribute_deprecated
35f3fdf4 223AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
b74a1da4 224attribute_deprecated
a27c8d5f 225void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
b74a1da4 226attribute_deprecated
35f3fdf4 227void avfilter_formats_unref(AVFilterFormats **ref);
b74a1da4 228attribute_deprecated
eb30e86c
MN
229void avfilter_formats_changeref(AVFilterFormats **oldref,
230 AVFilterFormats **newref);
b74a1da4
AK
231attribute_deprecated
232void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
233/**
234 * @}
235 */
236#endif
eb30e86c 237
35f3fdf4 238/**
664f6595 239 * A filter pad used for either input or output.
13ff8fd0 240 */
f607cc18 241struct AVFilterPad {
a5cbb2f4 242 /**
38efe768
SS
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
13ff8fd0 245 * pad has no need to ever be referenced by name.
a5cbb2f4 246 */
2844dd39 247 const char *name;
a5cbb2f4
VS
248
249 /**
0ce4a627 250 * AVFilterPad type.
a5cbb2f4 251 */
72415b2a 252 enum AVMediaType type;
a5cbb2f4
VS
253
254 /**
38efe768 255 * Minimum required permissions on incoming buffers. Any buffer with
60bf6ce3
VS
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 int min_perms;
262
263 /**
38efe768 264 * Permissions which are not accepted on incoming buffers. Any buffer
9ce95f27
SS
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
38efe768 267 * permissions. This can be used to easily disallow buffers with
9ce95f27 268 * AV_PERM_REUSE.
60bf6ce3
VS
269 *
270 * Input pads only.
271 */
272 int rej_perms;
273
274 /**
38efe768 275 * Callback called before passing the first slice of a new frame. If
a5cbb2f4
VS
276 * NULL, the filter layer will default to storing a reference to the
277 * picture inside the link structure.
13ff8fd0
VS
278 *
279 * Input video pads only.
a5cbb2f4 280 */
ecc8dada 281 void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
a5cbb2f4
VS
282
283 /**
ad2c9501 284 * Callback function to get a video buffer. If NULL, the filter system will
da23d424 285 * use avfilter_default_get_video_buffer().
13ff8fd0
VS
286 *
287 * Input video pads only.
a5cbb2f4 288 */
ecc8dada 289 AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
a5cbb2f4
VS
290
291 /**
ad2c9501
HM
292 * Callback function to get an audio buffer. If NULL, the filter system will
293 * use avfilter_default_get_audio_buffer().
294 *
295 * Input audio pads only.
296 */
297 AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
7ef0adcc 298 int nb_samples);
ad2c9501
HM
299
300 /**
38efe768 301 * Callback called after the slices of a frame are completely sent. If
a5cbb2f4
VS
302 * NULL, the filter layer will default to releasing the reference stored
303 * in the link structure during start_frame().
13ff8fd0
VS
304 *
305 * Input video pads only.
a5cbb2f4
VS
306 */
307 void (*end_frame)(AVFilterLink *link);
308
309 /**
38efe768 310 * Slice drawing callback. This is where a filter receives video data
13ff8fd0
VS
311 * and should do its processing.
312 *
313 * Input video pads only.
a5cbb2f4 314 */
a13a5437 315 void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
a5cbb2f4
VS
316
317 /**
ad2c9501
HM
318 * Samples filtering callback. This is where a filter receives audio data
319 * and should do its processing.
320 *
321 * Input audio pads only.
322 */
323 void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
324
325 /**
38efe768 326 * Frame poll callback. This returns the number of immediately available
177477f5 327 * samples. It should return a positive value if the next request_frame()
d224d73a
VS
328 * is guaranteed to return one frame (with no delay).
329 *
330 * Defaults to just calling the source poll_frame() method.
331 *
ce353a88 332 * Output pads only.
d224d73a
VS
333 */
334 int (*poll_frame)(AVFilterLink *link);
335
336 /**
38efe768
SS
337 * Frame request callback. A call to this should result in at least one
338 * frame being output over the given link. This should return zero on
13ff8fd0
VS
339 * success, and another value on error.
340 *
ce353a88 341 * Output pads only.
a5cbb2f4 342 */
63f64e6f 343 int (*request_frame)(AVFilterLink *link);
a5cbb2f4
VS
344
345 /**
13ff8fd0
VS
346 * Link configuration callback.
347 *
348 * For output pads, this should set the link properties such as
38efe768 349 * width/height. This should NOT set the format property - that is
13ff8fd0
VS
350 * negotiated between filters by the filter system using the
351 * query_formats() callback before this function is called.
d3e57c15
VS
352 *
353 * For input pads, this should check the properties of the link, and update
354 * the filter's internal state as necessary.
13ff8fd0
VS
355 *
356 * For both input and output filters, this should return zero on success,
357 * and another value on error.
a5cbb2f4 358 */
d3e57c15 359 int (*config_props)(AVFilterLink *link);
a5cbb2f4
VS
360};
361
43c7a01e 362#if FF_API_FILTERS_PUBLIC
2b187df9 363/** default handler for start_frame() for video inputs */
43c7a01e 364attribute_deprecated
ecc8dada 365void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
a4fb0ada 366
b9609848 367/** default handler for draw_slice() for video inputs */
43c7a01e 368attribute_deprecated
a13a5437 369void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
a4fb0ada 370
2b187df9 371/** default handler for end_frame() for video inputs */
43c7a01e 372attribute_deprecated
a5cbb2f4 373void avfilter_default_end_frame(AVFilterLink *link);
a4fb0ada 374
88c3b87b 375#if FF_API_DEFAULT_CONFIG_OUTPUT_LINK
ad2c9501 376/** default handler for config_props() for audio/video outputs */
88c3b87b 377attribute_deprecated
901e6b39 378int avfilter_default_config_output_link(AVFilterLink *link);
88c3b87b 379#endif
a4fb0ada 380
2b187df9 381/** default handler for get_video_buffer() for video inputs */
43c7a01e 382attribute_deprecated
ecc8dada 383AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
a4fb0ada 384 int perms, int w, int h);
ad2c9501 385
43c7a01e
AK
386/** Default handler for query_formats() */
387attribute_deprecated
388int avfilter_default_query_formats(AVFilterContext *ctx);
389#endif
390
c04c533f 391#if FF_API_FILTERS_PUBLIC
91d1c741 392/** start_frame() handler for filters which simply pass video along */
c04c533f 393attribute_deprecated
ecc8dada 394void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
91d1c741
BB
395
396/** draw_slice() handler for filters which simply pass video along */
c04c533f 397attribute_deprecated
91d1c741
BB
398void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
399
400/** end_frame() handler for filters which simply pass video along */
c04c533f 401attribute_deprecated
91d1c741
BB
402void avfilter_null_end_frame(AVFilterLink *link);
403
404/** get_video_buffer() handler for filters which simply pass video along */
c04c533f 405attribute_deprecated
ecc8dada 406AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
91d1c741 407 int perms, int w, int h);
c04c533f 408#endif
91d1c741 409
13ff8fd0 410/**
38efe768 411 * Filter definition. This defines the pads a filter contains, and all the
13ff8fd0
VS
412 * callback functions used to interact with the filter.
413 */
f607cc18 414typedef struct AVFilter {
2844dd39 415 const char *name; ///< filter name
a5cbb2f4 416
13ff8fd0 417 int priv_size; ///< size of private data to allocate for the filter
a5cbb2f4 418
4d96a914 419 /**
38efe768
SS
420 * Filter initialization function. Args contains the user-supplied
421 * parameters. FIXME: maybe an AVOption-based system would be better?
6e365c57
VS
422 * opaque is data provided by the code requesting creation of the filter,
423 * and is used to pass data to the filter.
4d96a914 424 */
95bcf498 425 int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
13ff8fd0
VS
426
427 /**
38efe768 428 * Filter uninitialization function. Should deallocate any memory held
7fce481a 429 * by the filter, release any buffer references, etc. This does not need
13ff8fd0
VS
430 * to deallocate the AVFilterContext->priv memory itself.
431 */
a5cbb2f4
VS
432 void (*uninit)(AVFilterContext *ctx);
433
35f3fdf4 434 /**
c4d2e41c 435 * Queries formats supported by the filter and its pads, and sets the
35f3fdf4
VS
436 * in_formats for links connected to its output pads, and out_formats
437 * for links connected to its input pads.
438 *
fe592585
SS
439 * @return zero on success, a negative value corresponding to an
440 * AVERROR code otherwise
35f3fdf4
VS
441 */
442 int (*query_formats)(AVFilterContext *);
443
13ff8fd0
VS
444 const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
445 const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
cccd292a
SS
446
447 /**
448 * A description for the filter. You should use the
449 * NULL_IF_CONFIG_SMALL() macro to define it.
450 */
451 const char *description;
a5cbb2f4
VS
452} AVFilter;
453
13ff8fd0 454/** An instance of a filter */
f607cc18 455struct AVFilterContext {
d42a814e 456 const AVClass *av_class; ///< needed for av_log()
a5cbb2f4 457
664f6595 458 AVFilter *filter; ///< the AVFilter of which this is an instance
a5cbb2f4 459
13ff8fd0 460 char *name; ///< name of this filter instance
dcea2482 461
13ff8fd0
VS
462 unsigned input_count; ///< number of input pads
463 AVFilterPad *input_pads; ///< array of input pads
464 AVFilterLink **inputs; ///< array of pointers to input links
25f8e601 465
13ff8fd0
VS
466 unsigned output_count; ///< number of output pads
467 AVFilterPad *output_pads; ///< array of output pads
468 AVFilterLink **outputs; ///< array of pointers to output links
a5cbb2f4 469
13ff8fd0 470 void *priv; ///< private data for use by the filter
a5cbb2f4
VS
471};
472
13ff8fd0 473/**
38efe768 474 * A link between two filters. This contains pointers to the source and
f4433de9 475 * destination filters between which this link exists, and the indexes of
38efe768 476 * the pads involved. In addition, this link also contains the parameters
13ff8fd0 477 * which have been negotiated and agreed upon between the filter, such as
2b187df9 478 * image dimensions, format, etc.
13ff8fd0 479 */
f607cc18 480struct AVFilterLink {
13ff8fd0 481 AVFilterContext *src; ///< source filter
acc0490f 482 AVFilterPad *srcpad; ///< output pad on the source filter
a5cbb2f4 483
13ff8fd0 484 AVFilterContext *dst; ///< dest filter
acc0490f 485 AVFilterPad *dstpad; ///< input pad on the dest filter
a5cbb2f4 486
24c4eff6
VS
487 /** stage of the initialization of the link properties (dimensions, etc) */
488 enum {
489 AVLINK_UNINIT = 0, ///< not started
490 AVLINK_STARTINIT, ///< started, but incomplete
491 AVLINK_INIT ///< complete
492 } init_state;
493
bdab614b
HM
494 enum AVMediaType type; ///< filter media type
495
910b5b82 496 /* These parameters apply only to video */
13ff8fd0
VS
497 int w; ///< agreed upon image width
498 int h; ///< agreed upon image height
910b5b82 499 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
ad2c9501 500 /* These two parameters apply only to audio */
cc276c85 501 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/audioconvert.h)
f20ab492 502#if FF_API_SAMPLERATE64
ad2c9501 503 int64_t sample_rate; ///< samples per second
f20ab492
AK
504#else
505 int sample_rate; ///< samples per second
506#endif
ad2c9501 507
bdab614b 508 int format; ///< agreed upon media format
a5cbb2f4 509
60bf6ce3 510 /**
35f3fdf4
VS
511 * Lists of formats supported by the input and output filters respectively.
512 * These lists are used for negotiating the format to actually be used,
513 * which will be loaded into the format member, above, when chosen.
514 */
515 AVFilterFormats *in_formats;
516 AVFilterFormats *out_formats;
517
518 /**
7fce481a 519 * The buffer reference currently being sent across the link by the source
38efe768 520 * filter. This is used internally by the filter system to allow
7fce481a 521 * automatic copying of buffers which do not have sufficient permissions
38efe768 522 * for the destination. This should not be accessed directly by the
60bf6ce3
VS
523 * filters.
524 */
5d4890d7 525 AVFilterBufferRef *src_buf;
60bf6ce3 526
5d4890d7
HM
527 AVFilterBufferRef *cur_buf;
528 AVFilterBufferRef *out_buf;
867ae7aa
SS
529
530 /**
531 * Define the time base used by the PTS of the frames/samples
532 * which will pass through this link.
533 * During the configuration stage, each filter is supposed to
534 * change only the output timebase, while the timebase of the
535 * input link is assumed to be an unchangeable property.
536 */
537 AVRational time_base;
5775a183
AK
538
539 /*****************************************************************
540 * All fields below this line are not part of the public API. They
541 * may not be used outside of libavfilter and can be changed and
542 * removed at will.
543 * New public fields should be added right above.
544 *****************************************************************
545 */
546 /**
547 * Lists of channel layouts and sample rates used for automatic
548 * negotiation.
549 */
550 AVFilterFormats *in_samplerates;
551 AVFilterFormats *out_samplerates;
552 struct AVFilterChannelLayouts *in_channel_layouts;
553 struct AVFilterChannelLayouts *out_channel_layouts;
a5cbb2f4
VS
554};
555
13ff8fd0 556/**
49bd8e4b 557 * Link two filters together.
3fa3e4f4 558 *
664f6595
VS
559 * @param src the source filter
560 * @param srcpad index of the output pad on the source filter
561 * @param dst the destination filter
562 * @param dstpad index of the input pad on the destination filter
563 * @return zero on success
13ff8fd0 564 */
a5cbb2f4
VS
565int avfilter_link(AVFilterContext *src, unsigned srcpad,
566 AVFilterContext *dst, unsigned dstpad);
567
13ff8fd0 568/**
bdab614b 569 * Negotiate the media format, dimensions, etc of all inputs to a filter.
3fa3e4f4 570 *
664f6595
VS
571 * @param filter the filter to negotiate the properties for its inputs
572 * @return zero on successful negotiation
13ff8fd0 573 */
24c4eff6 574int avfilter_config_links(AVFilterContext *filter);
85322466 575
6d58358a
AK
576#if FF_API_FILTERS_PUBLIC
577attribute_deprecated
ecc8dada 578AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
0eb4ff9e 579 int w, int h);
6d58358a 580#endif
13ff8fd0
VS
581
582/**
d38c340f
SS
583 * Create a buffer reference wrapped around an already allocated image
584 * buffer.
585 *
586 * @param data pointers to the planes of the image to reference
587 * @param linesize linesizes for the planes of the image to reference
588 * @param perms the required access permissions
589 * @param w the width of the image specified by the data and linesize arrays
590 * @param h the height of the image specified by the data and linesize arrays
591 * @param format the pixel format of the image specified by the data and linesize arrays
592 */
593AVFilterBufferRef *
594avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
595 int w, int h, enum PixelFormat format);
596
597/**
1b8c9271
SS
598 * Create an audio buffer reference wrapped around an already
599 * allocated samples buffer.
600 *
601 * @param data pointers to the samples plane buffers
602 * @param linesize linesize for the samples plane buffers
603 * @param perms the required access permissions
604 * @param nb_samples number of samples per channel
605 * @param sample_fmt the format of each sample in the buffer to allocate
606 * @param channel_layout the channel layout of the buffer
607 */
608AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
609 int linesize,
610 int perms,
611 int nb_samples,
612 enum AVSampleFormat sample_fmt,
613 uint64_t channel_layout);
614
803391f7
AK
615#if FF_API_FILTERS_PUBLIC
616attribute_deprecated
0155b1a1 617int avfilter_request_frame(AVFilterLink *link);
13ff8fd0 618
803391f7 619attribute_deprecated
b04c740a
VS
620int avfilter_poll_frame(AVFilterLink *link);
621
803391f7 622attribute_deprecated
ecc8dada 623void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
803391f7 624attribute_deprecated
a5cbb2f4 625void avfilter_end_frame(AVFilterLink *link);
803391f7 626attribute_deprecated
a13a5437 627void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
803391f7 628#endif
a5cbb2f4 629
49bd8e4b 630/** Initialize the filter system. Register all builtin filters. */
11de6cac 631void avfilter_register_all(void);
e4152452 632
49bd8e4b 633/** Uninitialize the filter system. Unregister all filters. */
a5cbb2f4 634void avfilter_uninit(void);
13ff8fd0
VS
635
636/**
49bd8e4b 637 * Register a filter. This is only needed if you plan to use
fc815c56
VS
638 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
639 * filter can still by instantiated with avfilter_open even if it is not
640 * registered.
3fa3e4f4 641 *
664f6595 642 * @param filter the filter to register
86a60fa1
SS
643 * @return 0 if the registration was succesfull, a negative value
644 * otherwise
13ff8fd0 645 */
86a60fa1 646int avfilter_register(AVFilter *filter);
13ff8fd0
VS
647
648/**
49bd8e4b 649 * Get a filter definition matching the given name.
3fa3e4f4 650 *
664f6595
VS
651 * @param name the filter name to find
652 * @return the filter definition, if any matching one is registered.
13ff8fd0
VS
653 * NULL if none found.
654 */
2844dd39 655AVFilter *avfilter_get_by_name(const char *name);
a5cbb2f4 656
13ff8fd0 657/**
1433c4ab
SS
658 * If filter is NULL, returns a pointer to the first registered filter pointer,
659 * if filter is non-NULL, returns the next pointer after filter.
660 * If the returned pointer points to NULL, the last registered filter
661 * was already reached.
662 */
663AVFilter **av_filter_next(AVFilter **filter);
664
665/**
49bd8e4b 666 * Create a filter instance.
84c03869
SS
667 *
668 * @param filter_ctx put here a pointer to the created filter context
669 * on success, NULL on failure
664f6595 670 * @param filter the filter to create an instance of
38efe768 671 * @param inst_name Name to give to the new instance. Can be NULL for none.
84c03869 672 * @return >= 0 in case of success, a negative error code otherwise
13ff8fd0 673 */
84c03869 674int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
13ff8fd0
VS
675
676/**
49bd8e4b 677 * Initialize a filter.
3fa3e4f4 678 *
664f6595 679 * @param filter the filter to initialize
13ff8fd0
VS
680 * @param args A string of parameters to use when initializing the filter.
681 * The format and meaning of this string varies by filter.
38efe768 682 * @param opaque Any extra non-string data needed by the filter. The meaning
13ff8fd0 683 * of this parameter varies by filter.
664f6595 684 * @return zero on success
13ff8fd0 685 */
6e365c57 686int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
13ff8fd0
VS
687
688/**
24de0edb 689 * Free a filter context.
3fa3e4f4 690 *
24de0edb 691 * @param filter the filter to free
13ff8fd0 692 */
24de0edb 693void avfilter_free(AVFilterContext *filter);
a5cbb2f4 694
13ff8fd0 695/**
49bd8e4b 696 * Insert a filter in the middle of an existing link.
3fa3e4f4 697 *
664f6595
VS
698 * @param link the link into which the filter should be inserted
699 * @param filt the filter to be inserted
486adc55
SS
700 * @param filt_srcpad_idx the input pad on the filter to connect
701 * @param filt_dstpad_idx the output pad on the filter to connect
664f6595 702 * @return zero on success
13ff8fd0 703 */
35f3fdf4 704int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
486adc55 705 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
d3e57c15 706
fa417fcd
AK
707#if FF_API_FILTERS_PUBLIC
708attribute_deprecated
a9c81431
VS
709void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
710 AVFilterPad **pads, AVFilterLink ***links,
711 AVFilterPad *newpad);
712
fa417fcd
AK
713attribute_deprecated
714void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
715 AVFilterPad *p);
716attribute_deprecated
717void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
718 AVFilterPad *p);
719#endif
a9c81431 720
1c9e340d
SS
721/**
722 * Copy the frame properties of src to dst, without copying the actual
723 * image data.
724 *
725 * @return 0 on success, a negative number on error.
726 */
727int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
728
ab165047
AK
729/**
730 * Copy the frame properties and data pointers of src to dst, without copying
731 * the actual data.
732 *
733 * @return 0 on success, a negative number on error.
734 */
735int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
736
153382e1 737#endif /* AVFILTER_AVFILTER_H */