Move get_logical_cpus() from lavc/pthread to lavu/cpu.
[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)
404
405/**
38efe768 406 * Filter definition. This defines the pads a filter contains, and all the
13ff8fd0
VS
407 * callback functions used to interact with the filter.
408 */
f607cc18 409typedef struct AVFilter {
2844dd39 410 const char *name; ///< filter name
a5cbb2f4 411
96180805
AK
412 /**
413 * A description for the filter. You should use the
414 * NULL_IF_CONFIG_SMALL() macro to define it.
415 */
416 const char *description;
417
418 const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
419 const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
420
b439c992
AK
421 /**
422 * A class for the private data, used to access filter private
423 * AVOptions.
424 */
425 const AVClass *priv_class;
426
7cdd737b
AK
427 /**
428 * A combination of AVFILTER_FLAG_*
429 */
430 int flags;
431
96180805
AK
432 /*****************************************************************
433 * All fields below this line are not part of the public API. They
434 * may not be used outside of libavfilter and can be changed and
435 * removed at will.
436 * New public fields should be added right above.
437 *****************************************************************
438 */
a5cbb2f4 439
4d96a914 440 /**
c43a7eca
AK
441 * Filter initialization function. Called when all the options have been
442 * set.
4d96a914 443 */
c43a7eca 444 int (*init)(AVFilterContext *ctx);
13ff8fd0
VS
445
446 /**
4fa1f52e
AK
447 * Should be set instead of init by the filters that want to pass a
448 * dictionary of AVOptions to nested contexts that are allocated in
449 * init.
450 */
451 int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
452
453 /**
38efe768 454 * Filter uninitialization function. Should deallocate any memory held
7fce481a 455 * by the filter, release any buffer references, etc. This does not need
13ff8fd0
VS
456 * to deallocate the AVFilterContext->priv memory itself.
457 */
a5cbb2f4
VS
458 void (*uninit)(AVFilterContext *ctx);
459
35f3fdf4 460 /**
c4d2e41c 461 * Queries formats supported by the filter and its pads, and sets the
35f3fdf4
VS
462 * in_formats for links connected to its output pads, and out_formats
463 * for links connected to its input pads.
464 *
fe592585
SS
465 * @return zero on success, a negative value corresponding to an
466 * AVERROR code otherwise
35f3fdf4
VS
467 */
468 int (*query_formats)(AVFilterContext *);
469
96180805 470 int priv_size; ///< size of private data to allocate for the filter
fa2a34cd
AK
471
472 struct AVFilter *next;
a5cbb2f4
VS
473} AVFilter;
474
13ff8fd0 475/** An instance of a filter */
f607cc18 476struct AVFilterContext {
d42a814e 477 const AVClass *av_class; ///< needed for av_log()
a5cbb2f4 478
91d2efa7 479 const AVFilter *filter; ///< the AVFilter of which this is an instance
a5cbb2f4 480
13ff8fd0 481 char *name; ///< name of this filter instance
dcea2482 482
f892013a
AK
483 AVFilterPad *input_pads; ///< array of input pads
484 AVFilterLink **inputs; ///< array of pointers to input links
9baeff95
AK
485#if FF_API_FOO_COUNT
486 unsigned input_count; ///< @deprecated use nb_inputs
487#endif
f892013a 488 unsigned nb_inputs; ///< number of input pads
25f8e601 489
f892013a
AK
490 AVFilterPad *output_pads; ///< array of output pads
491 AVFilterLink **outputs; ///< array of pointers to output links
9baeff95
AK
492#if FF_API_FOO_COUNT
493 unsigned output_count; ///< @deprecated use nb_outputs
494#endif
f892013a 495 unsigned nb_outputs; ///< number of output pads
a5cbb2f4 496
13ff8fd0 497 void *priv; ///< private data for use by the filter
11136726
AK
498
499 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
a5cbb2f4
VS
500};
501
13ff8fd0 502/**
38efe768 503 * A link between two filters. This contains pointers to the source and
f4433de9 504 * destination filters between which this link exists, and the indexes of
38efe768 505 * the pads involved. In addition, this link also contains the parameters
13ff8fd0 506 * which have been negotiated and agreed upon between the filter, such as
2b187df9 507 * image dimensions, format, etc.
13ff8fd0 508 */
f607cc18 509struct AVFilterLink {
13ff8fd0 510 AVFilterContext *src; ///< source filter
acc0490f 511 AVFilterPad *srcpad; ///< output pad on the source filter
a5cbb2f4 512
13ff8fd0 513 AVFilterContext *dst; ///< dest filter
acc0490f 514 AVFilterPad *dstpad; ///< input pad on the dest filter
a5cbb2f4 515
bdab614b
HM
516 enum AVMediaType type; ///< filter media type
517
910b5b82 518 /* These parameters apply only to video */
13ff8fd0
VS
519 int w; ///< agreed upon image width
520 int h; ///< agreed upon image height
910b5b82 521 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
ad2c9501 522 /* These two parameters apply only to audio */
a903f8f0 523 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
f20ab492 524 int sample_rate; ///< samples per second
ad2c9501 525
bdab614b 526 int format; ///< agreed upon media format
a5cbb2f4 527
60bf6ce3 528 /**
867ae7aa
SS
529 * Define the time base used by the PTS of the frames/samples
530 * which will pass through this link.
531 * During the configuration stage, each filter is supposed to
532 * change only the output timebase, while the timebase of the
533 * input link is assumed to be an unchangeable property.
534 */
535 AVRational time_base;
5775a183
AK
536
537 /*****************************************************************
538 * All fields below this line are not part of the public API. They
539 * may not be used outside of libavfilter and can be changed and
540 * removed at will.
541 * New public fields should be added right above.
542 *****************************************************************
543 */
544 /**
83ba2239
AK
545 * Lists of formats supported by the input and output filters respectively.
546 * These lists are used for negotiating the format to actually be used,
547 * which will be loaded into the format member, above, when chosen.
548 */
549 AVFilterFormats *in_formats;
550 AVFilterFormats *out_formats;
551
552 /**
5775a183
AK
553 * Lists of channel layouts and sample rates used for automatic
554 * negotiation.
555 */
556 AVFilterFormats *in_samplerates;
557 AVFilterFormats *out_samplerates;
558 struct AVFilterChannelLayouts *in_channel_layouts;
559 struct AVFilterChannelLayouts *out_channel_layouts;
f75be985
AK
560
561 /**
562 * Audio only, the destination filter sets this to a non-zero value to
563 * request that buffers with the given number of samples should be sent to
564 * it. AVFilterPad.needs_fifo must also be set on the corresponding input
565 * pad.
566 * Last buffer before EOF will be padded with silence.
567 */
568 int request_samples;
83ba2239
AK
569
570 /** stage of the initialization of the link properties (dimensions, etc) */
571 enum {
572 AVLINK_UNINIT = 0, ///< not started
573 AVLINK_STARTINIT, ///< started, but incomplete
574 AVLINK_INIT ///< complete
575 } init_state;
a5cbb2f4
VS
576};
577
13ff8fd0 578/**
49bd8e4b 579 * Link two filters together.
3fa3e4f4 580 *
664f6595
VS
581 * @param src the source filter
582 * @param srcpad index of the output pad on the source filter
583 * @param dst the destination filter
584 * @param dstpad index of the input pad on the destination filter
585 * @return zero on success
13ff8fd0 586 */
a5cbb2f4
VS
587int avfilter_link(AVFilterContext *src, unsigned srcpad,
588 AVFilterContext *dst, unsigned dstpad);
589
13ff8fd0 590/**
bdab614b 591 * Negotiate the media format, dimensions, etc of all inputs to a filter.
3fa3e4f4 592 *
664f6595
VS
593 * @param filter the filter to negotiate the properties for its inputs
594 * @return zero on successful negotiation
13ff8fd0 595 */
24c4eff6 596int avfilter_config_links(AVFilterContext *filter);
85322466 597
7e350379 598#if FF_API_AVFILTERBUFFER
13ff8fd0 599/**
d38c340f
SS
600 * Create a buffer reference wrapped around an already allocated image
601 * buffer.
602 *
603 * @param data pointers to the planes of the image to reference
604 * @param linesize linesizes for the planes of the image to reference
605 * @param perms the required access permissions
606 * @param w the width of the image specified by the data and linesize arrays
607 * @param h the height of the image specified by the data and linesize arrays
608 * @param format the pixel format of the image specified by the data and linesize arrays
609 */
7e350379 610attribute_deprecated
d38c340f
SS
611AVFilterBufferRef *
612avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
716d413c 613 int w, int h, enum AVPixelFormat format);
d38c340f
SS
614
615/**
1b8c9271
SS
616 * Create an audio buffer reference wrapped around an already
617 * allocated samples buffer.
618 *
619 * @param data pointers to the samples plane buffers
620 * @param linesize linesize for the samples plane buffers
621 * @param perms the required access permissions
622 * @param nb_samples number of samples per channel
623 * @param sample_fmt the format of each sample in the buffer to allocate
624 * @param channel_layout the channel layout of the buffer
625 */
7e350379 626attribute_deprecated
1b8c9271
SS
627AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
628 int linesize,
629 int perms,
630 int nb_samples,
631 enum AVSampleFormat sample_fmt,
632 uint64_t channel_layout);
7e350379 633#endif
1b8c9271 634
49bd8e4b 635/** Initialize the filter system. Register all builtin filters. */
11de6cac 636void avfilter_register_all(void);
e4152452 637
fa2a34cd 638#if FF_API_OLD_FILTER_REGISTER
49bd8e4b 639/** Uninitialize the filter system. Unregister all filters. */
fa2a34cd 640attribute_deprecated
a5cbb2f4 641void avfilter_uninit(void);
fa2a34cd 642#endif
13ff8fd0
VS
643
644/**
49bd8e4b 645 * Register a filter. This is only needed if you plan to use
fc815c56 646 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
bc1a985b
AK
647 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
648 * is not registered.
3fa3e4f4 649 *
664f6595 650 * @param filter the filter to register
86a60fa1
SS
651 * @return 0 if the registration was succesfull, a negative value
652 * otherwise
13ff8fd0 653 */
86a60fa1 654int avfilter_register(AVFilter *filter);
13ff8fd0
VS
655
656/**
49bd8e4b 657 * Get a filter definition matching the given name.
3fa3e4f4 658 *
664f6595
VS
659 * @param name the filter name to find
660 * @return the filter definition, if any matching one is registered.
13ff8fd0
VS
661 * NULL if none found.
662 */
2844dd39 663AVFilter *avfilter_get_by_name(const char *name);
a5cbb2f4 664
13ff8fd0 665/**
fa2a34cd
AK
666 * Iterate over all registered filters.
667 * @return If prev is non-NULL, next registered filter after prev or NULL if
668 * prev is the last filter. If prev is NULL, return the first registered filter.
669 */
670const AVFilter *avfilter_next(const AVFilter *prev);
671
672#if FF_API_OLD_FILTER_REGISTER
673/**
1433c4ab
SS
674 * If filter is NULL, returns a pointer to the first registered filter pointer,
675 * if filter is non-NULL, returns the next pointer after filter.
676 * If the returned pointer points to NULL, the last registered filter
677 * was already reached.
fa2a34cd 678 * @deprecated use avfilter_next()
1433c4ab 679 */
fa2a34cd 680attribute_deprecated
1433c4ab 681AVFilter **av_filter_next(AVFilter **filter);
fa2a34cd 682#endif
1433c4ab 683
bc1a985b 684#if FF_API_AVFILTER_OPEN
1433c4ab 685/**
49bd8e4b 686 * Create a filter instance.
84c03869
SS
687 *
688 * @param filter_ctx put here a pointer to the created filter context
689 * on success, NULL on failure
664f6595 690 * @param filter the filter to create an instance of
38efe768 691 * @param inst_name Name to give to the new instance. Can be NULL for none.
84c03869 692 * @return >= 0 in case of success, a negative error code otherwise
bc1a985b 693 * @deprecated use avfilter_graph_alloc_filter() instead
13ff8fd0 694 */
bc1a985b 695attribute_deprecated
84c03869 696int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
bc1a985b 697#endif
13ff8fd0 698
48a5adab
AK
699
700#if FF_API_AVFILTER_INIT_FILTER
13ff8fd0 701/**
49bd8e4b 702 * Initialize a filter.
3fa3e4f4 703 *
664f6595 704 * @param filter the filter to initialize
13ff8fd0
VS
705 * @param args A string of parameters to use when initializing the filter.
706 * The format and meaning of this string varies by filter.
38efe768 707 * @param opaque Any extra non-string data needed by the filter. The meaning
13ff8fd0 708 * of this parameter varies by filter.
664f6595 709 * @return zero on success
13ff8fd0 710 */
48a5adab 711attribute_deprecated
6e365c57 712int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
48a5adab
AK
713#endif
714
715/**
716 * Initialize a filter with the supplied parameters.
717 *
718 * @param ctx uninitialized filter context to initialize
719 * @param args Options to initialize the filter with. This must be a
720 * ':'-separated list of options in the 'key=value' form.
721 * May be NULL if the options have been set directly using the
722 * AVOptions API or there are no options that need to be set.
723 * @return 0 on success, a negative AVERROR on failure
724 */
725int avfilter_init_str(AVFilterContext *ctx, const char *args);
13ff8fd0
VS
726
727/**
1ba95a9c
AK
728 * Initialize a filter with the supplied dictionary of options.
729 *
730 * @param ctx uninitialized filter context to initialize
731 * @param options An AVDictionary filled with options for this filter. On
732 * return this parameter will be destroyed and replaced with
733 * a dict containing options that were not found. This dictionary
734 * must be freed by the caller.
735 * May be NULL, then this function is equivalent to
736 * avfilter_init_str() with the second parameter set to NULL.
737 * @return 0 on success, a negative AVERROR on failure
738 *
739 * @note This function and avfilter_init_str() do essentially the same thing,
740 * the difference is in manner in which the options are passed. It is up to the
741 * calling code to choose whichever is more preferable. The two functions also
742 * behave differently when some of the provided options are not declared as
743 * supported by the filter. In such a case, avfilter_init_str() will fail, but
744 * this function will leave those extra options in the options AVDictionary and
745 * continue as usual.
746 */
747int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
748
749/**
1565cbc6
AK
750 * Free a filter context. This will also remove the filter from its
751 * filtergraph's list of filters.
3fa3e4f4 752 *
24de0edb 753 * @param filter the filter to free
13ff8fd0 754 */
24de0edb 755void avfilter_free(AVFilterContext *filter);
a5cbb2f4 756
13ff8fd0 757/**
49bd8e4b 758 * Insert a filter in the middle of an existing link.
3fa3e4f4 759 *
664f6595
VS
760 * @param link the link into which the filter should be inserted
761 * @param filt the filter to be inserted
486adc55
SS
762 * @param filt_srcpad_idx the input pad on the filter to connect
763 * @param filt_dstpad_idx the output pad on the filter to connect
664f6595 764 * @return zero on success
13ff8fd0 765 */
35f3fdf4 766int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
486adc55 767 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
d3e57c15 768
7e350379 769#if FF_API_AVFILTERBUFFER
1c9e340d
SS
770/**
771 * Copy the frame properties of src to dst, without copying the actual
772 * image data.
773 *
774 * @return 0 on success, a negative number on error.
775 */
7e350379 776attribute_deprecated
1c9e340d
SS
777int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
778
ab165047
AK
779/**
780 * Copy the frame properties and data pointers of src to dst, without copying
781 * the actual data.
782 *
783 * @return 0 on success, a negative number on error.
784 */
7e350379 785attribute_deprecated
ab165047 786int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
7e350379 787#endif
ab165047 788
8114c101
AK
789/**
790 * @return AVClass for AVFilterContext.
791 *
792 * @see av_opt_find().
793 */
794const AVClass *avfilter_get_class(void);
795
38f0c078
AK
796typedef struct AVFilterGraph {
797 const AVClass *av_class;
798#if FF_API_FOO_COUNT
799 attribute_deprecated
800 unsigned filter_count;
801#endif
802 AVFilterContext **filters;
803#if !FF_API_FOO_COUNT
804 unsigned nb_filters;
805#endif
806
807 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
808 char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
809#if FF_API_FOO_COUNT
810 unsigned nb_filters;
811#endif
812} AVFilterGraph;
813
814/**
815 * Allocate a filter graph.
816 */
817AVFilterGraph *avfilter_graph_alloc(void);
818
819/**
bc1a985b
AK
820 * Create a new filter instance in a filter graph.
821 *
822 * @param graph graph in which the new filter will be used
823 * @param filter the filter to create an instance of
824 * @param name Name to give to the new instance (will be copied to
825 * AVFilterContext.name). This may be used by the caller to identify
826 * different filters, libavfilter itself assigns no semantics to
827 * this parameter. May be NULL.
828 *
829 * @return the context of the newly created filter instance (note that it is
830 * also retrievable directly through AVFilterGraph.filters or with
831 * avfilter_graph_get_filter()) on success or NULL or failure.
832 */
833AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
834 const AVFilter *filter,
835 const char *name);
836
837/**
38f0c078
AK
838 * Get a filter instance with name name from graph.
839 *
840 * @return the pointer to the found filter instance or NULL if it
841 * cannot be found.
842 */
843AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
844
c2c9801b 845#if FF_API_AVFILTER_OPEN
38f0c078
AK
846/**
847 * Add an existing filter instance to a filter graph.
848 *
849 * @param graphctx the filter graph
850 * @param filter the filter to be added
c2c9801b
AK
851 *
852 * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
853 * filter graph
38f0c078 854 */
c2c9801b 855attribute_deprecated
38f0c078 856int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
c2c9801b 857#endif
38f0c078
AK
858
859/**
860 * Create and add a filter instance into an existing graph.
861 * The filter instance is created from the filter filt and inited
862 * with the parameters args and opaque.
863 *
864 * In case of success put in *filt_ctx the pointer to the created
865 * filter instance, otherwise set *filt_ctx to NULL.
866 *
867 * @param name the instance name to give to the created filter instance
868 * @param graph_ctx the filter graph
869 * @return a negative AVERROR error code in case of failure, a non
870 * negative value otherwise
871 */
872int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
873 const char *name, const char *args, void *opaque,
874 AVFilterGraph *graph_ctx);
875
876/**
877 * Check validity and configure all the links and formats in the graph.
878 *
879 * @param graphctx the filter graph
880 * @param log_ctx context used for logging
881 * @return 0 in case of success, a negative AVERROR code otherwise
882 */
883int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
884
885/**
886 * Free a graph, destroy its links, and set *graph to NULL.
887 * If *graph is NULL, do nothing.
888 */
889void avfilter_graph_free(AVFilterGraph **graph);
890
891/**
892 * A linked-list of the inputs/outputs of the filter chain.
893 *
894 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
895 * where it is used to communicate open (unlinked) inputs and outputs from and
896 * to the caller.
897 * This struct specifies, per each not connected pad contained in the graph, the
898 * filter context and the pad index required for establishing a link.
899 */
900typedef struct AVFilterInOut {
901 /** unique name for this input/output in the list */
902 char *name;
903
904 /** filter context associated to this input/output */
905 AVFilterContext *filter_ctx;
906
907 /** index of the filt_ctx pad to use for linking */
908 int pad_idx;
909
910 /** next input/input in the list, NULL if this is the last */
911 struct AVFilterInOut *next;
912} AVFilterInOut;
913
914/**
915 * Allocate a single AVFilterInOut entry.
916 * Must be freed with avfilter_inout_free().
917 * @return allocated AVFilterInOut on success, NULL on failure.
918 */
919AVFilterInOut *avfilter_inout_alloc(void);
920
921/**
922 * Free the supplied list of AVFilterInOut and set *inout to NULL.
923 * If *inout is NULL, do nothing.
924 */
925void avfilter_inout_free(AVFilterInOut **inout);
926
927/**
928 * Add a graph described by a string to a graph.
929 *
930 * @param graph the filter graph where to link the parsed graph context
931 * @param filters string to be parsed
932 * @param inputs linked list to the inputs of the graph
933 * @param outputs linked list to the outputs of the graph
934 * @return zero on success, a negative AVERROR code on error
935 */
936int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
937 AVFilterInOut *inputs, AVFilterInOut *outputs,
938 void *log_ctx);
939
940/**
941 * Add a graph described by a string to a graph.
942 *
943 * @param[in] graph the filter graph where to link the parsed graph context
944 * @param[in] filters string to be parsed
945 * @param[out] inputs a linked list of all free (unlinked) inputs of the
946 * parsed graph will be returned here. It is to be freed
947 * by the caller using avfilter_inout_free().
948 * @param[out] outputs a linked list of all free (unlinked) outputs of the
949 * parsed graph will be returned here. It is to be freed by the
950 * caller using avfilter_inout_free().
951 * @return zero on success, a negative AVERROR code on error
952 *
953 * @note the difference between avfilter_graph_parse2() and
954 * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
955 * the lists of inputs and outputs, which therefore must be known before calling
956 * the function. On the other hand, avfilter_graph_parse2() \em returns the
957 * inputs and outputs that are left unlinked after parsing the graph and the
958 * caller then deals with them. Another difference is that in
959 * avfilter_graph_parse(), the inputs parameter describes inputs of the
960 * <em>already existing</em> part of the graph; i.e. from the point of view of
961 * the newly created part, they are outputs. Similarly the outputs parameter
962 * describes outputs of the already existing filters, which are provided as
963 * inputs to the parsed filters.
964 * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
965 * whatsoever to already existing parts of the graph and the inputs parameter
966 * will on return contain inputs of the newly parsed part of the graph.
967 * Analogously the outputs parameter will contain outputs of the newly created
968 * filters.
969 */
970int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
971 AVFilterInOut **inputs,
972 AVFilterInOut **outputs);
973
bc8c1cdc
AK
974/**
975 * @}
976 */
977
153382e1 978#endif /* AVFILTER_AVFILTER_H */