lavfi: Drop deprecated public AVFilterPad struct
[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
bf4b0ed1 36#include "libavutil/attributes.h"
1f20782c 37#include "libavutil/avutil.h"
7e350379 38#include "libavutil/frame.h"
abc78a5a 39#include "libavutil/log.h"
737eb597 40#include "libavutil/samplefmt.h"
d49ea4af 41#include "libavutil/pixfmt.h"
e91709ca 42#include "libavutil/rational.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
84b9fbe0 231/**
7e8fe4be
AK
232 * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
233 * AVFilter.inputs/outputs).
234 */
235int avfilter_pad_count(const AVFilterPad *pads);
236
237/**
84b9fbe0
AK
238 * Get the name of an AVFilterPad.
239 *
240 * @param pads an array of AVFilterPads
241 * @param pad_idx index of the pad in the array it; is the caller's
242 * responsibility to ensure the index is valid
243 *
244 * @return name of the pad_idx'th pad in pads
245 */
4a37d4b3 246const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
84b9fbe0
AK
247
248/**
249 * Get the type of an AVFilterPad.
250 *
251 * @param pads an array of AVFilterPads
252 * @param pad_idx index of the pad in the array; it is the caller's
253 * responsibility to ensure the index is valid
254 *
255 * @return type of the pad_idx'th pad in pads
256 */
4a37d4b3 257enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
84b9fbe0 258
13ff8fd0 259/**
7cdd737b
AK
260 * The number of the filter inputs is not determined just by AVFilter.inputs.
261 * The filter might add additional inputs during initialization depending on the
262 * options supplied to it.
263 */
264#define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
265/**
266 * The number of the filter outputs is not determined just by AVFilter.outputs.
267 * The filter might add additional outputs during initialization depending on
268 * the options supplied to it.
269 */
270#define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
129bb238
AK
271/**
272 * The filter supports multithreading by splitting frames into multiple parts
273 * and processing them concurrently.
274 */
275#define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
7cdd737b
AK
276
277/**
38efe768 278 * Filter definition. This defines the pads a filter contains, and all the
13ff8fd0
VS
279 * callback functions used to interact with the filter.
280 */
f607cc18 281typedef struct AVFilter {
8b7dffc2
AK
282 /**
283 * Filter name. Must be non-NULL and unique among filters.
284 */
285 const char *name;
a5cbb2f4 286
96180805 287 /**
8b7dffc2
AK
288 * A description of the filter. May be NULL.
289 *
290 * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
96180805
AK
291 */
292 const char *description;
293
8b7dffc2
AK
294 /**
295 * List of inputs, terminated by a zeroed element.
296 *
297 * NULL if there are no (static) inputs. Instances of filters with
298 * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
299 * this list.
300 */
301 const AVFilterPad *inputs;
302 /**
303 * List of outputs, terminated by a zeroed element.
304 *
305 * NULL if there are no (static) outputs. Instances of filters with
306 * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
307 * this list.
308 */
309 const AVFilterPad *outputs;
96180805 310
b439c992 311 /**
8b7dffc2
AK
312 * A class for the private data, used to declare filter private AVOptions.
313 * This field is NULL for filters that do not declare any options.
314 *
315 * If this field is non-NULL, the first member of the filter private data
316 * must be a pointer to AVClass, which will be set by libavfilter generic
317 * code to this class.
b439c992
AK
318 */
319 const AVClass *priv_class;
320
7cdd737b
AK
321 /**
322 * A combination of AVFILTER_FLAG_*
323 */
324 int flags;
325
96180805
AK
326 /*****************************************************************
327 * All fields below this line are not part of the public API. They
328 * may not be used outside of libavfilter and can be changed and
329 * removed at will.
330 * New public fields should be added right above.
331 *****************************************************************
332 */
a5cbb2f4 333
4d96a914 334 /**
8b7dffc2
AK
335 * Filter initialization function.
336 *
337 * This callback will be called only once during the filter lifetime, after
338 * all the options have been set, but before links between filters are
339 * established and format negotiation is done.
340 *
341 * Basic filter initialization should be done here. Filters with dynamic
342 * inputs and/or outputs should create those inputs/outputs here based on
343 * provided options. No more changes to this filter's inputs/outputs can be
344 * done after this callback.
345 *
346 * This callback must not assume that the filter links exist or frame
347 * parameters are known.
348 *
349 * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
350 * initialization fails, so this callback does not have to clean up on
351 * failure.
352 *
353 * @return 0 on success, a negative AVERROR on failure
4d96a914 354 */
c43a7eca 355 int (*init)(AVFilterContext *ctx);
13ff8fd0
VS
356
357 /**
8b7dffc2
AK
358 * Should be set instead of @ref AVFilter.init "init" by the filters that
359 * want to pass a dictionary of AVOptions to nested contexts that are
360 * allocated during init.
361 *
362 * On return, the options dict should be freed and replaced with one that
363 * contains all the options which could not be processed by this filter (or
364 * with NULL if all the options were processed).
365 *
366 * Otherwise the semantics is the same as for @ref AVFilter.init "init".
4fa1f52e
AK
367 */
368 int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
369
370 /**
8b7dffc2
AK
371 * Filter uninitialization function.
372 *
373 * Called only once right before the filter is freed. Should deallocate any
374 * memory held by the filter, release any buffer references, etc. It does
375 * not need to deallocate the AVFilterContext.priv memory itself.
376 *
377 * This callback may be called even if @ref AVFilter.init "init" was not
378 * called or failed, so it must be prepared to handle such a situation.
13ff8fd0 379 */
a5cbb2f4
VS
380 void (*uninit)(AVFilterContext *ctx);
381
35f3fdf4 382 /**
8b7dffc2
AK
383 * Query formats supported by the filter on its inputs and outputs.
384 *
385 * This callback is called after the filter is initialized (so the inputs
386 * and outputs are fixed), shortly before the format negotiation. This
387 * callback may be called more than once.
388 *
389 * This callback must set AVFilterLink.out_formats on every input link and
390 * AVFilterLink.in_formats on every output link to a list of pixel/sample
391 * formats that the filter supports on that link. For audio links, this
392 * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
393 * @ref AVFilterLink.out_samplerates "out_samplerates" and
394 * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
395 * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
396 *
397 * This callback may be NULL for filters with one input, in which case
398 * libavfilter assumes that it supports all input formats and preserves
399 * them on output.
35f3fdf4 400 *
fe592585
SS
401 * @return zero on success, a negative value corresponding to an
402 * AVERROR code otherwise
35f3fdf4
VS
403 */
404 int (*query_formats)(AVFilterContext *);
405
96180805 406 int priv_size; ///< size of private data to allocate for the filter
fa2a34cd 407
8b7dffc2
AK
408 /**
409 * Used by the filter registration system. Must not be touched by any other
410 * code.
411 */
fa2a34cd 412 struct AVFilter *next;
a5cbb2f4
VS
413} AVFilter;
414
129bb238
AK
415/**
416 * Process multiple parts of the frame concurrently.
417 */
418#define AVFILTER_THREAD_SLICE (1 << 0)
419
420typedef struct AVFilterInternal AVFilterInternal;
421
13ff8fd0 422/** An instance of a filter */
f607cc18 423struct AVFilterContext {
d42a814e 424 const AVClass *av_class; ///< needed for av_log()
a5cbb2f4 425
91d2efa7 426 const AVFilter *filter; ///< the AVFilter of which this is an instance
a5cbb2f4 427
13ff8fd0 428 char *name; ///< name of this filter instance
dcea2482 429
f892013a
AK
430 AVFilterPad *input_pads; ///< array of input pads
431 AVFilterLink **inputs; ///< array of pointers to input links
9baeff95 432#if FF_API_FOO_COUNT
bf4b0ed1 433 attribute_deprecated unsigned input_count; ///< @deprecated use nb_inputs
9baeff95 434#endif
f892013a 435 unsigned nb_inputs; ///< number of input pads
25f8e601 436
f892013a
AK
437 AVFilterPad *output_pads; ///< array of output pads
438 AVFilterLink **outputs; ///< array of pointers to output links
9baeff95 439#if FF_API_FOO_COUNT
bf4b0ed1 440 attribute_deprecated unsigned output_count; ///< @deprecated use nb_outputs
9baeff95 441#endif
f892013a 442 unsigned nb_outputs; ///< number of output pads
a5cbb2f4 443
13ff8fd0 444 void *priv; ///< private data for use by the filter
11136726
AK
445
446 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
129bb238
AK
447
448 /**
449 * Type of multithreading being allowed/used. A combination of
450 * AVFILTER_THREAD_* flags.
451 *
452 * May be set by the caller before initializing the filter to forbid some
453 * or all kinds of multithreading for this filter. The default is allowing
454 * everything.
455 *
456 * When the filter is initialized, this field is combined using bit AND with
457 * AVFilterGraph.thread_type to get the final mask used for determining
458 * allowed threading types. I.e. a threading type needs to be set in both
459 * to be allowed.
460 *
461 * After the filter is initialzed, libavfilter sets this field to the
462 * threading type that is actually used (0 for no multithreading).
463 */
464 int thread_type;
465
466 /**
467 * An opaque struct for libavfilter internal use.
468 */
469 AVFilterInternal *internal;
a5cbb2f4
VS
470};
471
13ff8fd0 472/**
38efe768 473 * A link between two filters. This contains pointers to the source and
f4433de9 474 * destination filters between which this link exists, and the indexes of
38efe768 475 * the pads involved. In addition, this link also contains the parameters
13ff8fd0 476 * which have been negotiated and agreed upon between the filter, such as
2b187df9 477 * image dimensions, format, etc.
13ff8fd0 478 */
f607cc18 479struct AVFilterLink {
13ff8fd0 480 AVFilterContext *src; ///< source filter
acc0490f 481 AVFilterPad *srcpad; ///< output pad on the source filter
a5cbb2f4 482
13ff8fd0 483 AVFilterContext *dst; ///< dest filter
acc0490f 484 AVFilterPad *dstpad; ///< input pad on the dest filter
a5cbb2f4 485
bdab614b
HM
486 enum AVMediaType type; ///< filter media type
487
910b5b82 488 /* These parameters apply only to video */
13ff8fd0
VS
489 int w; ///< agreed upon image width
490 int h; ///< agreed upon image height
910b5b82 491 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
ad2c9501 492 /* These two parameters apply only to audio */
a903f8f0 493 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
f20ab492 494 int sample_rate; ///< samples per second
ad2c9501 495
bdab614b 496 int format; ///< agreed upon media format
a5cbb2f4 497
60bf6ce3 498 /**
867ae7aa
SS
499 * Define the time base used by the PTS of the frames/samples
500 * which will pass through this link.
501 * During the configuration stage, each filter is supposed to
502 * change only the output timebase, while the timebase of the
503 * input link is assumed to be an unchangeable property.
504 */
505 AVRational time_base;
5775a183
AK
506
507 /*****************************************************************
508 * All fields below this line are not part of the public API. They
509 * may not be used outside of libavfilter and can be changed and
510 * removed at will.
511 * New public fields should be added right above.
512 *****************************************************************
513 */
514 /**
83ba2239
AK
515 * Lists of formats supported by the input and output filters respectively.
516 * These lists are used for negotiating the format to actually be used,
517 * which will be loaded into the format member, above, when chosen.
518 */
519 AVFilterFormats *in_formats;
520 AVFilterFormats *out_formats;
521
522 /**
5775a183
AK
523 * Lists of channel layouts and sample rates used for automatic
524 * negotiation.
525 */
526 AVFilterFormats *in_samplerates;
527 AVFilterFormats *out_samplerates;
528 struct AVFilterChannelLayouts *in_channel_layouts;
529 struct AVFilterChannelLayouts *out_channel_layouts;
f75be985
AK
530
531 /**
532 * Audio only, the destination filter sets this to a non-zero value to
533 * request that buffers with the given number of samples should be sent to
534 * it. AVFilterPad.needs_fifo must also be set on the corresponding input
535 * pad.
536 * Last buffer before EOF will be padded with silence.
537 */
538 int request_samples;
83ba2239
AK
539
540 /** stage of the initialization of the link properties (dimensions, etc) */
541 enum {
542 AVLINK_UNINIT = 0, ///< not started
543 AVLINK_STARTINIT, ///< started, but incomplete
544 AVLINK_INIT ///< complete
545 } init_state;
a5cbb2f4
VS
546};
547
13ff8fd0 548/**
49bd8e4b 549 * Link two filters together.
3fa3e4f4 550 *
664f6595
VS
551 * @param src the source filter
552 * @param srcpad index of the output pad on the source filter
553 * @param dst the destination filter
554 * @param dstpad index of the input pad on the destination filter
555 * @return zero on success
13ff8fd0 556 */
a5cbb2f4
VS
557int avfilter_link(AVFilterContext *src, unsigned srcpad,
558 AVFilterContext *dst, unsigned dstpad);
559
13ff8fd0 560/**
bdab614b 561 * Negotiate the media format, dimensions, etc of all inputs to a filter.
3fa3e4f4 562 *
664f6595
VS
563 * @param filter the filter to negotiate the properties for its inputs
564 * @return zero on successful negotiation
13ff8fd0 565 */
24c4eff6 566int avfilter_config_links(AVFilterContext *filter);
85322466 567
7e350379 568#if FF_API_AVFILTERBUFFER
13ff8fd0 569/**
d38c340f
SS
570 * Create a buffer reference wrapped around an already allocated image
571 * buffer.
572 *
573 * @param data pointers to the planes of the image to reference
574 * @param linesize linesizes for the planes of the image to reference
575 * @param perms the required access permissions
576 * @param w the width of the image specified by the data and linesize arrays
577 * @param h the height of the image specified by the data and linesize arrays
578 * @param format the pixel format of the image specified by the data and linesize arrays
579 */
7e350379 580attribute_deprecated
d38c340f
SS
581AVFilterBufferRef *
582avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
716d413c 583 int w, int h, enum AVPixelFormat format);
d38c340f
SS
584
585/**
1b8c9271
SS
586 * Create an audio buffer reference wrapped around an already
587 * allocated samples buffer.
588 *
589 * @param data pointers to the samples plane buffers
590 * @param linesize linesize for the samples plane buffers
591 * @param perms the required access permissions
592 * @param nb_samples number of samples per channel
593 * @param sample_fmt the format of each sample in the buffer to allocate
594 * @param channel_layout the channel layout of the buffer
595 */
7e350379 596attribute_deprecated
1b8c9271
SS
597AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
598 int linesize,
599 int perms,
600 int nb_samples,
601 enum AVSampleFormat sample_fmt,
602 uint64_t channel_layout);
7e350379 603#endif
1b8c9271 604
49bd8e4b 605/** Initialize the filter system. Register all builtin filters. */
11de6cac 606void avfilter_register_all(void);
e4152452 607
fa2a34cd 608#if FF_API_OLD_FILTER_REGISTER
49bd8e4b 609/** Uninitialize the filter system. Unregister all filters. */
fa2a34cd 610attribute_deprecated
a5cbb2f4 611void avfilter_uninit(void);
fa2a34cd 612#endif
13ff8fd0
VS
613
614/**
49bd8e4b 615 * Register a filter. This is only needed if you plan to use
fc815c56 616 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
bc1a985b
AK
617 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
618 * is not registered.
3fa3e4f4 619 *
664f6595 620 * @param filter the filter to register
86a60fa1
SS
621 * @return 0 if the registration was succesfull, a negative value
622 * otherwise
13ff8fd0 623 */
86a60fa1 624int avfilter_register(AVFilter *filter);
13ff8fd0
VS
625
626/**
49bd8e4b 627 * Get a filter definition matching the given name.
3fa3e4f4 628 *
664f6595
VS
629 * @param name the filter name to find
630 * @return the filter definition, if any matching one is registered.
13ff8fd0
VS
631 * NULL if none found.
632 */
5c439b41
VG
633#if !FF_API_NOCONST_GET_NAME
634const
635#endif
2844dd39 636AVFilter *avfilter_get_by_name(const char *name);
a5cbb2f4 637
13ff8fd0 638/**
fa2a34cd
AK
639 * Iterate over all registered filters.
640 * @return If prev is non-NULL, next registered filter after prev or NULL if
641 * prev is the last filter. If prev is NULL, return the first registered filter.
642 */
643const AVFilter *avfilter_next(const AVFilter *prev);
644
645#if FF_API_OLD_FILTER_REGISTER
646/**
1433c4ab
SS
647 * If filter is NULL, returns a pointer to the first registered filter pointer,
648 * if filter is non-NULL, returns the next pointer after filter.
649 * If the returned pointer points to NULL, the last registered filter
650 * was already reached.
fa2a34cd 651 * @deprecated use avfilter_next()
1433c4ab 652 */
fa2a34cd 653attribute_deprecated
1433c4ab 654AVFilter **av_filter_next(AVFilter **filter);
fa2a34cd 655#endif
1433c4ab 656
bc1a985b 657#if FF_API_AVFILTER_OPEN
1433c4ab 658/**
49bd8e4b 659 * Create a filter instance.
84c03869
SS
660 *
661 * @param filter_ctx put here a pointer to the created filter context
662 * on success, NULL on failure
664f6595 663 * @param filter the filter to create an instance of
38efe768 664 * @param inst_name Name to give to the new instance. Can be NULL for none.
84c03869 665 * @return >= 0 in case of success, a negative error code otherwise
bc1a985b 666 * @deprecated use avfilter_graph_alloc_filter() instead
13ff8fd0 667 */
bc1a985b 668attribute_deprecated
84c03869 669int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
bc1a985b 670#endif
13ff8fd0 671
48a5adab
AK
672
673#if FF_API_AVFILTER_INIT_FILTER
13ff8fd0 674/**
49bd8e4b 675 * Initialize a filter.
3fa3e4f4 676 *
664f6595 677 * @param filter the filter to initialize
13ff8fd0
VS
678 * @param args A string of parameters to use when initializing the filter.
679 * The format and meaning of this string varies by filter.
38efe768 680 * @param opaque Any extra non-string data needed by the filter. The meaning
13ff8fd0 681 * of this parameter varies by filter.
664f6595 682 * @return zero on success
13ff8fd0 683 */
48a5adab 684attribute_deprecated
6e365c57 685int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
48a5adab
AK
686#endif
687
688/**
689 * Initialize a filter with the supplied parameters.
690 *
691 * @param ctx uninitialized filter context to initialize
692 * @param args Options to initialize the filter with. This must be a
693 * ':'-separated list of options in the 'key=value' form.
694 * May be NULL if the options have been set directly using the
695 * AVOptions API or there are no options that need to be set.
696 * @return 0 on success, a negative AVERROR on failure
697 */
698int avfilter_init_str(AVFilterContext *ctx, const char *args);
13ff8fd0
VS
699
700/**
1ba95a9c
AK
701 * Initialize a filter with the supplied dictionary of options.
702 *
703 * @param ctx uninitialized filter context to initialize
704 * @param options An AVDictionary filled with options for this filter. On
705 * return this parameter will be destroyed and replaced with
706 * a dict containing options that were not found. This dictionary
707 * must be freed by the caller.
708 * May be NULL, then this function is equivalent to
709 * avfilter_init_str() with the second parameter set to NULL.
710 * @return 0 on success, a negative AVERROR on failure
711 *
712 * @note This function and avfilter_init_str() do essentially the same thing,
713 * the difference is in manner in which the options are passed. It is up to the
714 * calling code to choose whichever is more preferable. The two functions also
715 * behave differently when some of the provided options are not declared as
716 * supported by the filter. In such a case, avfilter_init_str() will fail, but
717 * this function will leave those extra options in the options AVDictionary and
718 * continue as usual.
719 */
720int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
721
722/**
1565cbc6
AK
723 * Free a filter context. This will also remove the filter from its
724 * filtergraph's list of filters.
3fa3e4f4 725 *
24de0edb 726 * @param filter the filter to free
13ff8fd0 727 */
24de0edb 728void avfilter_free(AVFilterContext *filter);
a5cbb2f4 729
13ff8fd0 730/**
49bd8e4b 731 * Insert a filter in the middle of an existing link.
3fa3e4f4 732 *
664f6595
VS
733 * @param link the link into which the filter should be inserted
734 * @param filt the filter to be inserted
486adc55
SS
735 * @param filt_srcpad_idx the input pad on the filter to connect
736 * @param filt_dstpad_idx the output pad on the filter to connect
664f6595 737 * @return zero on success
13ff8fd0 738 */
35f3fdf4 739int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
486adc55 740 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
d3e57c15 741
7e350379 742#if FF_API_AVFILTERBUFFER
1c9e340d
SS
743/**
744 * Copy the frame properties of src to dst, without copying the actual
745 * image data.
746 *
747 * @return 0 on success, a negative number on error.
748 */
7e350379 749attribute_deprecated
1c9e340d
SS
750int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
751
ab165047
AK
752/**
753 * Copy the frame properties and data pointers of src to dst, without copying
754 * the actual data.
755 *
756 * @return 0 on success, a negative number on error.
757 */
7e350379 758attribute_deprecated
ab165047 759int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
7e350379 760#endif
ab165047 761
8114c101
AK
762/**
763 * @return AVClass for AVFilterContext.
764 *
765 * @see av_opt_find().
766 */
767const AVClass *avfilter_get_class(void);
768
129bb238
AK
769typedef struct AVFilterGraphInternal AVFilterGraphInternal;
770
0767bfd1
AK
771/**
772 * A function pointer passed to the @ref AVFilterGraph.execute callback to be
773 * executed multiple times, possibly in parallel.
774 *
775 * @param ctx the filter context the job belongs to
776 * @param arg an opaque parameter passed through from @ref
777 * AVFilterGraph.execute
778 * @param jobnr the index of the job being executed
779 * @param nb_jobs the total number of jobs
780 *
781 * @return 0 on success, a negative AVERROR on error
782 */
783typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
784
785/**
786 * A function executing multiple jobs, possibly in parallel.
787 *
788 * @param ctx the filter context to which the jobs belong
789 * @param func the function to be called multiple times
790 * @param arg the argument to be passed to func
791 * @param ret a nb_jobs-sized array to be filled with return values from each
792 * invocation of func
793 * @param nb_jobs the number of jobs to execute
794 *
795 * @return 0 on success, a negative AVERROR on error
796 */
797typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
798 void *arg, int *ret, int nb_jobs);
799
38f0c078
AK
800typedef struct AVFilterGraph {
801 const AVClass *av_class;
802#if FF_API_FOO_COUNT
803 attribute_deprecated
804 unsigned filter_count;
805#endif
806 AVFilterContext **filters;
807#if !FF_API_FOO_COUNT
808 unsigned nb_filters;
809#endif
810
811 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
812 char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
813#if FF_API_FOO_COUNT
814 unsigned nb_filters;
815#endif
129bb238
AK
816
817 /**
818 * Type of multithreading allowed for filters in this graph. A combination
819 * of AVFILTER_THREAD_* flags.
820 *
821 * May be set by the caller at any point, the setting will apply to all
822 * filters initialized after that. The default is allowing everything.
823 *
824 * When a filter in this graph is initialized, this field is combined using
825 * bit AND with AVFilterContext.thread_type to get the final mask used for
826 * determining allowed threading types. I.e. a threading type needs to be
827 * set in both to be allowed.
828 */
829 int thread_type;
830
831 /**
832 * Maximum number of threads used by filters in this graph. May be set by
833 * the caller before adding any filters to the filtergraph. Zero (the
834 * default) means that the number of threads is determined automatically.
835 */
836 int nb_threads;
837
838 /**
839 * Opaque object for libavfilter internal use.
840 */
841 AVFilterGraphInternal *internal;
0767bfd1
AK
842
843 /**
844 * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
845 * be used from callbacks like @ref AVFilterGraph.execute.
846 * Libavfilter will not touch this field in any way.
847 */
848 void *opaque;
849
850 /**
851 * This callback may be set by the caller immediately after allocating the
852 * graph and before adding any filters to it, to provide a custom
853 * multithreading implementation.
854 *
855 * If set, filters with slice threading capability will call this callback
856 * to execute multiple jobs in parallel.
857 *
858 * If this field is left unset, libavfilter will use its internal
859 * implementation, which may or may not be multithreaded depending on the
860 * platform and build options.
861 */
862 avfilter_execute_func *execute;
38f0c078
AK
863} AVFilterGraph;
864
865/**
866 * Allocate a filter graph.
cfe64613
FT
867 *
868 * @return the allocated filter graph on success or NULL.
38f0c078
AK
869 */
870AVFilterGraph *avfilter_graph_alloc(void);
871
872/**
bc1a985b
AK
873 * Create a new filter instance in a filter graph.
874 *
875 * @param graph graph in which the new filter will be used
876 * @param filter the filter to create an instance of
877 * @param name Name to give to the new instance (will be copied to
878 * AVFilterContext.name). This may be used by the caller to identify
879 * different filters, libavfilter itself assigns no semantics to
880 * this parameter. May be NULL.
881 *
882 * @return the context of the newly created filter instance (note that it is
883 * also retrievable directly through AVFilterGraph.filters or with
884 * avfilter_graph_get_filter()) on success or NULL or failure.
885 */
886AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
887 const AVFilter *filter,
888 const char *name);
889
890/**
38f0c078
AK
891 * Get a filter instance with name name from graph.
892 *
893 * @return the pointer to the found filter instance or NULL if it
894 * cannot be found.
895 */
896AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
897
c2c9801b 898#if FF_API_AVFILTER_OPEN
38f0c078
AK
899/**
900 * Add an existing filter instance to a filter graph.
901 *
902 * @param graphctx the filter graph
903 * @param filter the filter to be added
c2c9801b
AK
904 *
905 * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
906 * filter graph
38f0c078 907 */
c2c9801b 908attribute_deprecated
38f0c078 909int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
c2c9801b 910#endif
38f0c078
AK
911
912/**
913 * Create and add a filter instance into an existing graph.
914 * The filter instance is created from the filter filt and inited
915 * with the parameters args and opaque.
916 *
917 * In case of success put in *filt_ctx the pointer to the created
918 * filter instance, otherwise set *filt_ctx to NULL.
919 *
920 * @param name the instance name to give to the created filter instance
921 * @param graph_ctx the filter graph
922 * @return a negative AVERROR error code in case of failure, a non
923 * negative value otherwise
924 */
77cc958f 925int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
38f0c078
AK
926 const char *name, const char *args, void *opaque,
927 AVFilterGraph *graph_ctx);
928
929/**
930 * Check validity and configure all the links and formats in the graph.
931 *
932 * @param graphctx the filter graph
933 * @param log_ctx context used for logging
934 * @return 0 in case of success, a negative AVERROR code otherwise
935 */
936int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
937
938/**
939 * Free a graph, destroy its links, and set *graph to NULL.
940 * If *graph is NULL, do nothing.
941 */
942void avfilter_graph_free(AVFilterGraph **graph);
943
944/**
945 * A linked-list of the inputs/outputs of the filter chain.
946 *
947 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
948 * where it is used to communicate open (unlinked) inputs and outputs from and
949 * to the caller.
950 * This struct specifies, per each not connected pad contained in the graph, the
951 * filter context and the pad index required for establishing a link.
952 */
953typedef struct AVFilterInOut {
954 /** unique name for this input/output in the list */
955 char *name;
956
957 /** filter context associated to this input/output */
958 AVFilterContext *filter_ctx;
959
960 /** index of the filt_ctx pad to use for linking */
961 int pad_idx;
962
963 /** next input/input in the list, NULL if this is the last */
964 struct AVFilterInOut *next;
965} AVFilterInOut;
966
967/**
968 * Allocate a single AVFilterInOut entry.
969 * Must be freed with avfilter_inout_free().
970 * @return allocated AVFilterInOut on success, NULL on failure.
971 */
972AVFilterInOut *avfilter_inout_alloc(void);
973
974/**
975 * Free the supplied list of AVFilterInOut and set *inout to NULL.
976 * If *inout is NULL, do nothing.
977 */
978void avfilter_inout_free(AVFilterInOut **inout);
979
980/**
981 * Add a graph described by a string to a graph.
982 *
983 * @param graph the filter graph where to link the parsed graph context
984 * @param filters string to be parsed
985 * @param inputs linked list to the inputs of the graph
986 * @param outputs linked list to the outputs of the graph
987 * @return zero on success, a negative AVERROR code on error
988 */
989int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
990 AVFilterInOut *inputs, AVFilterInOut *outputs,
991 void *log_ctx);
992
993/**
994 * Add a graph described by a string to a graph.
995 *
996 * @param[in] graph the filter graph where to link the parsed graph context
997 * @param[in] filters string to be parsed
998 * @param[out] inputs a linked list of all free (unlinked) inputs of the
999 * parsed graph will be returned here. It is to be freed
1000 * by the caller using avfilter_inout_free().
1001 * @param[out] outputs a linked list of all free (unlinked) outputs of the
1002 * parsed graph will be returned here. It is to be freed by the
1003 * caller using avfilter_inout_free().
1004 * @return zero on success, a negative AVERROR code on error
1005 *
1006 * @note the difference between avfilter_graph_parse2() and
1007 * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
1008 * the lists of inputs and outputs, which therefore must be known before calling
1009 * the function. On the other hand, avfilter_graph_parse2() \em returns the
1010 * inputs and outputs that are left unlinked after parsing the graph and the
1011 * caller then deals with them. Another difference is that in
1012 * avfilter_graph_parse(), the inputs parameter describes inputs of the
1013 * <em>already existing</em> part of the graph; i.e. from the point of view of
1014 * the newly created part, they are outputs. Similarly the outputs parameter
1015 * describes outputs of the already existing filters, which are provided as
1016 * inputs to the parsed filters.
1017 * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
1018 * whatsoever to already existing parts of the graph and the inputs parameter
1019 * will on return contain inputs of the newly parsed part of the graph.
1020 * Analogously the outputs parameter will contain outputs of the newly created
1021 * filters.
1022 */
1023int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
1024 AVFilterInOut **inputs,
1025 AVFilterInOut **outputs);
1026
bc8c1cdc
AK
1027/**
1028 * @}
1029 */
1030
153382e1 1031#endif /* AVFILTER_AVFILTER_H */