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