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