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 extern (C):
25 import ffmpeg; @nogc nothrow:
26 
27 /**
28  * @file
29  * @ingroup lavfi
30  * Main libavfilter public API header
31  */
32 
33 /**
34  * @defgroup lavfi libavfilter
35  * Graph-based frame editing library.
36  *
37  * @{
38  */
39 
40 /**
41  * Return the LIBAVFILTER_VERSION_INT constant.
42  */
43 uint avfilter_version ();
44 
45 /**
46  * Return the libavfilter build-time configuration.
47  */
48 const(char)* avfilter_configuration ();
49 
50 /**
51  * Return the libavfilter license.
52  */
53 const(char)* avfilter_license ();
54 
55 struct AVFilterPad;
56 struct AVFilterFormats;
57 
58 /**
59  * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
60  * AVFilter.inputs/outputs).
61  */
62 int avfilter_pad_count (const(AVFilterPad)* pads);
63 
64 /**
65  * Get the name of an AVFilterPad.
66  *
67  * @param pads an array of AVFilterPads
68  * @param pad_idx index of the pad in the array it; is the caller's
69  *                responsibility to ensure the index is valid
70  *
71  * @return name of the pad_idx'th pad in pads
72  */
73 const(char)* avfilter_pad_get_name (const(AVFilterPad)* pads, int pad_idx);
74 
75 /**
76  * Get the type of an AVFilterPad.
77  *
78  * @param pads an array of AVFilterPads
79  * @param pad_idx index of the pad in the array; it is the caller's
80  *                responsibility to ensure the index is valid
81  *
82  * @return type of the pad_idx'th pad in pads
83  */
84 AVMediaType avfilter_pad_get_type (const(AVFilterPad)* pads, int pad_idx);
85 
86 /**
87  * The number of the filter inputs is not determined just by AVFilter.inputs.
88  * The filter might add additional inputs during initialization depending on the
89  * options supplied to it.
90  */
91 enum AVFILTER_FLAG_DYNAMIC_INPUTS = 1 << 0;
92 /**
93  * The number of the filter outputs is not determined just by AVFilter.outputs.
94  * The filter might add additional outputs during initialization depending on
95  * the options supplied to it.
96  */
97 enum AVFILTER_FLAG_DYNAMIC_OUTPUTS = 1 << 1;
98 /**
99  * The filter supports multithreading by splitting frames into multiple parts
100  * and processing them concurrently.
101  */
102 enum AVFILTER_FLAG_SLICE_THREADS = 1 << 2;
103 /**
104  * Some filters support a generic "enable" expression option that can be used
105  * to enable or disable a filter in the timeline. Filters supporting this
106  * option have this flag set. When the enable expression is false, the default
107  * no-op filter_frame() function is called in place of the filter_frame()
108  * callback defined on each input pad, thus the frame is passed unchanged to
109  * the next filters.
110  */
111 enum AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC = 1 << 16;
112 /**
113  * Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will
114  * have its filter_frame() callback(s) called as usual even when the enable
115  * expression is false. The filter will disable filtering within the
116  * filter_frame() callback(s) itself, for example executing code depending on
117  * the AVFilterContext->is_disabled value.
118  */
119 enum AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL = 1 << 17;
120 /**
121  * Handy mask to test whether the filter supports or no the timeline feature
122  * (internally or generically).
123  */
124 enum AVFILTER_FLAG_SUPPORT_TIMELINE = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL;
125 
126 /**
127  * Filter definition. This defines the pads a filter contains, and all the
128  * callback functions used to interact with the filter.
129  */
130 struct AVFilter
131 {
132     /**
133      * Filter name. Must be non-NULL and unique among filters.
134      */
135     const(char)* name;
136 
137     /**
138      * A description of the filter. May be NULL.
139      *
140      * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
141      */
142     const(char)* description;
143 
144     /**
145      * List of inputs, terminated by a zeroed element.
146      *
147      * NULL if there are no (static) inputs. Instances of filters with
148      * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
149      * this list.
150      */
151     const(AVFilterPad)* inputs;
152     /**
153      * List of outputs, terminated by a zeroed element.
154      *
155      * NULL if there are no (static) outputs. Instances of filters with
156      * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
157      * this list.
158      */
159     const(AVFilterPad)* outputs;
160 
161     /**
162      * A class for the private data, used to declare filter private AVOptions.
163      * This field is NULL for filters that do not declare any options.
164      *
165      * If this field is non-NULL, the first member of the filter private data
166      * must be a pointer to AVClass, which will be set by libavfilter generic
167      * code to this class.
168      */
169     const(AVClass)* priv_class;
170 
171     /**
172      * A combination of AVFILTER_FLAG_*
173      */
174     int flags;
175 
176     /*****************************************************************
177      * All fields below this line are not part of the public API. They
178      * may not be used outside of libavfilter and can be changed and
179      * removed at will.
180      * New public fields should be added right above.
181      *****************************************************************
182      */
183 
184     /**
185      * Filter pre-initialization function
186      *
187      * This callback will be called immediately after the filter context is
188      * allocated, to allow allocating and initing sub-objects.
189      *
190      * If this callback is not NULL, the uninit callback will be called on
191      * allocation failure.
192      *
193      * @return 0 on success,
194      *         AVERROR code on failure (but the code will be
195      *           dropped and treated as ENOMEM by the calling code)
196      */
197     int function (AVFilterContext* ctx) preinit;
198 
199     /**
200      * Filter initialization function.
201      *
202      * This callback will be called only once during the filter lifetime, after
203      * all the options have been set, but before links between filters are
204      * established and format negotiation is done.
205      *
206      * Basic filter initialization should be done here. Filters with dynamic
207      * inputs and/or outputs should create those inputs/outputs here based on
208      * provided options. No more changes to this filter's inputs/outputs can be
209      * done after this callback.
210      *
211      * This callback must not assume that the filter links exist or frame
212      * parameters are known.
213      *
214      * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
215      * initialization fails, so this callback does not have to clean up on
216      * failure.
217      *
218      * @return 0 on success, a negative AVERROR on failure
219      */
220     int function (AVFilterContext* ctx) init;
221 
222     /**
223      * Should be set instead of @ref AVFilter.init "init" by the filters that
224      * want to pass a dictionary of AVOptions to nested contexts that are
225      * allocated during init.
226      *
227      * On return, the options dict should be freed and replaced with one that
228      * contains all the options which could not be processed by this filter (or
229      * with NULL if all the options were processed).
230      *
231      * Otherwise the semantics is the same as for @ref AVFilter.init "init".
232      */
233     int function (AVFilterContext* ctx, AVDictionary** options) init_dict;
234 
235     /**
236      * Filter uninitialization function.
237      *
238      * Called only once right before the filter is freed. Should deallocate any
239      * memory held by the filter, release any buffer references, etc. It does
240      * not need to deallocate the AVFilterContext.priv memory itself.
241      *
242      * This callback may be called even if @ref AVFilter.init "init" was not
243      * called or failed, so it must be prepared to handle such a situation.
244      */
245     void function (AVFilterContext* ctx) uninit;
246 
247     /**
248      * Query formats supported by the filter on its inputs and outputs.
249      *
250      * This callback is called after the filter is initialized (so the inputs
251      * and outputs are fixed), shortly before the format negotiation. This
252      * callback may be called more than once.
253      *
254      * This callback must set AVFilterLink.out_formats on every input link and
255      * AVFilterLink.in_formats on every output link to a list of pixel/sample
256      * formats that the filter supports on that link. For audio links, this
257      * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
258      * @ref AVFilterLink.out_samplerates "out_samplerates" and
259      * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
260      * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
261      *
262      * This callback may be NULL for filters with one input, in which case
263      * libavfilter assumes that it supports all input formats and preserves
264      * them on output.
265      *
266      * @return zero on success, a negative value corresponding to an
267      * AVERROR code otherwise
268      */
269     int function (AVFilterContext*) query_formats;
270 
271     int priv_size; ///< size of private data to allocate for the filter
272 
273     int flags_internal; ///< Additional flags for avfilter internal use only.
274 
275     /**
276      * Used by the filter registration system. Must not be touched by any other
277      * code.
278      */
279     AVFilter* next;
280 
281     /**
282      * Make the filter instance process a command.
283      *
284      * @param cmd    the command to process, for handling simplicity all commands must be alphanumeric only
285      * @param arg    the argument for the command
286      * @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.
287      * @param flags  if AVFILTER_CMD_FLAG_FAST is set and the command would be
288      *               time consuming then a filter should treat it like an unsupported command
289      *
290      * @returns >=0 on success otherwise an error code.
291      *          AVERROR(ENOSYS) on unsupported commands
292      */
293     int function (AVFilterContext*, const(char)* cmd, const(char)* arg, char* res, int res_len, int flags) process_command;
294 
295     /**
296      * Filter initialization function, alternative to the init()
297      * callback. Args contains the user-supplied parameters, opaque is
298      * used for providing binary data.
299      */
300     int function (AVFilterContext* ctx, void* opaque) init_opaque;
301 
302     /**
303      * Filter activation function.
304      *
305      * Called when any processing is needed from the filter, instead of any
306      * filter_frame and request_frame on pads.
307      *
308      * The function must examine inlinks and outlinks and perform a single
309      * step of processing. If there is nothing to do, the function must do
310      * nothing and not return an error. If more steps are or may be
311      * possible, it must use ff_filter_set_ready() to schedule another
312      * activation.
313      */
314     int function (AVFilterContext* ctx) activate;
315 }
316 
317 /**
318  * Process multiple parts of the frame concurrently.
319  */
320 enum AVFILTER_THREAD_SLICE = 1 << 0;
321 
322 struct AVFilterInternal;
323 
324 /** An instance of a filter */
325 struct AVFilterContext
326 {
327     const(AVClass)* av_class; ///< needed for av_log() and filters common options
328 
329     const(AVFilter)* filter; ///< the AVFilter of which this is an instance
330 
331     char* name; ///< name of this filter instance
332 
333     AVFilterPad* input_pads; ///< array of input pads
334     AVFilterLink** inputs; ///< array of pointers to input links
335     uint nb_inputs; ///< number of input pads
336 
337     AVFilterPad* output_pads; ///< array of output pads
338     AVFilterLink** outputs; ///< array of pointers to output links
339     uint nb_outputs; ///< number of output pads
340 
341     void* priv; ///< private data for use by the filter
342 
343     AVFilterGraph* graph; ///< filtergraph this filter belongs to
344 
345     /**
346      * Type of multithreading being allowed/used. A combination of
347      * AVFILTER_THREAD_* flags.
348      *
349      * May be set by the caller before initializing the filter to forbid some
350      * or all kinds of multithreading for this filter. The default is allowing
351      * everything.
352      *
353      * When the filter is initialized, this field is combined using bit AND with
354      * AVFilterGraph.thread_type to get the final mask used for determining
355      * allowed threading types. I.e. a threading type needs to be set in both
356      * to be allowed.
357      *
358      * After the filter is initialized, libavfilter sets this field to the
359      * threading type that is actually used (0 for no multithreading).
360      */
361     int thread_type;
362 
363     /**
364      * An opaque struct for libavfilter internal use.
365      */
366     AVFilterInternal* internal;
367 
368     struct AVFilterCommand;
369     AVFilterCommand* command_queue;
370 
371     char* enable_str; ///< enable expression string
372     void* enable; ///< parsed expression (AVExpr*)
373     double* var_values; ///< variable values for the enable expression
374     int is_disabled; ///< the enabled state from the last expression evaluation
375 
376     /**
377      * For filters which will create hardware frames, sets the device the
378      * filter should create them in.  All other filters will ignore this field:
379      * in particular, a filter which consumes or processes hardware frames will
380      * instead use the hw_frames_ctx field in AVFilterLink to carry the
381      * hardware context information.
382      */
383     AVBufferRef* hw_device_ctx;
384 
385     /**
386      * Max number of threads allowed in this filter instance.
387      * If <= 0, its value is ignored.
388      * Overrides global number of threads set per filter graph.
389      */
390     int nb_threads;
391 
392     /**
393      * Ready status of the filter.
394      * A non-0 value means that the filter needs activating;
395      * a higher value suggests a more urgent activation.
396      */
397     uint ready;
398 
399     /**
400      * Sets the number of extra hardware frames which the filter will
401      * allocate on its output links for use in following filters or by
402      * the caller.
403      *
404      * Some hardware filters require all frames that they will use for
405      * output to be defined in advance before filtering starts.  For such
406      * filters, any hardware frame pools used for output must therefore be
407      * of fixed size.  The extra frames set here are on top of any number
408      * that the filter needs internally in order to operate normally.
409      *
410      * This field must be set before the graph containing this filter is
411      * configured.
412      */
413     int extra_hw_frames;
414 }
415 
416 /**
417  * A link between two filters. This contains pointers to the source and
418  * destination filters between which this link exists, and the indexes of
419  * the pads involved. In addition, this link also contains the parameters
420  * which have been negotiated and agreed upon between the filter, such as
421  * image dimensions, format, etc.
422  *
423  * Applications must not normally access the link structure directly.
424  * Use the buffersrc and buffersink API instead.
425  * In the future, access to the header may be reserved for filters
426  * implementation.
427  */
428 struct AVFilterLink
429 {
430     AVFilterContext* src; ///< source filter
431     AVFilterPad* srcpad; ///< output pad on the source filter
432 
433     AVFilterContext* dst; ///< dest filter
434     AVFilterPad* dstpad; ///< input pad on the dest filter
435 
436     AVMediaType type; ///< filter media type
437 
438     /* These parameters apply only to video */
439     int w; ///< agreed upon image width
440     int h; ///< agreed upon image height
441     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
442     /* These parameters apply only to audio */
443     ulong channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
444     int sample_rate; ///< samples per second
445 
446     int format; ///< agreed upon media format
447 
448     /**
449      * Define the time base used by the PTS of the frames/samples
450      * which will pass through this link.
451      * During the configuration stage, each filter is supposed to
452      * change only the output timebase, while the timebase of the
453      * input link is assumed to be an unchangeable property.
454      */
455     AVRational time_base;
456 
457     /*****************************************************************
458      * All fields below this line are not part of the public API. They
459      * may not be used outside of libavfilter and can be changed and
460      * removed at will.
461      * New public fields should be added right above.
462      *****************************************************************
463      */
464     /**
465      * Lists of formats and channel layouts supported by the input and output
466      * filters respectively. These lists are used for negotiating the format
467      * to actually be used, which will be loaded into the format and
468      * channel_layout members, above, when chosen.
469      *
470      */
471     AVFilterFormats* in_formats;
472     AVFilterFormats* out_formats;
473 
474     /**
475      * Lists of channel layouts and sample rates used for automatic
476      * negotiation.
477      */
478     AVFilterFormats* in_samplerates;
479     AVFilterFormats* out_samplerates;
480     struct AVFilterChannelLayouts;
481     AVFilterChannelLayouts* in_channel_layouts;
482     AVFilterChannelLayouts* out_channel_layouts;
483 
484     /**
485      * Audio only, the destination filter sets this to a non-zero value to
486      * request that buffers with the given number of samples should be sent to
487      * it. AVFilterPad.needs_fifo must also be set on the corresponding input
488      * pad.
489      * Last buffer before EOF will be padded with silence.
490      */
491     int request_samples;
492 
493     /** stage of the initialization of the link properties (dimensions, etc) */
494     enum _Anonymous_0
495     {
496         AVLINK_UNINIT = 0, ///< not started
497         AVLINK_STARTINIT = 1, ///< started, but incomplete
498         AVLINK_INIT = 2 ///< complete
499     }
500 
501     _Anonymous_0 init_state;
502 
503     /**
504      * Graph the filter belongs to.
505      */
506     AVFilterGraph* graph;
507 
508     /**
509      * Current timestamp of the link, as defined by the most recent
510      * frame(s), in link time_base units.
511      */
512     long current_pts;
513 
514     /**
515      * Current timestamp of the link, as defined by the most recent
516      * frame(s), in AV_TIME_BASE units.
517      */
518     long current_pts_us;
519 
520     /**
521      * Index in the age array.
522      */
523     int age_index;
524 
525     /**
526      * Frame rate of the stream on the link, or 1/0 if unknown or variable;
527      * if left to 0/0, will be automatically copied from the first input
528      * of the source filter if it exists.
529      *
530      * Sources should set it to the best estimation of the real frame rate.
531      * If the source frame rate is unknown or variable, set this to 1/0.
532      * Filters should update it if necessary depending on their function.
533      * Sinks can use it to set a default output frame rate.
534      * It is similar to the r_frame_rate field in AVStream.
535      */
536     AVRational frame_rate;
537 
538     /**
539      * Buffer partially filled with samples to achieve a fixed/minimum size.
540      */
541     AVFrame* partial_buf;
542 
543     /**
544      * Size of the partial buffer to allocate.
545      * Must be between min_samples and max_samples.
546      */
547     int partial_buf_size;
548 
549     /**
550      * Minimum number of samples to filter at once. If filter_frame() is
551      * called with fewer samples, it will accumulate them in partial_buf.
552      * This field and the related ones must not be changed after filtering
553      * has started.
554      * If 0, all related fields are ignored.
555      */
556     int min_samples;
557 
558     /**
559      * Maximum number of samples to filter at once. If filter_frame() is
560      * called with more samples, it will split them.
561      */
562     int max_samples;
563 
564     /**
565      * Number of channels.
566      */
567     int channels;
568 
569     /**
570      * Link processing flags.
571      */
572     uint flags;
573 
574     /**
575      * Number of past frames sent through the link.
576      */
577     long frame_count_in;
578     long frame_count_out;
579 
580     /**
581      * A pointer to a FFFramePool struct.
582      */
583     void* frame_pool;
584 
585     /**
586      * True if a frame is currently wanted on the output of this filter.
587      * Set when ff_request_frame() is called by the output,
588      * cleared when a frame is filtered.
589      */
590     int frame_wanted_out;
591 
592     /**
593      * For hwaccel pixel formats, this should be a reference to the
594      * AVHWFramesContext describing the frames.
595      */
596     AVBufferRef* hw_frames_ctx;
597 
598     /**
599      * Internal structure members.
600      * The fields below this limit are internal for libavfilter's use
601      * and must in no way be accessed by applications.
602      */
603     char[0xF000] reserved;
604 
605     /* FF_INTERNAL_FIELDS */
606 
607     /**
608      * Queue of frames waiting to be filtered.
609      */
610 
611     /**
612      * If set, the source filter can not generate a frame as is.
613      * The goal is to avoid repeatedly calling the request_frame() method on
614      * the same link.
615      */
616 
617     /**
618      * Link input status.
619      * If not zero, all attempts of filter_frame will fail with the
620      * corresponding code.
621      */
622 
623     /**
624      * Timestamp of the input status change.
625      */
626 
627     /**
628      * Link output status.
629      * If not zero, all attempts of request_frame will fail with the
630      * corresponding code.
631      */
632 
633     /* FF_INTERNAL_FIELDS */
634 }
635 
636 alias AVLINK_UNINIT = AVFilterLink._Anonymous_0.AVLINK_UNINIT;
637 alias AVLINK_STARTINIT = AVFilterLink._Anonymous_0.AVLINK_STARTINIT;
638 alias AVLINK_INIT = AVFilterLink._Anonymous_0.AVLINK_INIT;
639 
640 /**
641  * Link two filters together.
642  *
643  * @param src    the source filter
644  * @param srcpad index of the output pad on the source filter
645  * @param dst    the destination filter
646  * @param dstpad index of the input pad on the destination filter
647  * @return       zero on success
648  */
649 int avfilter_link (
650     AVFilterContext* src,
651     uint srcpad,
652     AVFilterContext* dst,
653     uint dstpad);
654 
655 /**
656  * Free the link in *link, and set its pointer to NULL.
657  */
658 void avfilter_link_free (AVFilterLink** link);
659 
660 /**
661  * Get the number of channels of a link.
662  * @deprecated Use av_buffersink_get_channels()
663  */
664 int avfilter_link_get_channels (AVFilterLink* link);
665 
666 /**
667  * Set the closed field of a link.
668  * @deprecated applications are not supposed to mess with links, they should
669  * close the sinks.
670  */
671 void avfilter_link_set_closed (AVFilterLink* link, int closed);
672 
673 /**
674  * Negotiate the media format, dimensions, etc of all inputs to a filter.
675  *
676  * @param filter the filter to negotiate the properties for its inputs
677  * @return       zero on successful negotiation
678  */
679 int avfilter_config_links (AVFilterContext* filter);
680 
681 enum AVFILTER_CMD_FLAG_ONE = 1; ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
682 enum AVFILTER_CMD_FLAG_FAST = 2; ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
683 
684 /**
685  * Make the filter instance process a command.
686  * It is recommended to use avfilter_graph_send_command().
687  */
688 int avfilter_process_command (AVFilterContext* filter, const(char)* cmd, const(char)* arg, char* res, int res_len, int flags);
689 
690 /**
691  * Iterate over all registered filters.
692  *
693  * @param opaque a pointer where libavfilter will store the iteration state. Must
694  *               point to NULL to start the iteration.
695  *
696  * @return the next registered filter or NULL when the iteration is
697  *         finished
698  */
699 const(AVFilter)* av_filter_iterate (void** opaque);
700 
701 /** Initialize the filter system. Register all builtin filters. */
702 void avfilter_register_all ();
703 
704 /**
705  * Register a filter. This is only needed if you plan to use
706  * avfilter_get_by_name later to lookup the AVFilter structure by name. A
707  * filter can still by instantiated with avfilter_graph_alloc_filter even if it
708  * is not registered.
709  *
710  * @param filter the filter to register
711  * @return 0 if the registration was successful, a negative value
712  * otherwise
713  */
714 int avfilter_register (AVFilter* filter);
715 
716 /**
717  * Iterate over all registered filters.
718  * @return If prev is non-NULL, next registered filter after prev or NULL if
719  * prev is the last filter. If prev is NULL, return the first registered filter.
720  */
721 const(AVFilter)* avfilter_next (const(AVFilter)* prev);
722 
723 /**
724  * Get a filter definition matching the given name.
725  *
726  * @param name the filter name to find
727  * @return     the filter definition, if any matching one is registered.
728  *             NULL if none found.
729  */
730 const(AVFilter)* avfilter_get_by_name (const(char)* name);
731 
732 /**
733  * Initialize a filter with the supplied parameters.
734  *
735  * @param ctx  uninitialized filter context to initialize
736  * @param args Options to initialize the filter with. This must be a
737  *             ':'-separated list of options in the 'key=value' form.
738  *             May be NULL if the options have been set directly using the
739  *             AVOptions API or there are no options that need to be set.
740  * @return 0 on success, a negative AVERROR on failure
741  */
742 int avfilter_init_str (AVFilterContext* ctx, const(char)* args);
743 
744 /**
745  * Initialize a filter with the supplied dictionary of options.
746  *
747  * @param ctx     uninitialized filter context to initialize
748  * @param options An AVDictionary filled with options for this filter. On
749  *                return this parameter will be destroyed and replaced with
750  *                a dict containing options that were not found. This dictionary
751  *                must be freed by the caller.
752  *                May be NULL, then this function is equivalent to
753  *                avfilter_init_str() with the second parameter set to NULL.
754  * @return 0 on success, a negative AVERROR on failure
755  *
756  * @note This function and avfilter_init_str() do essentially the same thing,
757  * the difference is in manner in which the options are passed. It is up to the
758  * calling code to choose whichever is more preferable. The two functions also
759  * behave differently when some of the provided options are not declared as
760  * supported by the filter. In such a case, avfilter_init_str() will fail, but
761  * this function will leave those extra options in the options AVDictionary and
762  * continue as usual.
763  */
764 int avfilter_init_dict (AVFilterContext* ctx, AVDictionary** options);
765 
766 /**
767  * Free a filter context. This will also remove the filter from its
768  * filtergraph's list of filters.
769  *
770  * @param filter the filter to free
771  */
772 void avfilter_free (AVFilterContext* filter);
773 
774 /**
775  * Insert a filter in the middle of an existing link.
776  *
777  * @param link the link into which the filter should be inserted
778  * @param filt the filter to be inserted
779  * @param filt_srcpad_idx the input pad on the filter to connect
780  * @param filt_dstpad_idx the output pad on the filter to connect
781  * @return     zero on success
782  */
783 int avfilter_insert_filter (
784     AVFilterLink* link,
785     AVFilterContext* filt,
786     uint filt_srcpad_idx,
787     uint filt_dstpad_idx);
788 
789 /**
790  * @return AVClass for AVFilterContext.
791  *
792  * @see av_opt_find().
793  */
794 const(AVClass)* avfilter_get_class ();
795 
796 struct AVFilterGraphInternal;
797 
798 /**
799  * A function pointer passed to the @ref AVFilterGraph.execute callback to be
800  * executed multiple times, possibly in parallel.
801  *
802  * @param ctx the filter context the job belongs to
803  * @param arg an opaque parameter passed through from @ref
804  *            AVFilterGraph.execute
805  * @param jobnr the index of the job being executed
806  * @param nb_jobs the total number of jobs
807  *
808  * @return 0 on success, a negative AVERROR on error
809  */
810 alias avfilter_action_func = int function (AVFilterContext* ctx, void* arg, int jobnr, int nb_jobs);
811 
812 /**
813  * A function executing multiple jobs, possibly in parallel.
814  *
815  * @param ctx the filter context to which the jobs belong
816  * @param func the function to be called multiple times
817  * @param arg the argument to be passed to func
818  * @param ret a nb_jobs-sized array to be filled with return values from each
819  *            invocation of func
820  * @param nb_jobs the number of jobs to execute
821  *
822  * @return 0 on success, a negative AVERROR on error
823  */
824 alias avfilter_execute_func = int function (
825     AVFilterContext* ctx,
826     int function () func,
827     void* arg,
828     int* ret,
829     int nb_jobs);
830 
831 struct AVFilterGraph
832 {
833     const(AVClass)* av_class;
834     AVFilterContext** filters;
835     uint nb_filters;
836 
837     char* scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
838 
839     char* resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
840 
841     /**
842      * Type of multithreading allowed for filters in this graph. A combination
843      * of AVFILTER_THREAD_* flags.
844      *
845      * May be set by the caller at any point, the setting will apply to all
846      * filters initialized after that. The default is allowing everything.
847      *
848      * When a filter in this graph is initialized, this field is combined using
849      * bit AND with AVFilterContext.thread_type to get the final mask used for
850      * determining allowed threading types. I.e. a threading type needs to be
851      * set in both to be allowed.
852      */
853     int thread_type;
854 
855     /**
856      * Maximum number of threads used by filters in this graph. May be set by
857      * the caller before adding any filters to the filtergraph. Zero (the
858      * default) means that the number of threads is determined automatically.
859      */
860     int nb_threads;
861 
862     /**
863      * Opaque object for libavfilter internal use.
864      */
865     AVFilterGraphInternal* internal;
866 
867     /**
868      * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
869      * be used from callbacks like @ref AVFilterGraph.execute.
870      * Libavfilter will not touch this field in any way.
871      */
872     void* opaque;
873 
874     /**
875      * This callback may be set by the caller immediately after allocating the
876      * graph and before adding any filters to it, to provide a custom
877      * multithreading implementation.
878      *
879      * If set, filters with slice threading capability will call this callback
880      * to execute multiple jobs in parallel.
881      *
882      * If this field is left unset, libavfilter will use its internal
883      * implementation, which may or may not be multithreaded depending on the
884      * platform and build options.
885      */
886     int function () execute;
887 
888     char* aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
889 
890     /**
891      * Private fields
892      *
893      * The following fields are for internal use only.
894      * Their type, offset, number and semantic can change without notice.
895      */
896 
897     AVFilterLink** sink_links;
898     int sink_links_count;
899 
900     uint disable_auto_convert;
901 }
902 
903 /**
904  * Allocate a filter graph.
905  *
906  * @return the allocated filter graph on success or NULL.
907  */
908 AVFilterGraph* avfilter_graph_alloc ();
909 
910 /**
911  * Create a new filter instance in a filter graph.
912  *
913  * @param graph graph in which the new filter will be used
914  * @param filter the filter to create an instance of
915  * @param name Name to give to the new instance (will be copied to
916  *             AVFilterContext.name). This may be used by the caller to identify
917  *             different filters, libavfilter itself assigns no semantics to
918  *             this parameter. May be NULL.
919  *
920  * @return the context of the newly created filter instance (note that it is
921  *         also retrievable directly through AVFilterGraph.filters or with
922  *         avfilter_graph_get_filter()) on success or NULL on failure.
923  */
924 AVFilterContext* avfilter_graph_alloc_filter (
925     AVFilterGraph* graph,
926     const(AVFilter)* filter,
927     const(char)* name);
928 
929 /**
930  * Get a filter instance identified by instance name from graph.
931  *
932  * @param graph filter graph to search through.
933  * @param name filter instance name (should be unique in the graph).
934  * @return the pointer to the found filter instance or NULL if it
935  * cannot be found.
936  */
937 AVFilterContext* avfilter_graph_get_filter (AVFilterGraph* graph, const(char)* name);
938 
939 /**
940  * Create and add a filter instance into an existing graph.
941  * The filter instance is created from the filter filt and inited
942  * with the parameters args and opaque.
943  *
944  * In case of success put in *filt_ctx the pointer to the created
945  * filter instance, otherwise set *filt_ctx to NULL.
946  *
947  * @param name the instance name to give to the created filter instance
948  * @param graph_ctx the filter graph
949  * @return a negative AVERROR error code in case of failure, a non
950  * negative value otherwise
951  */
952 int avfilter_graph_create_filter (
953     AVFilterContext** filt_ctx,
954     const(AVFilter)* filt,
955     const(char)* name,
956     const(char)* args,
957     void* opaque,
958     AVFilterGraph* graph_ctx);
959 
960 /**
961  * Enable or disable automatic format conversion inside the graph.
962  *
963  * Note that format conversion can still happen inside explicitly inserted
964  * scale and aresample filters.
965  *
966  * @param flags  any of the AVFILTER_AUTO_CONVERT_* constants
967  */
968 void avfilter_graph_set_auto_convert (AVFilterGraph* graph, uint flags);
969 
970 enum
971 {
972     AVFILTER_AUTO_CONVERT_ALL = 0, /**< all automatic conversions enabled */
973     AVFILTER_AUTO_CONVERT_NONE = -1 /**< all automatic conversions disabled */
974 }
975 
976 /**
977  * Check validity and configure all the links and formats in the graph.
978  *
979  * @param graphctx the filter graph
980  * @param log_ctx context used for logging
981  * @return >= 0 in case of success, a negative AVERROR code otherwise
982  */
983 int avfilter_graph_config (AVFilterGraph* graphctx, void* log_ctx);
984 
985 /**
986  * Free a graph, destroy its links, and set *graph to NULL.
987  * If *graph is NULL, do nothing.
988  */
989 void avfilter_graph_free (AVFilterGraph** graph);
990 
991 /**
992  * A linked-list of the inputs/outputs of the filter chain.
993  *
994  * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
995  * where it is used to communicate open (unlinked) inputs and outputs from and
996  * to the caller.
997  * This struct specifies, per each not connected pad contained in the graph, the
998  * filter context and the pad index required for establishing a link.
999  */
1000 struct AVFilterInOut
1001 {
1002     /** unique name for this input/output in the list */
1003     char* name;
1004 
1005     /** filter context associated to this input/output */
1006     AVFilterContext* filter_ctx;
1007 
1008     /** index of the filt_ctx pad to use for linking */
1009     int pad_idx;
1010 
1011     /** next input/input in the list, NULL if this is the last */
1012     AVFilterInOut* next;
1013 }
1014 
1015 /**
1016  * Allocate a single AVFilterInOut entry.
1017  * Must be freed with avfilter_inout_free().
1018  * @return allocated AVFilterInOut on success, NULL on failure.
1019  */
1020 AVFilterInOut* avfilter_inout_alloc ();
1021 
1022 /**
1023  * Free the supplied list of AVFilterInOut and set *inout to NULL.
1024  * If *inout is NULL, do nothing.
1025  */
1026 void avfilter_inout_free (AVFilterInOut** inout_);
1027 
1028 /**
1029  * Add a graph described by a string to a graph.
1030  *
1031  * @note The caller must provide the lists of inputs and outputs,
1032  * which therefore must be known before calling the function.
1033  *
1034  * @note The inputs parameter describes inputs of the already existing
1035  * part of the graph; i.e. from the point of view of the newly created
1036  * part, they are outputs. Similarly the outputs parameter describes
1037  * outputs of the already existing filters, which are provided as
1038  * inputs to the parsed filters.
1039  *
1040  * @param graph   the filter graph where to link the parsed graph context
1041  * @param filters string to be parsed
1042  * @param inputs  linked list to the inputs of the graph
1043  * @param outputs linked list to the outputs of the graph
1044  * @return zero on success, a negative AVERROR code on error
1045  */
1046 int avfilter_graph_parse (
1047     AVFilterGraph* graph,
1048     const(char)* filters,
1049     AVFilterInOut* inputs,
1050     AVFilterInOut* outputs,
1051     void* log_ctx);
1052 
1053 /**
1054  * Add a graph described by a string to a graph.
1055  *
1056  * In the graph filters description, if the input label of the first
1057  * filter is not specified, "in" is assumed; if the output label of
1058  * the last filter is not specified, "out" is assumed.
1059  *
1060  * @param graph   the filter graph where to link the parsed graph context
1061  * @param filters string to be parsed
1062  * @param inputs  pointer to a linked list to the inputs of the graph, may be NULL.
1063  *                If non-NULL, *inputs is updated to contain the list of open inputs
1064  *                after the parsing, should be freed with avfilter_inout_free().
1065  * @param outputs pointer to a linked list to the outputs of the graph, may be NULL.
1066  *                If non-NULL, *outputs is updated to contain the list of open outputs
1067  *                after the parsing, should be freed with avfilter_inout_free().
1068  * @return non negative on success, a negative AVERROR code on error
1069  */
1070 int avfilter_graph_parse_ptr (
1071     AVFilterGraph* graph,
1072     const(char)* filters,
1073     AVFilterInOut** inputs,
1074     AVFilterInOut** outputs,
1075     void* log_ctx);
1076 
1077 /**
1078  * Add a graph described by a string to a graph.
1079  *
1080  * @param[in]  graph   the filter graph where to link the parsed graph context
1081  * @param[in]  filters string to be parsed
1082  * @param[out] inputs  a linked list of all free (unlinked) inputs of the
1083  *                     parsed graph will be returned here. It is to be freed
1084  *                     by the caller using avfilter_inout_free().
1085  * @param[out] outputs a linked list of all free (unlinked) outputs of the
1086  *                     parsed graph will be returned here. It is to be freed by the
1087  *                     caller using avfilter_inout_free().
1088  * @return zero on success, a negative AVERROR code on error
1089  *
1090  * @note This function returns the inputs and outputs that are left
1091  * unlinked after parsing the graph and the caller then deals with
1092  * them.
1093  * @note This function makes no reference whatsoever to already
1094  * existing parts of the graph and the inputs parameter will on return
1095  * contain inputs of the newly parsed part of the graph.  Analogously
1096  * the outputs parameter will contain outputs of the newly created
1097  * filters.
1098  */
1099 int avfilter_graph_parse2 (
1100     AVFilterGraph* graph,
1101     const(char)* filters,
1102     AVFilterInOut** inputs,
1103     AVFilterInOut** outputs);
1104 
1105 /**
1106  * Send a command to one or more filter instances.
1107  *
1108  * @param graph  the filter graph
1109  * @param target the filter(s) to which the command should be sent
1110  *               "all" sends to all filters
1111  *               otherwise it can be a filter or filter instance name
1112  *               which will send the command to all matching filters.
1113  * @param cmd    the command to send, for handling simplicity all commands must be alphanumeric only
1114  * @param arg    the argument for the command
1115  * @param res    a buffer with size res_size where the filter(s) can return a response.
1116  *
1117  * @returns >=0 on success otherwise an error code.
1118  *              AVERROR(ENOSYS) on unsupported commands
1119  */
1120 int avfilter_graph_send_command (AVFilterGraph* graph, const(char)* target, const(char)* cmd, const(char)* arg, char* res, int res_len, int flags);
1121 
1122 /**
1123  * Queue a command for one or more filter instances.
1124  *
1125  * @param graph  the filter graph
1126  * @param target the filter(s) to which the command should be sent
1127  *               "all" sends to all filters
1128  *               otherwise it can be a filter or filter instance name
1129  *               which will send the command to all matching filters.
1130  * @param cmd    the command to sent, for handling simplicity all commands must be alphanumeric only
1131  * @param arg    the argument for the command
1132  * @param ts     time at which the command should be sent to the filter
1133  *
1134  * @note As this executes commands after this function returns, no return code
1135  *       from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
1136  */
1137 int avfilter_graph_queue_command (AVFilterGraph* graph, const(char)* target, const(char)* cmd, const(char)* arg, int flags, double ts);
1138 
1139 /**
1140  * Dump a graph into a human-readable string representation.
1141  *
1142  * @param graph    the graph to dump
1143  * @param options  formatting options; currently ignored
1144  * @return  a string, or NULL in case of memory allocation failure;
1145  *          the string must be freed using av_free
1146  */
1147 char* avfilter_graph_dump (AVFilterGraph* graph, const(char)* options);
1148 
1149 /**
1150  * Request a frame on the oldest sink link.
1151  *
1152  * If the request returns AVERROR_EOF, try the next.
1153  *
1154  * Note that this function is not meant to be the sole scheduling mechanism
1155  * of a filtergraph, only a convenience function to help drain a filtergraph
1156  * in a balanced way under normal circumstances.
1157  *
1158  * Also note that AVERROR_EOF does not mean that frames did not arrive on
1159  * some of the sinks during the process.
1160  * When there are multiple sink links, in case the requested link
1161  * returns an EOF, this may cause a filter to flush pending frames
1162  * which are sent to another sink link, although unrequested.
1163  *
1164  * @return  the return value of ff_request_frame(),
1165  *          or AVERROR_EOF if all links returned AVERROR_EOF
1166  */
1167 int avfilter_graph_request_oldest (AVFilterGraph* graph);
1168 
1169 /**
1170  * @}
1171  */
1172 
1173 /* AVFILTER_AVFILTER_H */