You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1524 lines
55KB

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