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