annotate ffmpeg/libavfilter/avfilter.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * filter layer
yading@10 3 * Copyright (c) 2007 Bobby Bingham
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 #ifndef AVFILTER_AVFILTER_H
yading@10 23 #define AVFILTER_AVFILTER_H
yading@10 24
yading@10 25 /**
yading@10 26 * @file
yading@10 27 * @ingroup lavfi
yading@10 28 * external API header
yading@10 29 */
yading@10 30
yading@10 31 /**
yading@10 32 * @defgroup lavfi Libavfilter
yading@10 33 * @{
yading@10 34 */
yading@10 35
yading@10 36 #include <stddef.h>
yading@10 37
yading@10 38 #include "libavutil/avutil.h"
yading@10 39 #include "libavutil/dict.h"
yading@10 40 #include "libavutil/frame.h"
yading@10 41 #include "libavutil/log.h"
yading@10 42 #include "libavutil/samplefmt.h"
yading@10 43 #include "libavutil/pixfmt.h"
yading@10 44 #include "libavutil/rational.h"
yading@10 45
yading@10 46 #include "libavfilter/version.h"
yading@10 47
yading@10 48 /**
yading@10 49 * Return the LIBAVFILTER_VERSION_INT constant.
yading@10 50 */
yading@10 51 unsigned avfilter_version(void);
yading@10 52
yading@10 53 /**
yading@10 54 * Return the libavfilter build-time configuration.
yading@10 55 */
yading@10 56 const char *avfilter_configuration(void);
yading@10 57
yading@10 58 /**
yading@10 59 * Return the libavfilter license.
yading@10 60 */
yading@10 61 const char *avfilter_license(void);
yading@10 62
yading@10 63 typedef struct AVFilterContext AVFilterContext;
yading@10 64 typedef struct AVFilterLink AVFilterLink;
yading@10 65 typedef struct AVFilterPad AVFilterPad;
yading@10 66 typedef struct AVFilterFormats AVFilterFormats;
yading@10 67
yading@10 68 #if FF_API_AVFILTERBUFFER
yading@10 69 /**
yading@10 70 * A reference-counted buffer data type used by the filter system. Filters
yading@10 71 * should not store pointers to this structure directly, but instead use the
yading@10 72 * AVFilterBufferRef structure below.
yading@10 73 */
yading@10 74 typedef struct AVFilterBuffer {
yading@10 75 uint8_t *data[8]; ///< buffer data for each plane/channel
yading@10 76
yading@10 77 /**
yading@10 78 * pointers to the data planes/channels.
yading@10 79 *
yading@10 80 * For video, this should simply point to data[].
yading@10 81 *
yading@10 82 * For planar audio, each channel has a separate data pointer, and
yading@10 83 * linesize[0] contains the size of each channel buffer.
yading@10 84 * For packed audio, there is just one data pointer, and linesize[0]
yading@10 85 * contains the total size of the buffer for all channels.
yading@10 86 *
yading@10 87 * Note: Both data and extended_data will always be set, but for planar
yading@10 88 * audio with more channels that can fit in data, extended_data must be used
yading@10 89 * in order to access all channels.
yading@10 90 */
yading@10 91 uint8_t **extended_data;
yading@10 92 int linesize[8]; ///< number of bytes per line
yading@10 93
yading@10 94 /** private data to be used by a custom free function */
yading@10 95 void *priv;
yading@10 96 /**
yading@10 97 * A pointer to the function to deallocate this buffer if the default
yading@10 98 * function is not sufficient. This could, for example, add the memory
yading@10 99 * back into a memory pool to be reused later without the overhead of
yading@10 100 * reallocating it from scratch.
yading@10 101 */
yading@10 102 void (*free)(struct AVFilterBuffer *buf);
yading@10 103
yading@10 104 int format; ///< media format
yading@10 105 int w, h; ///< width and height of the allocated buffer
yading@10 106 unsigned refcount; ///< number of references to this buffer
yading@10 107 } AVFilterBuffer;
yading@10 108
yading@10 109 #define AV_PERM_READ 0x01 ///< can read from the buffer
yading@10 110 #define AV_PERM_WRITE 0x02 ///< can write to the buffer
yading@10 111 #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
yading@10 112 #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
yading@10 113 #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
yading@10 114 #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
yading@10 115 #define AV_PERM_ALIGN 0x40 ///< the buffer must be aligned
yading@10 116
yading@10 117 #define AVFILTER_ALIGN 16 //not part of ABI
yading@10 118
yading@10 119 /**
yading@10 120 * Audio specific properties in a reference to an AVFilterBuffer. Since
yading@10 121 * AVFilterBufferRef is common to different media formats, audio specific
yading@10 122 * per reference properties must be separated out.
yading@10 123 */
yading@10 124 typedef struct AVFilterBufferRefAudioProps {
yading@10 125 uint64_t channel_layout; ///< channel layout of audio buffer
yading@10 126 int nb_samples; ///< number of audio samples per channel
yading@10 127 int sample_rate; ///< audio buffer sample rate
yading@10 128 int channels; ///< number of channels (do not access directly)
yading@10 129 } AVFilterBufferRefAudioProps;
yading@10 130
yading@10 131 /**
yading@10 132 * Video specific properties in a reference to an AVFilterBuffer. Since
yading@10 133 * AVFilterBufferRef is common to different media formats, video specific
yading@10 134 * per reference properties must be separated out.
yading@10 135 */
yading@10 136 typedef struct AVFilterBufferRefVideoProps {
yading@10 137 int w; ///< image width
yading@10 138 int h; ///< image height
yading@10 139 AVRational sample_aspect_ratio; ///< sample aspect ratio
yading@10 140 int interlaced; ///< is frame interlaced
yading@10 141 int top_field_first; ///< field order
yading@10 142 enum AVPictureType pict_type; ///< picture type of the frame
yading@10 143 int key_frame; ///< 1 -> keyframe, 0-> not
yading@10 144 int qp_table_linesize; ///< qp_table stride
yading@10 145 int qp_table_size; ///< qp_table size
yading@10 146 int8_t *qp_table; ///< array of Quantization Parameters
yading@10 147 } AVFilterBufferRefVideoProps;
yading@10 148
yading@10 149 /**
yading@10 150 * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
yading@10 151 * a buffer to, for example, crop image without any memcpy, the buffer origin
yading@10 152 * and dimensions are per-reference properties. Linesize is also useful for
yading@10 153 * image flipping, frame to field filters, etc, and so is also per-reference.
yading@10 154 *
yading@10 155 * TODO: add anything necessary for frame reordering
yading@10 156 */
yading@10 157 typedef struct AVFilterBufferRef {
yading@10 158 AVFilterBuffer *buf; ///< the buffer that this is a reference to
yading@10 159 uint8_t *data[8]; ///< picture/audio data for each plane
yading@10 160 /**
yading@10 161 * pointers to the data planes/channels.
yading@10 162 *
yading@10 163 * For video, this should simply point to data[].
yading@10 164 *
yading@10 165 * For planar audio, each channel has a separate data pointer, and
yading@10 166 * linesize[0] contains the size of each channel buffer.
yading@10 167 * For packed audio, there is just one data pointer, and linesize[0]
yading@10 168 * contains the total size of the buffer for all channels.
yading@10 169 *
yading@10 170 * Note: Both data and extended_data will always be set, but for planar
yading@10 171 * audio with more channels that can fit in data, extended_data must be used
yading@10 172 * in order to access all channels.
yading@10 173 */
yading@10 174 uint8_t **extended_data;
yading@10 175 int linesize[8]; ///< number of bytes per line
yading@10 176
yading@10 177 AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
yading@10 178 AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
yading@10 179
yading@10 180 /**
yading@10 181 * presentation timestamp. The time unit may change during
yading@10 182 * filtering, as it is specified in the link and the filter code
yading@10 183 * may need to rescale the PTS accordingly.
yading@10 184 */
yading@10 185 int64_t pts;
yading@10 186 int64_t pos; ///< byte position in stream, -1 if unknown
yading@10 187
yading@10 188 int format; ///< media format
yading@10 189
yading@10 190 int perms; ///< permissions, see the AV_PERM_* flags
yading@10 191
yading@10 192 enum AVMediaType type; ///< media type of buffer data
yading@10 193
yading@10 194 AVDictionary *metadata; ///< dictionary containing metadata key=value tags
yading@10 195 } AVFilterBufferRef;
yading@10 196
yading@10 197 /**
yading@10 198 * Copy properties of src to dst, without copying the actual data
yading@10 199 */
yading@10 200 attribute_deprecated
yading@10 201 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
yading@10 202
yading@10 203 /**
yading@10 204 * Add a new reference to a buffer.
yading@10 205 *
yading@10 206 * @param ref an existing reference to the buffer
yading@10 207 * @param pmask a bitmask containing the allowable permissions in the new
yading@10 208 * reference
yading@10 209 * @return a new reference to the buffer with the same properties as the
yading@10 210 * old, excluding any permissions denied by pmask
yading@10 211 */
yading@10 212 attribute_deprecated
yading@10 213 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
yading@10 214
yading@10 215 /**
yading@10 216 * Remove a reference to a buffer. If this is the last reference to the
yading@10 217 * buffer, the buffer itself is also automatically freed.
yading@10 218 *
yading@10 219 * @param ref reference to the buffer, may be NULL
yading@10 220 *
yading@10 221 * @note it is recommended to use avfilter_unref_bufferp() instead of this
yading@10 222 * function
yading@10 223 */
yading@10 224 attribute_deprecated
yading@10 225 void avfilter_unref_buffer(AVFilterBufferRef *ref);
yading@10 226
yading@10 227 /**
yading@10 228 * Remove a reference to a buffer and set the pointer to NULL.
yading@10 229 * If this is the last reference to the buffer, the buffer itself
yading@10 230 * is also automatically freed.
yading@10 231 *
yading@10 232 * @param ref pointer to the buffer reference
yading@10 233 */
yading@10 234 attribute_deprecated
yading@10 235 void avfilter_unref_bufferp(AVFilterBufferRef **ref);
yading@10 236 #endif
yading@10 237
yading@10 238 /**
yading@10 239 * Get the number of channels of a buffer reference.
yading@10 240 */
yading@10 241 attribute_deprecated
yading@10 242 int avfilter_ref_get_channels(AVFilterBufferRef *ref);
yading@10 243
yading@10 244 #if FF_API_AVFILTERPAD_PUBLIC
yading@10 245 /**
yading@10 246 * A filter pad used for either input or output.
yading@10 247 *
yading@10 248 * See doc/filter_design.txt for details on how to implement the methods.
yading@10 249 *
yading@10 250 * @warning this struct might be removed from public API.
yading@10 251 * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
yading@10 252 * to access the name and type fields; there should be no need to access
yading@10 253 * any other fields from outside of libavfilter.
yading@10 254 */
yading@10 255 struct AVFilterPad {
yading@10 256 /**
yading@10 257 * Pad name. The name is unique among inputs and among outputs, but an
yading@10 258 * input may have the same name as an output. This may be NULL if this
yading@10 259 * pad has no need to ever be referenced by name.
yading@10 260 */
yading@10 261 const char *name;
yading@10 262
yading@10 263 /**
yading@10 264 * AVFilterPad type.
yading@10 265 */
yading@10 266 enum AVMediaType type;
yading@10 267
yading@10 268 /**
yading@10 269 * Input pads:
yading@10 270 * Minimum required permissions on incoming buffers. Any buffer with
yading@10 271 * insufficient permissions will be automatically copied by the filter
yading@10 272 * system to a new buffer which provides the needed access permissions.
yading@10 273 *
yading@10 274 * Output pads:
yading@10 275 * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
yading@10 276 * link must have at least these permissions; this fact is checked by
yading@10 277 * asserts. It can be used to optimize buffer allocation.
yading@10 278 */
yading@10 279 attribute_deprecated int min_perms;
yading@10 280
yading@10 281 /**
yading@10 282 * Input pads:
yading@10 283 * Permissions which are not accepted on incoming buffers. Any buffer
yading@10 284 * which has any of these permissions set will be automatically copied
yading@10 285 * by the filter system to a new buffer which does not have those
yading@10 286 * permissions. This can be used to easily disallow buffers with
yading@10 287 * AV_PERM_REUSE.
yading@10 288 *
yading@10 289 * Output pads:
yading@10 290 * Permissions which are automatically removed on outgoing buffers. It
yading@10 291 * can be used to optimize buffer allocation.
yading@10 292 */
yading@10 293 attribute_deprecated int rej_perms;
yading@10 294
yading@10 295 /**
yading@10 296 * @deprecated unused
yading@10 297 */
yading@10 298 int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
yading@10 299
yading@10 300 /**
yading@10 301 * Callback function to get a video buffer. If NULL, the filter system will
yading@10 302 * use ff_default_get_video_buffer().
yading@10 303 *
yading@10 304 * Input video pads only.
yading@10 305 */
yading@10 306 AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
yading@10 307
yading@10 308 /**
yading@10 309 * Callback function to get an audio buffer. If NULL, the filter system will
yading@10 310 * use ff_default_get_audio_buffer().
yading@10 311 *
yading@10 312 * Input audio pads only.
yading@10 313 */
yading@10 314 AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
yading@10 315
yading@10 316 /**
yading@10 317 * @deprecated unused
yading@10 318 */
yading@10 319 int (*end_frame)(AVFilterLink *link);
yading@10 320
yading@10 321 /**
yading@10 322 * @deprecated unused
yading@10 323 */
yading@10 324 int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
yading@10 325
yading@10 326 /**
yading@10 327 * Filtering callback. This is where a filter receives a frame with
yading@10 328 * audio/video data and should do its processing.
yading@10 329 *
yading@10 330 * Input pads only.
yading@10 331 *
yading@10 332 * @return >= 0 on success, a negative AVERROR on error. This function
yading@10 333 * must ensure that frame is properly unreferenced on error if it
yading@10 334 * hasn't been passed on to another filter.
yading@10 335 */
yading@10 336 int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
yading@10 337
yading@10 338 /**
yading@10 339 * Frame poll callback. This returns the number of immediately available
yading@10 340 * samples. It should return a positive value if the next request_frame()
yading@10 341 * is guaranteed to return one frame (with no delay).
yading@10 342 *
yading@10 343 * Defaults to just calling the source poll_frame() method.
yading@10 344 *
yading@10 345 * Output pads only.
yading@10 346 */
yading@10 347 int (*poll_frame)(AVFilterLink *link);
yading@10 348
yading@10 349 /**
yading@10 350 * Frame request callback. A call to this should result in at least one
yading@10 351 * frame being output over the given link. This should return zero on
yading@10 352 * success, and another value on error.
yading@10 353 * See ff_request_frame() for the error codes with a specific
yading@10 354 * meaning.
yading@10 355 *
yading@10 356 * Output pads only.
yading@10 357 */
yading@10 358 int (*request_frame)(AVFilterLink *link);
yading@10 359
yading@10 360 /**
yading@10 361 * Link configuration callback.
yading@10 362 *
yading@10 363 * For output pads, this should set the following link properties:
yading@10 364 * video: width, height, sample_aspect_ratio, time_base
yading@10 365 * audio: sample_rate.
yading@10 366 *
yading@10 367 * This should NOT set properties such as format, channel_layout, etc which
yading@10 368 * are negotiated between filters by the filter system using the
yading@10 369 * query_formats() callback before this function is called.
yading@10 370 *
yading@10 371 * For input pads, this should check the properties of the link, and update
yading@10 372 * the filter's internal state as necessary.
yading@10 373 *
yading@10 374 * For both input and output pads, this should return zero on success,
yading@10 375 * and another value on error.
yading@10 376 */
yading@10 377 int (*config_props)(AVFilterLink *link);
yading@10 378
yading@10 379 /**
yading@10 380 * The filter expects a fifo to be inserted on its input link,
yading@10 381 * typically because it has a delay.
yading@10 382 *
yading@10 383 * input pads only.
yading@10 384 */
yading@10 385 int needs_fifo;
yading@10 386
yading@10 387 int needs_writable;
yading@10 388 };
yading@10 389 #endif
yading@10 390
yading@10 391 /**
yading@10 392 * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
yading@10 393 * AVFilter.inputs/outputs).
yading@10 394 */
yading@10 395 int avfilter_pad_count(const AVFilterPad *pads);
yading@10 396
yading@10 397 /**
yading@10 398 * Get the name of an AVFilterPad.
yading@10 399 *
yading@10 400 * @param pads an array of AVFilterPads
yading@10 401 * @param pad_idx index of the pad in the array it; is the caller's
yading@10 402 * responsibility to ensure the index is valid
yading@10 403 *
yading@10 404 * @return name of the pad_idx'th pad in pads
yading@10 405 */
yading@10 406 const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
yading@10 407
yading@10 408 /**
yading@10 409 * Get the type of an AVFilterPad.
yading@10 410 *
yading@10 411 * @param pads an array of AVFilterPads
yading@10 412 * @param pad_idx index of the pad in the array; it is the caller's
yading@10 413 * responsibility to ensure the index is valid
yading@10 414 *
yading@10 415 * @return type of the pad_idx'th pad in pads
yading@10 416 */
yading@10 417 enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
yading@10 418
yading@10 419 /**
yading@10 420 * The number of the filter inputs is not determined just by AVFilter.inputs.
yading@10 421 * The filter might add additional inputs during initialization depending on the
yading@10 422 * options supplied to it.
yading@10 423 */
yading@10 424 #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
yading@10 425 /**
yading@10 426 * The number of the filter outputs is not determined just by AVFilter.outputs.
yading@10 427 * The filter might add additional outputs during initialization depending on
yading@10 428 * the options supplied to it.
yading@10 429 */
yading@10 430 #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
yading@10 431
yading@10 432 /**
yading@10 433 * Filter definition. This defines the pads a filter contains, and all the
yading@10 434 * callback functions used to interact with the filter.
yading@10 435 */
yading@10 436 typedef struct AVFilter {
yading@10 437 const char *name; ///< filter name
yading@10 438
yading@10 439 /**
yading@10 440 * A description for the filter. You should use the
yading@10 441 * NULL_IF_CONFIG_SMALL() macro to define it.
yading@10 442 */
yading@10 443 const char *description;
yading@10 444
yading@10 445 const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
yading@10 446 const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
yading@10 447
yading@10 448 /**
yading@10 449 * A class for the private data, used to access filter private
yading@10 450 * AVOptions.
yading@10 451 */
yading@10 452 const AVClass *priv_class;
yading@10 453
yading@10 454 /**
yading@10 455 * A combination of AVFILTER_FLAG_*
yading@10 456 */
yading@10 457 int flags;
yading@10 458
yading@10 459 /*****************************************************************
yading@10 460 * All fields below this line are not part of the public API. They
yading@10 461 * may not be used outside of libavfilter and can be changed and
yading@10 462 * removed at will.
yading@10 463 * New public fields should be added right above.
yading@10 464 *****************************************************************
yading@10 465 */
yading@10 466
yading@10 467 /**
yading@10 468 * Filter initialization function. Called when all the options have been
yading@10 469 * set.
yading@10 470 */
yading@10 471 int (*init)(AVFilterContext *ctx);
yading@10 472
yading@10 473 /**
yading@10 474 * Should be set instead of init by the filters that want to pass a
yading@10 475 * dictionary of AVOptions to nested contexts that are allocated in
yading@10 476 * init.
yading@10 477 */
yading@10 478 int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
yading@10 479
yading@10 480 /**
yading@10 481 * Filter uninitialization function. Should deallocate any memory held
yading@10 482 * by the filter, release any buffer references, etc. This does not need
yading@10 483 * to deallocate the AVFilterContext->priv memory itself.
yading@10 484 */
yading@10 485 void (*uninit)(AVFilterContext *ctx);
yading@10 486
yading@10 487 /**
yading@10 488 * Queries formats/layouts supported by the filter and its pads, and sets
yading@10 489 * the in_formats/in_chlayouts for links connected to its output pads,
yading@10 490 * and out_formats/out_chlayouts for links connected to its input pads.
yading@10 491 *
yading@10 492 * @return zero on success, a negative value corresponding to an
yading@10 493 * AVERROR code otherwise
yading@10 494 */
yading@10 495 int (*query_formats)(AVFilterContext *);
yading@10 496
yading@10 497 int priv_size; ///< size of private data to allocate for the filter
yading@10 498
yading@10 499 struct AVFilter *next;
yading@10 500
yading@10 501 /**
yading@10 502 * Make the filter instance process a command.
yading@10 503 *
yading@10 504 * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
yading@10 505 * @param arg the argument for the command
yading@10 506 * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported.
yading@10 507 * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
yading@10 508 * time consuming then a filter should treat it like an unsupported command
yading@10 509 *
yading@10 510 * @returns >=0 on success otherwise an error code.
yading@10 511 * AVERROR(ENOSYS) on unsupported commands
yading@10 512 */
yading@10 513 int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
yading@10 514
yading@10 515 /**
yading@10 516 * Filter initialization function, alternative to the init()
yading@10 517 * callback. Args contains the user-supplied parameters, opaque is
yading@10 518 * used for providing binary data.
yading@10 519 */
yading@10 520 int (*init_opaque)(AVFilterContext *ctx, void *opaque);
yading@10 521 } AVFilter;
yading@10 522
yading@10 523 /** An instance of a filter */
yading@10 524 struct AVFilterContext {
yading@10 525 const AVClass *av_class; ///< needed for av_log()
yading@10 526
yading@10 527 const AVFilter *filter; ///< the AVFilter of which this is an instance
yading@10 528
yading@10 529 char *name; ///< name of this filter instance
yading@10 530
yading@10 531 AVFilterPad *input_pads; ///< array of input pads
yading@10 532 AVFilterLink **inputs; ///< array of pointers to input links
yading@10 533 #if FF_API_FOO_COUNT
yading@10 534 unsigned input_count; ///< @deprecated use nb_inputs
yading@10 535 #endif
yading@10 536 unsigned nb_inputs; ///< number of input pads
yading@10 537
yading@10 538 AVFilterPad *output_pads; ///< array of output pads
yading@10 539 AVFilterLink **outputs; ///< array of pointers to output links
yading@10 540 #if FF_API_FOO_COUNT
yading@10 541 unsigned output_count; ///< @deprecated use nb_outputs
yading@10 542 #endif
yading@10 543 unsigned nb_outputs; ///< number of output pads
yading@10 544
yading@10 545 void *priv; ///< private data for use by the filter
yading@10 546
yading@10 547 struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
yading@10 548
yading@10 549 struct AVFilterCommand *command_queue;
yading@10 550 };
yading@10 551
yading@10 552 /**
yading@10 553 * A link between two filters. This contains pointers to the source and
yading@10 554 * destination filters between which this link exists, and the indexes of
yading@10 555 * the pads involved. In addition, this link also contains the parameters
yading@10 556 * which have been negotiated and agreed upon between the filter, such as
yading@10 557 * image dimensions, format, etc.
yading@10 558 */
yading@10 559 struct AVFilterLink {
yading@10 560 AVFilterContext *src; ///< source filter
yading@10 561 AVFilterPad *srcpad; ///< output pad on the source filter
yading@10 562
yading@10 563 AVFilterContext *dst; ///< dest filter
yading@10 564 AVFilterPad *dstpad; ///< input pad on the dest filter
yading@10 565
yading@10 566 enum AVMediaType type; ///< filter media type
yading@10 567
yading@10 568 /* These parameters apply only to video */
yading@10 569 int w; ///< agreed upon image width
yading@10 570 int h; ///< agreed upon image height
yading@10 571 AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
yading@10 572 /* These parameters apply only to audio */
yading@10 573 uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
yading@10 574 int sample_rate; ///< samples per second
yading@10 575
yading@10 576 int format; ///< agreed upon media format
yading@10 577
yading@10 578 /**
yading@10 579 * Define the time base used by the PTS of the frames/samples
yading@10 580 * which will pass through this link.
yading@10 581 * During the configuration stage, each filter is supposed to
yading@10 582 * change only the output timebase, while the timebase of the
yading@10 583 * input link is assumed to be an unchangeable property.
yading@10 584 */
yading@10 585 AVRational time_base;
yading@10 586
yading@10 587 /*****************************************************************
yading@10 588 * All fields below this line are not part of the public API. They
yading@10 589 * may not be used outside of libavfilter and can be changed and
yading@10 590 * removed at will.
yading@10 591 * New public fields should be added right above.
yading@10 592 *****************************************************************
yading@10 593 */
yading@10 594 /**
yading@10 595 * Lists of formats and channel layouts supported by the input and output
yading@10 596 * filters respectively. These lists are used for negotiating the format
yading@10 597 * to actually be used, which will be loaded into the format and
yading@10 598 * channel_layout members, above, when chosen.
yading@10 599 *
yading@10 600 */
yading@10 601 AVFilterFormats *in_formats;
yading@10 602 AVFilterFormats *out_formats;
yading@10 603
yading@10 604 /**
yading@10 605 * Lists of channel layouts and sample rates used for automatic
yading@10 606 * negotiation.
yading@10 607 */
yading@10 608 AVFilterFormats *in_samplerates;
yading@10 609 AVFilterFormats *out_samplerates;
yading@10 610 struct AVFilterChannelLayouts *in_channel_layouts;
yading@10 611 struct AVFilterChannelLayouts *out_channel_layouts;
yading@10 612
yading@10 613 /**
yading@10 614 * Audio only, the destination filter sets this to a non-zero value to
yading@10 615 * request that buffers with the given number of samples should be sent to
yading@10 616 * it. AVFilterPad.needs_fifo must also be set on the corresponding input
yading@10 617 * pad.
yading@10 618 * Last buffer before EOF will be padded with silence.
yading@10 619 */
yading@10 620 int request_samples;
yading@10 621
yading@10 622 /** stage of the initialization of the link properties (dimensions, etc) */
yading@10 623 enum {
yading@10 624 AVLINK_UNINIT = 0, ///< not started
yading@10 625 AVLINK_STARTINIT, ///< started, but incomplete
yading@10 626 AVLINK_INIT ///< complete
yading@10 627 } init_state;
yading@10 628
yading@10 629 struct AVFilterPool *pool;
yading@10 630
yading@10 631 /**
yading@10 632 * Graph the filter belongs to.
yading@10 633 */
yading@10 634 struct AVFilterGraph *graph;
yading@10 635
yading@10 636 /**
yading@10 637 * Current timestamp of the link, as defined by the most recent
yading@10 638 * frame(s), in AV_TIME_BASE units.
yading@10 639 */
yading@10 640 int64_t current_pts;
yading@10 641
yading@10 642 /**
yading@10 643 * Index in the age array.
yading@10 644 */
yading@10 645 int age_index;
yading@10 646
yading@10 647 /**
yading@10 648 * Frame rate of the stream on the link, or 1/0 if unknown;
yading@10 649 * if left to 0/0, will be automatically be copied from the first input
yading@10 650 * of the source filter if it exists.
yading@10 651 *
yading@10 652 * Sources should set it to the best estimation of the real frame rate.
yading@10 653 * Filters should update it if necessary depending on their function.
yading@10 654 * Sinks can use it to set a default output frame rate.
yading@10 655 * It is similar to the r_frame_rate field in AVStream.
yading@10 656 */
yading@10 657 AVRational frame_rate;
yading@10 658
yading@10 659 /**
yading@10 660 * Buffer partially filled with samples to achieve a fixed/minimum size.
yading@10 661 */
yading@10 662 AVFrame *partial_buf;
yading@10 663
yading@10 664 /**
yading@10 665 * Size of the partial buffer to allocate.
yading@10 666 * Must be between min_samples and max_samples.
yading@10 667 */
yading@10 668 int partial_buf_size;
yading@10 669
yading@10 670 /**
yading@10 671 * Minimum number of samples to filter at once. If filter_frame() is
yading@10 672 * called with fewer samples, it will accumulate them in partial_buf.
yading@10 673 * This field and the related ones must not be changed after filtering
yading@10 674 * has started.
yading@10 675 * If 0, all related fields are ignored.
yading@10 676 */
yading@10 677 int min_samples;
yading@10 678
yading@10 679 /**
yading@10 680 * Maximum number of samples to filter at once. If filter_frame() is
yading@10 681 * called with more samples, it will split them.
yading@10 682 */
yading@10 683 int max_samples;
yading@10 684
yading@10 685 /**
yading@10 686 * The buffer reference currently being received across the link by the
yading@10 687 * destination filter. This is used internally by the filter system to
yading@10 688 * allow automatic copying of buffers which do not have sufficient
yading@10 689 * permissions for the destination. This should not be accessed directly
yading@10 690 * by the filters.
yading@10 691 */
yading@10 692 AVFilterBufferRef *cur_buf_copy;
yading@10 693
yading@10 694 /**
yading@10 695 * True if the link is closed.
yading@10 696 * If set, all attemps of start_frame, filter_frame or request_frame
yading@10 697 * will fail with AVERROR_EOF, and if necessary the reference will be
yading@10 698 * destroyed.
yading@10 699 * If request_frame returns AVERROR_EOF, this flag is set on the
yading@10 700 * corresponding link.
yading@10 701 * It can be set also be set by either the source or the destination
yading@10 702 * filter.
yading@10 703 */
yading@10 704 int closed;
yading@10 705
yading@10 706 /**
yading@10 707 * Number of channels.
yading@10 708 */
yading@10 709 int channels;
yading@10 710
yading@10 711 /**
yading@10 712 * True if a frame is being requested on the link.
yading@10 713 * Used internally by the framework.
yading@10 714 */
yading@10 715 unsigned frame_requested;
yading@10 716
yading@10 717 /**
yading@10 718 * Link processing flags.
yading@10 719 */
yading@10 720 unsigned flags;
yading@10 721 };
yading@10 722
yading@10 723 /**
yading@10 724 * Link two filters together.
yading@10 725 *
yading@10 726 * @param src the source filter
yading@10 727 * @param srcpad index of the output pad on the source filter
yading@10 728 * @param dst the destination filter
yading@10 729 * @param dstpad index of the input pad on the destination filter
yading@10 730 * @return zero on success
yading@10 731 */
yading@10 732 int avfilter_link(AVFilterContext *src, unsigned srcpad,
yading@10 733 AVFilterContext *dst, unsigned dstpad);
yading@10 734
yading@10 735 /**
yading@10 736 * Free the link in *link, and set its pointer to NULL.
yading@10 737 */
yading@10 738 void avfilter_link_free(AVFilterLink **link);
yading@10 739
yading@10 740 /**
yading@10 741 * Get the number of channels of a link.
yading@10 742 */
yading@10 743 int avfilter_link_get_channels(AVFilterLink *link);
yading@10 744
yading@10 745 /**
yading@10 746 * Set the closed field of a link.
yading@10 747 */
yading@10 748 void avfilter_link_set_closed(AVFilterLink *link, int closed);
yading@10 749
yading@10 750 /**
yading@10 751 * Negotiate the media format, dimensions, etc of all inputs to a filter.
yading@10 752 *
yading@10 753 * @param filter the filter to negotiate the properties for its inputs
yading@10 754 * @return zero on successful negotiation
yading@10 755 */
yading@10 756 int avfilter_config_links(AVFilterContext *filter);
yading@10 757
yading@10 758 #if FF_API_AVFILTERBUFFER
yading@10 759 /**
yading@10 760 * Create a buffer reference wrapped around an already allocated image
yading@10 761 * buffer.
yading@10 762 *
yading@10 763 * @param data pointers to the planes of the image to reference
yading@10 764 * @param linesize linesizes for the planes of the image to reference
yading@10 765 * @param perms the required access permissions
yading@10 766 * @param w the width of the image specified by the data and linesize arrays
yading@10 767 * @param h the height of the image specified by the data and linesize arrays
yading@10 768 * @param format the pixel format of the image specified by the data and linesize arrays
yading@10 769 */
yading@10 770 attribute_deprecated
yading@10 771 AVFilterBufferRef *
yading@10 772 avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
yading@10 773 int w, int h, enum AVPixelFormat format);
yading@10 774
yading@10 775 /**
yading@10 776 * Create an audio buffer reference wrapped around an already
yading@10 777 * allocated samples buffer.
yading@10 778 *
yading@10 779 * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
yading@10 780 * that can handle unknown channel layouts.
yading@10 781 *
yading@10 782 * @param data pointers to the samples plane buffers
yading@10 783 * @param linesize linesize for the samples plane buffers
yading@10 784 * @param perms the required access permissions
yading@10 785 * @param nb_samples number of samples per channel
yading@10 786 * @param sample_fmt the format of each sample in the buffer to allocate
yading@10 787 * @param channel_layout the channel layout of the buffer
yading@10 788 */
yading@10 789 attribute_deprecated
yading@10 790 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
yading@10 791 int linesize,
yading@10 792 int perms,
yading@10 793 int nb_samples,
yading@10 794 enum AVSampleFormat sample_fmt,
yading@10 795 uint64_t channel_layout);
yading@10 796 /**
yading@10 797 * Create an audio buffer reference wrapped around an already
yading@10 798 * allocated samples buffer.
yading@10 799 *
yading@10 800 * @param data pointers to the samples plane buffers
yading@10 801 * @param linesize linesize for the samples plane buffers
yading@10 802 * @param perms the required access permissions
yading@10 803 * @param nb_samples number of samples per channel
yading@10 804 * @param sample_fmt the format of each sample in the buffer to allocate
yading@10 805 * @param channels the number of channels of the buffer
yading@10 806 * @param channel_layout the channel layout of the buffer,
yading@10 807 * must be either 0 or consistent with channels
yading@10 808 */
yading@10 809 attribute_deprecated
yading@10 810 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
yading@10 811 int linesize,
yading@10 812 int perms,
yading@10 813 int nb_samples,
yading@10 814 enum AVSampleFormat sample_fmt,
yading@10 815 int channels,
yading@10 816 uint64_t channel_layout);
yading@10 817
yading@10 818 #endif
yading@10 819
yading@10 820
yading@10 821 #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
yading@10 822 #define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
yading@10 823
yading@10 824 /**
yading@10 825 * Make the filter instance process a command.
yading@10 826 * It is recommended to use avfilter_graph_send_command().
yading@10 827 */
yading@10 828 int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
yading@10 829
yading@10 830 /** Initialize the filter system. Register all builtin filters. */
yading@10 831 void avfilter_register_all(void);
yading@10 832
yading@10 833 #if FF_API_OLD_FILTER_REGISTER
yading@10 834 /** Uninitialize the filter system. Unregister all filters. */
yading@10 835 attribute_deprecated
yading@10 836 void avfilter_uninit(void);
yading@10 837 #endif
yading@10 838
yading@10 839 /**
yading@10 840 * Register a filter. This is only needed if you plan to use
yading@10 841 * avfilter_get_by_name later to lookup the AVFilter structure by name. A
yading@10 842 * filter can still by instantiated with avfilter_graph_alloc_filter even if it
yading@10 843 * is not registered.
yading@10 844 *
yading@10 845 * @param filter the filter to register
yading@10 846 * @return 0 if the registration was successful, a negative value
yading@10 847 * otherwise
yading@10 848 */
yading@10 849 int avfilter_register(AVFilter *filter);
yading@10 850
yading@10 851 /**
yading@10 852 * Get a filter definition matching the given name.
yading@10 853 *
yading@10 854 * @param name the filter name to find
yading@10 855 * @return the filter definition, if any matching one is registered.
yading@10 856 * NULL if none found.
yading@10 857 */
yading@10 858 AVFilter *avfilter_get_by_name(const char *name);
yading@10 859
yading@10 860 /**
yading@10 861 * Iterate over all registered filters.
yading@10 862 * @return If prev is non-NULL, next registered filter after prev or NULL if
yading@10 863 * prev is the last filter. If prev is NULL, return the first registered filter.
yading@10 864 */
yading@10 865 const AVFilter *avfilter_next(const AVFilter *prev);
yading@10 866
yading@10 867 #if FF_API_OLD_FILTER_REGISTER
yading@10 868 /**
yading@10 869 * If filter is NULL, returns a pointer to the first registered filter pointer,
yading@10 870 * if filter is non-NULL, returns the next pointer after filter.
yading@10 871 * If the returned pointer points to NULL, the last registered filter
yading@10 872 * was already reached.
yading@10 873 * @deprecated use avfilter_next()
yading@10 874 */
yading@10 875 attribute_deprecated
yading@10 876 AVFilter **av_filter_next(AVFilter **filter);
yading@10 877 #endif
yading@10 878
yading@10 879 #if FF_API_AVFILTER_OPEN
yading@10 880 /**
yading@10 881 * Create a filter instance.
yading@10 882 *
yading@10 883 * @param filter_ctx put here a pointer to the created filter context
yading@10 884 * on success, NULL on failure
yading@10 885 * @param filter the filter to create an instance of
yading@10 886 * @param inst_name Name to give to the new instance. Can be NULL for none.
yading@10 887 * @return >= 0 in case of success, a negative error code otherwise
yading@10 888 * @deprecated use avfilter_graph_alloc_filter() instead
yading@10 889 */
yading@10 890 attribute_deprecated
yading@10 891 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
yading@10 892 #endif
yading@10 893
yading@10 894
yading@10 895 #if FF_API_AVFILTER_INIT_FILTER
yading@10 896 /**
yading@10 897 * Initialize a filter.
yading@10 898 *
yading@10 899 * @param filter the filter to initialize
yading@10 900 * @param args A string of parameters to use when initializing the filter.
yading@10 901 * The format and meaning of this string varies by filter.
yading@10 902 * @param opaque Any extra non-string data needed by the filter. The meaning
yading@10 903 * of this parameter varies by filter.
yading@10 904 * @return zero on success
yading@10 905 */
yading@10 906 attribute_deprecated
yading@10 907 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
yading@10 908 #endif
yading@10 909
yading@10 910 /**
yading@10 911 * Initialize a filter with the supplied parameters.
yading@10 912 *
yading@10 913 * @param ctx uninitialized filter context to initialize
yading@10 914 * @param args Options to initialize the filter with. This must be a
yading@10 915 * ':'-separated list of options in the 'key=value' form.
yading@10 916 * May be NULL if the options have been set directly using the
yading@10 917 * AVOptions API or there are no options that need to be set.
yading@10 918 * @return 0 on success, a negative AVERROR on failure
yading@10 919 */
yading@10 920 int avfilter_init_str(AVFilterContext *ctx, const char *args);
yading@10 921
yading@10 922 /**
yading@10 923 * Initialize a filter with the supplied dictionary of options.
yading@10 924 *
yading@10 925 * @param ctx uninitialized filter context to initialize
yading@10 926 * @param options An AVDictionary filled with options for this filter. On
yading@10 927 * return this parameter will be destroyed and replaced with
yading@10 928 * a dict containing options that were not found. This dictionary
yading@10 929 * must be freed by the caller.
yading@10 930 * May be NULL, then this function is equivalent to
yading@10 931 * avfilter_init_str() with the second parameter set to NULL.
yading@10 932 * @return 0 on success, a negative AVERROR on failure
yading@10 933 *
yading@10 934 * @note This function and avfilter_init_str() do essentially the same thing,
yading@10 935 * the difference is in manner in which the options are passed. It is up to the
yading@10 936 * calling code to choose whichever is more preferable. The two functions also
yading@10 937 * behave differently when some of the provided options are not declared as
yading@10 938 * supported by the filter. In such a case, avfilter_init_str() will fail, but
yading@10 939 * this function will leave those extra options in the options AVDictionary and
yading@10 940 * continue as usual.
yading@10 941 */
yading@10 942 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
yading@10 943
yading@10 944 /**
yading@10 945 * Free a filter context. This will also remove the filter from its
yading@10 946 * filtergraph's list of filters.
yading@10 947 *
yading@10 948 * @param filter the filter to free
yading@10 949 */
yading@10 950 void avfilter_free(AVFilterContext *filter);
yading@10 951
yading@10 952 /**
yading@10 953 * Insert a filter in the middle of an existing link.
yading@10 954 *
yading@10 955 * @param link the link into which the filter should be inserted
yading@10 956 * @param filt the filter to be inserted
yading@10 957 * @param filt_srcpad_idx the input pad on the filter to connect
yading@10 958 * @param filt_dstpad_idx the output pad on the filter to connect
yading@10 959 * @return zero on success
yading@10 960 */
yading@10 961 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
yading@10 962 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
yading@10 963
yading@10 964 #if FF_API_AVFILTERBUFFER
yading@10 965 /**
yading@10 966 * Copy the frame properties of src to dst, without copying the actual
yading@10 967 * image data.
yading@10 968 *
yading@10 969 * @return 0 on success, a negative number on error.
yading@10 970 */
yading@10 971 attribute_deprecated
yading@10 972 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
yading@10 973
yading@10 974 /**
yading@10 975 * Copy the frame properties and data pointers of src to dst, without copying
yading@10 976 * the actual data.
yading@10 977 *
yading@10 978 * @return 0 on success, a negative number on error.
yading@10 979 */
yading@10 980 attribute_deprecated
yading@10 981 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
yading@10 982 #endif
yading@10 983
yading@10 984 /**
yading@10 985 * @return AVClass for AVFilterContext.
yading@10 986 *
yading@10 987 * @see av_opt_find().
yading@10 988 */
yading@10 989 const AVClass *avfilter_get_class(void);
yading@10 990
yading@10 991 typedef struct AVFilterGraph {
yading@10 992 const AVClass *av_class;
yading@10 993 #if FF_API_FOO_COUNT
yading@10 994 attribute_deprecated
yading@10 995 unsigned filter_count_unused;
yading@10 996 #endif
yading@10 997 AVFilterContext **filters;
yading@10 998 #if !FF_API_FOO_COUNT
yading@10 999 unsigned nb_filters;
yading@10 1000 #endif
yading@10 1001
yading@10 1002 char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
yading@10 1003 char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
yading@10 1004 #if FF_API_FOO_COUNT
yading@10 1005 unsigned nb_filters;
yading@10 1006 #endif
yading@10 1007 char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
yading@10 1008
yading@10 1009 /**
yading@10 1010 * Private fields
yading@10 1011 *
yading@10 1012 * The following fields are for internal use only.
yading@10 1013 * Their type, offset, number and semantic can change without notice.
yading@10 1014 */
yading@10 1015
yading@10 1016 AVFilterLink **sink_links;
yading@10 1017 int sink_links_count;
yading@10 1018
yading@10 1019 unsigned disable_auto_convert;
yading@10 1020 } AVFilterGraph;
yading@10 1021
yading@10 1022 /**
yading@10 1023 * Allocate a filter graph.
yading@10 1024 */
yading@10 1025 AVFilterGraph *avfilter_graph_alloc(void);
yading@10 1026
yading@10 1027 /**
yading@10 1028 * Create a new filter instance in a filter graph.
yading@10 1029 *
yading@10 1030 * @param graph graph in which the new filter will be used
yading@10 1031 * @param filter the filter to create an instance of
yading@10 1032 * @param name Name to give to the new instance (will be copied to
yading@10 1033 * AVFilterContext.name). This may be used by the caller to identify
yading@10 1034 * different filters, libavfilter itself assigns no semantics to
yading@10 1035 * this parameter. May be NULL.
yading@10 1036 *
yading@10 1037 * @return the context of the newly created filter instance (note that it is
yading@10 1038 * also retrievable directly through AVFilterGraph.filters or with
yading@10 1039 * avfilter_graph_get_filter()) on success or NULL or failure.
yading@10 1040 */
yading@10 1041 AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
yading@10 1042 const AVFilter *filter,
yading@10 1043 const char *name);
yading@10 1044
yading@10 1045 /**
yading@10 1046 * Get a filter instance with name name from graph.
yading@10 1047 *
yading@10 1048 * @return the pointer to the found filter instance or NULL if it
yading@10 1049 * cannot be found.
yading@10 1050 */
yading@10 1051 AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
yading@10 1052
yading@10 1053 #if FF_API_AVFILTER_OPEN
yading@10 1054 /**
yading@10 1055 * Add an existing filter instance to a filter graph.
yading@10 1056 *
yading@10 1057 * @param graphctx the filter graph
yading@10 1058 * @param filter the filter to be added
yading@10 1059 *
yading@10 1060 * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
yading@10 1061 * filter graph
yading@10 1062 */
yading@10 1063 attribute_deprecated
yading@10 1064 int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
yading@10 1065 #endif
yading@10 1066
yading@10 1067 /**
yading@10 1068 * Create and add a filter instance into an existing graph.
yading@10 1069 * The filter instance is created from the filter filt and inited
yading@10 1070 * with the parameters args and opaque.
yading@10 1071 *
yading@10 1072 * In case of success put in *filt_ctx the pointer to the created
yading@10 1073 * filter instance, otherwise set *filt_ctx to NULL.
yading@10 1074 *
yading@10 1075 * @param name the instance name to give to the created filter instance
yading@10 1076 * @param graph_ctx the filter graph
yading@10 1077 * @return a negative AVERROR error code in case of failure, a non
yading@10 1078 * negative value otherwise
yading@10 1079 */
yading@10 1080 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, AVFilter *filt,
yading@10 1081 const char *name, const char *args, void *opaque,
yading@10 1082 AVFilterGraph *graph_ctx);
yading@10 1083
yading@10 1084 /**
yading@10 1085 * Enable or disable automatic format conversion inside the graph.
yading@10 1086 *
yading@10 1087 * Note that format conversion can still happen inside explicitly inserted
yading@10 1088 * scale and aresample filters.
yading@10 1089 *
yading@10 1090 * @param flags any of the AVFILTER_AUTO_CONVERT_* constants
yading@10 1091 */
yading@10 1092 void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags);
yading@10 1093
yading@10 1094 enum {
yading@10 1095 AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
yading@10 1096 AVFILTER_AUTO_CONVERT_NONE = -1, /**< all automatic conversions disabled */
yading@10 1097 };
yading@10 1098
yading@10 1099 /**
yading@10 1100 * Check validity and configure all the links and formats in the graph.
yading@10 1101 *
yading@10 1102 * @param graphctx the filter graph
yading@10 1103 * @param log_ctx context used for logging
yading@10 1104 * @return 0 in case of success, a negative AVERROR code otherwise
yading@10 1105 */
yading@10 1106 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
yading@10 1107
yading@10 1108 /**
yading@10 1109 * Free a graph, destroy its links, and set *graph to NULL.
yading@10 1110 * If *graph is NULL, do nothing.
yading@10 1111 */
yading@10 1112 void avfilter_graph_free(AVFilterGraph **graph);
yading@10 1113
yading@10 1114 /**
yading@10 1115 * A linked-list of the inputs/outputs of the filter chain.
yading@10 1116 *
yading@10 1117 * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
yading@10 1118 * where it is used to communicate open (unlinked) inputs and outputs from and
yading@10 1119 * to the caller.
yading@10 1120 * This struct specifies, per each not connected pad contained in the graph, the
yading@10 1121 * filter context and the pad index required for establishing a link.
yading@10 1122 */
yading@10 1123 typedef struct AVFilterInOut {
yading@10 1124 /** unique name for this input/output in the list */
yading@10 1125 char *name;
yading@10 1126
yading@10 1127 /** filter context associated to this input/output */
yading@10 1128 AVFilterContext *filter_ctx;
yading@10 1129
yading@10 1130 /** index of the filt_ctx pad to use for linking */
yading@10 1131 int pad_idx;
yading@10 1132
yading@10 1133 /** next input/input in the list, NULL if this is the last */
yading@10 1134 struct AVFilterInOut *next;
yading@10 1135 } AVFilterInOut;
yading@10 1136
yading@10 1137 /**
yading@10 1138 * Allocate a single AVFilterInOut entry.
yading@10 1139 * Must be freed with avfilter_inout_free().
yading@10 1140 * @return allocated AVFilterInOut on success, NULL on failure.
yading@10 1141 */
yading@10 1142 AVFilterInOut *avfilter_inout_alloc(void);
yading@10 1143
yading@10 1144 /**
yading@10 1145 * Free the supplied list of AVFilterInOut and set *inout to NULL.
yading@10 1146 * If *inout is NULL, do nothing.
yading@10 1147 */
yading@10 1148 void avfilter_inout_free(AVFilterInOut **inout);
yading@10 1149
yading@10 1150 /**
yading@10 1151 * Add a graph described by a string to a graph.
yading@10 1152 *
yading@10 1153 * @param graph the filter graph where to link the parsed graph context
yading@10 1154 * @param filters string to be parsed
yading@10 1155 * @param inputs pointer to a linked list to the inputs of the graph, may be NULL.
yading@10 1156 * If non-NULL, *inputs is updated to contain the list of open inputs
yading@10 1157 * after the parsing, should be freed with avfilter_inout_free().
yading@10 1158 * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
yading@10 1159 * If non-NULL, *outputs is updated to contain the list of open outputs
yading@10 1160 * after the parsing, should be freed with avfilter_inout_free().
yading@10 1161 * @return non negative on success, a negative AVERROR code on error
yading@10 1162 */
yading@10 1163 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
yading@10 1164 AVFilterInOut **inputs, AVFilterInOut **outputs,
yading@10 1165 void *log_ctx);
yading@10 1166
yading@10 1167 /**
yading@10 1168 * Add a graph described by a string to a graph.
yading@10 1169 *
yading@10 1170 * @param[in] graph the filter graph where to link the parsed graph context
yading@10 1171 * @param[in] filters string to be parsed
yading@10 1172 * @param[out] inputs a linked list of all free (unlinked) inputs of the
yading@10 1173 * parsed graph will be returned here. It is to be freed
yading@10 1174 * by the caller using avfilter_inout_free().
yading@10 1175 * @param[out] outputs a linked list of all free (unlinked) outputs of the
yading@10 1176 * parsed graph will be returned here. It is to be freed by the
yading@10 1177 * caller using avfilter_inout_free().
yading@10 1178 * @return zero on success, a negative AVERROR code on error
yading@10 1179 *
yading@10 1180 * @note the difference between avfilter_graph_parse2() and
yading@10 1181 * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
yading@10 1182 * the lists of inputs and outputs, which therefore must be known before calling
yading@10 1183 * the function. On the other hand, avfilter_graph_parse2() \em returns the
yading@10 1184 * inputs and outputs that are left unlinked after parsing the graph and the
yading@10 1185 * caller then deals with them. Another difference is that in
yading@10 1186 * avfilter_graph_parse(), the inputs parameter describes inputs of the
yading@10 1187 * <em>already existing</em> part of the graph; i.e. from the point of view of
yading@10 1188 * the newly created part, they are outputs. Similarly the outputs parameter
yading@10 1189 * describes outputs of the already existing filters, which are provided as
yading@10 1190 * inputs to the parsed filters.
yading@10 1191 * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
yading@10 1192 * whatsoever to already existing parts of the graph and the inputs parameter
yading@10 1193 * will on return contain inputs of the newly parsed part of the graph.
yading@10 1194 * Analogously the outputs parameter will contain outputs of the newly created
yading@10 1195 * filters.
yading@10 1196 */
yading@10 1197 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
yading@10 1198 AVFilterInOut **inputs,
yading@10 1199 AVFilterInOut **outputs);
yading@10 1200
yading@10 1201 /**
yading@10 1202 * Send a command to one or more filter instances.
yading@10 1203 *
yading@10 1204 * @param graph the filter graph
yading@10 1205 * @param target the filter(s) to which the command should be sent
yading@10 1206 * "all" sends to all filters
yading@10 1207 * otherwise it can be a filter or filter instance name
yading@10 1208 * which will send the command to all matching filters.
yading@10 1209 * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
yading@10 1210 * @param arg the argument for the command
yading@10 1211 * @param res a buffer with size res_size where the filter(s) can return a response.
yading@10 1212 *
yading@10 1213 * @returns >=0 on success otherwise an error code.
yading@10 1214 * AVERROR(ENOSYS) on unsupported commands
yading@10 1215 */
yading@10 1216 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
yading@10 1217
yading@10 1218 /**
yading@10 1219 * Queue a command for one or more filter instances.
yading@10 1220 *
yading@10 1221 * @param graph the filter graph
yading@10 1222 * @param target the filter(s) to which the command should be sent
yading@10 1223 * "all" sends to all filters
yading@10 1224 * otherwise it can be a filter or filter instance name
yading@10 1225 * which will send the command to all matching filters.
yading@10 1226 * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only
yading@10 1227 * @param arg the argument for the command
yading@10 1228 * @param ts time at which the command should be sent to the filter
yading@10 1229 *
yading@10 1230 * @note As this executes commands after this function returns, no return code
yading@10 1231 * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
yading@10 1232 */
yading@10 1233 int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
yading@10 1234
yading@10 1235
yading@10 1236 /**
yading@10 1237 * Dump a graph into a human-readable string representation.
yading@10 1238 *
yading@10 1239 * @param graph the graph to dump
yading@10 1240 * @param options formatting options; currently ignored
yading@10 1241 * @return a string, or NULL in case of memory allocation failure;
yading@10 1242 * the string must be freed using av_free
yading@10 1243 */
yading@10 1244 char *avfilter_graph_dump(AVFilterGraph *graph, const char *options);
yading@10 1245
yading@10 1246 /**
yading@10 1247 * Request a frame on the oldest sink link.
yading@10 1248 *
yading@10 1249 * If the request returns AVERROR_EOF, try the next.
yading@10 1250 *
yading@10 1251 * Note that this function is not meant to be the sole scheduling mechanism
yading@10 1252 * of a filtergraph, only a convenience function to help drain a filtergraph
yading@10 1253 * in a balanced way under normal circumstances.
yading@10 1254 *
yading@10 1255 * Also note that AVERROR_EOF does not mean that frames did not arrive on
yading@10 1256 * some of the sinks during the process.
yading@10 1257 * When there are multiple sink links, in case the requested link
yading@10 1258 * returns an EOF, this may cause a filter to flush pending frames
yading@10 1259 * which are sent to another sink link, although unrequested.
yading@10 1260 *
yading@10 1261 * @return the return value of ff_request_frame(),
yading@10 1262 * or AVERROR_EOF if all links returned AVERROR_EOF
yading@10 1263 */
yading@10 1264 int avfilter_graph_request_oldest(AVFilterGraph *graph);
yading@10 1265
yading@10 1266 /**
yading@10 1267 * @}
yading@10 1268 */
yading@10 1269 #endif /* AVFILTER_AVFILTER_H */