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.

919 lines
32KB

  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. * external API header
  27. */
  28. /**
  29. * @defgroup lavfi Libavfilter
  30. * @{
  31. */
  32. #include <stddef.h>
  33. #include "libavutil/avutil.h"
  34. #include "libavutil/dict.h"
  35. #include "libavutil/frame.h"
  36. #include "libavutil/log.h"
  37. #include "libavutil/samplefmt.h"
  38. #include "libavutil/pixfmt.h"
  39. #include "libavutil/rational.h"
  40. #include "libavfilter/version.h"
  41. /**
  42. * Return the LIBAVFILTER_VERSION_INT constant.
  43. */
  44. unsigned avfilter_version(void);
  45. /**
  46. * Return the libavfilter build-time configuration.
  47. */
  48. const char *avfilter_configuration(void);
  49. /**
  50. * Return the libavfilter license.
  51. */
  52. const char *avfilter_license(void);
  53. typedef struct AVFilterContext AVFilterContext;
  54. typedef struct AVFilterLink AVFilterLink;
  55. typedef struct AVFilterPad AVFilterPad;
  56. typedef struct AVFilterFormats AVFilterFormats;
  57. #if FF_API_AVFILTERBUFFER
  58. /**
  59. * A reference-counted buffer data type used by the filter system. Filters
  60. * should not store pointers to this structure directly, but instead use the
  61. * AVFilterBufferRef structure below.
  62. */
  63. typedef struct AVFilterBuffer {
  64. uint8_t *data[8]; ///< buffer data for each plane/channel
  65. /**
  66. * pointers to the data planes/channels.
  67. *
  68. * For video, this should simply point to data[].
  69. *
  70. * For planar audio, each channel has a separate data pointer, and
  71. * linesize[0] contains the size of each channel buffer.
  72. * For packed audio, there is just one data pointer, and linesize[0]
  73. * contains the total size of the buffer for all channels.
  74. *
  75. * Note: Both data and extended_data will always be set, but for planar
  76. * audio with more channels that can fit in data, extended_data must be used
  77. * in order to access all channels.
  78. */
  79. uint8_t **extended_data;
  80. int linesize[8]; ///< number of bytes per line
  81. /** private data to be used by a custom free function */
  82. void *priv;
  83. /**
  84. * A pointer to the function to deallocate this buffer if the default
  85. * function is not sufficient. This could, for example, add the memory
  86. * back into a memory pool to be reused later without the overhead of
  87. * reallocating it from scratch.
  88. */
  89. void (*free)(struct AVFilterBuffer *buf);
  90. int format; ///< media format
  91. int w, h; ///< width and height of the allocated buffer
  92. unsigned refcount; ///< number of references to this buffer
  93. } AVFilterBuffer;
  94. #define AV_PERM_READ 0x01 ///< can read from the buffer
  95. #define AV_PERM_WRITE 0x02 ///< can write to the buffer
  96. #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
  97. #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
  98. #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
  99. #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes
  100. #define AV_PERM_ALIGN 0x40 ///< the buffer must be aligned
  101. #define AVFILTER_ALIGN 16 //not part of ABI
  102. /**
  103. * Audio specific properties in a reference to an AVFilterBuffer. Since
  104. * AVFilterBufferRef is common to different media formats, audio specific
  105. * per reference properties must be separated out.
  106. */
  107. typedef struct AVFilterBufferRefAudioProps {
  108. uint64_t channel_layout; ///< channel layout of audio buffer
  109. int nb_samples; ///< number of audio samples per channel
  110. int sample_rate; ///< audio buffer sample rate
  111. int channels; ///< number of channels (do not access directly)
  112. } AVFilterBufferRefAudioProps;
  113. /**
  114. * Video specific properties in a reference to an AVFilterBuffer. Since
  115. * AVFilterBufferRef is common to different media formats, video specific
  116. * per reference properties must be separated out.
  117. */
  118. typedef struct AVFilterBufferRefVideoProps {
  119. int w; ///< image width
  120. int h; ///< image height
  121. AVRational sample_aspect_ratio; ///< sample aspect ratio
  122. int interlaced; ///< is frame interlaced
  123. int top_field_first; ///< field order
  124. enum AVPictureType pict_type; ///< picture type of the frame
  125. int key_frame; ///< 1 -> keyframe, 0-> not
  126. int qp_table_linesize; ///< qp_table stride
  127. int qp_table_size; ///< qp_table size
  128. int8_t *qp_table; ///< array of Quantization Parameters
  129. } AVFilterBufferRefVideoProps;
  130. /**
  131. * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
  132. * a buffer to, for example, crop image without any memcpy, the buffer origin
  133. * and dimensions are per-reference properties. Linesize is also useful for
  134. * image flipping, frame to field filters, etc, and so is also per-reference.
  135. *
  136. * TODO: add anything necessary for frame reordering
  137. */
  138. typedef struct AVFilterBufferRef {
  139. AVFilterBuffer *buf; ///< the buffer that this is a reference to
  140. uint8_t *data[8]; ///< picture/audio data for each plane
  141. /**
  142. * pointers to the data planes/channels.
  143. *
  144. * For video, this should simply point to data[].
  145. *
  146. * For planar audio, each channel has a separate data pointer, and
  147. * linesize[0] contains the size of each channel buffer.
  148. * For packed audio, there is just one data pointer, and linesize[0]
  149. * contains the total size of the buffer for all channels.
  150. *
  151. * Note: Both data and extended_data will always be set, but for planar
  152. * audio with more channels that can fit in data, extended_data must be used
  153. * in order to access all channels.
  154. */
  155. uint8_t **extended_data;
  156. int linesize[8]; ///< number of bytes per line
  157. AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
  158. AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
  159. /**
  160. * presentation timestamp. The time unit may change during
  161. * filtering, as it is specified in the link and the filter code
  162. * may need to rescale the PTS accordingly.
  163. */
  164. int64_t pts;
  165. int64_t pos; ///< byte position in stream, -1 if unknown
  166. int format; ///< media format
  167. int perms; ///< permissions, see the AV_PERM_* flags
  168. enum AVMediaType type; ///< media type of buffer data
  169. AVDictionary *metadata; ///< dictionary containing metadata key=value tags
  170. } AVFilterBufferRef;
  171. /**
  172. * Copy properties of src to dst, without copying the actual data
  173. */
  174. attribute_deprecated
  175. void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
  176. /**
  177. * Add a new reference to a buffer.
  178. *
  179. * @param ref an existing reference to the buffer
  180. * @param pmask a bitmask containing the allowable permissions in the new
  181. * reference
  182. * @return a new reference to the buffer with the same properties as the
  183. * old, excluding any permissions denied by pmask
  184. */
  185. attribute_deprecated
  186. AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
  187. /**
  188. * Remove a reference to a buffer. If this is the last reference to the
  189. * buffer, the buffer itself is also automatically freed.
  190. *
  191. * @param ref reference to the buffer, may be NULL
  192. *
  193. * @note it is recommended to use avfilter_unref_bufferp() instead of this
  194. * function
  195. */
  196. attribute_deprecated
  197. void avfilter_unref_buffer(AVFilterBufferRef *ref);
  198. /**
  199. * Remove a reference to a buffer and set the pointer to NULL.
  200. * If this is the last reference to the buffer, the buffer itself
  201. * is also automatically freed.
  202. *
  203. * @param ref pointer to the buffer reference
  204. */
  205. attribute_deprecated
  206. void avfilter_unref_bufferp(AVFilterBufferRef **ref);
  207. #endif
  208. /**
  209. * Get the number of channels of a buffer reference.
  210. */
  211. attribute_deprecated
  212. int avfilter_ref_get_channels(AVFilterBufferRef *ref);
  213. #if FF_API_AVFILTERPAD_PUBLIC
  214. /**
  215. * A filter pad used for either input or output.
  216. *
  217. * See doc/filter_design.txt for details on how to implement the methods.
  218. *
  219. * @warning this struct might be removed from public API.
  220. * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
  221. * to access the name and type fields; there should be no need to access
  222. * any other fields from outside of libavfilter.
  223. */
  224. struct AVFilterPad {
  225. /**
  226. * Pad name. The name is unique among inputs and among outputs, but an
  227. * input may have the same name as an output. This may be NULL if this
  228. * pad has no need to ever be referenced by name.
  229. */
  230. const char *name;
  231. /**
  232. * AVFilterPad type.
  233. */
  234. enum AVMediaType type;
  235. /**
  236. * Input pads:
  237. * Minimum required permissions on incoming buffers. Any buffer with
  238. * insufficient permissions will be automatically copied by the filter
  239. * system to a new buffer which provides the needed access permissions.
  240. *
  241. * Output pads:
  242. * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
  243. * link must have at least these permissions; this fact is checked by
  244. * asserts. It can be used to optimize buffer allocation.
  245. */
  246. attribute_deprecated int min_perms;
  247. /**
  248. * Input pads:
  249. * Permissions which are not accepted on incoming buffers. Any buffer
  250. * which has any of these permissions set will be automatically copied
  251. * by the filter system to a new buffer which does not have those
  252. * permissions. This can be used to easily disallow buffers with
  253. * AV_PERM_REUSE.
  254. *
  255. * Output pads:
  256. * Permissions which are automatically removed on outgoing buffers. It
  257. * can be used to optimize buffer allocation.
  258. */
  259. attribute_deprecated int rej_perms;
  260. /**
  261. * @deprecated unused
  262. */
  263. int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
  264. /**
  265. * Callback function to get a video buffer. If NULL, the filter system will
  266. * use ff_default_get_video_buffer().
  267. *
  268. * Input video pads only.
  269. */
  270. AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
  271. /**
  272. * Callback function to get an audio buffer. If NULL, the filter system will
  273. * use ff_default_get_audio_buffer().
  274. *
  275. * Input audio pads only.
  276. */
  277. AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
  278. /**
  279. * @deprecated unused
  280. */
  281. int (*end_frame)(AVFilterLink *link);
  282. /**
  283. * @deprecated unused
  284. */
  285. int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  286. /**
  287. * Filtering callback. This is where a filter receives a frame with
  288. * audio/video data and should do its processing.
  289. *
  290. * Input pads only.
  291. *
  292. * @return >= 0 on success, a negative AVERROR on error. This function
  293. * must ensure that frame is properly unreferenced on error if it
  294. * hasn't been passed on to another filter.
  295. */
  296. int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
  297. /**
  298. * Frame poll callback. This returns the number of immediately available
  299. * samples. It should return a positive value if the next request_frame()
  300. * is guaranteed to return one frame (with no delay).
  301. *
  302. * Defaults to just calling the source poll_frame() method.
  303. *
  304. * Output pads only.
  305. */
  306. int (*poll_frame)(AVFilterLink *link);
  307. /**
  308. * Frame request callback. A call to this should result in at least one
  309. * frame being output over the given link. This should return zero on
  310. * success, and another value on error.
  311. * See ff_request_frame() for the error codes with a specific
  312. * meaning.
  313. *
  314. * Output pads only.
  315. */
  316. int (*request_frame)(AVFilterLink *link);
  317. /**
  318. * Link configuration callback.
  319. *
  320. * For output pads, this should set the following link properties:
  321. * video: width, height, sample_aspect_ratio, time_base
  322. * audio: sample_rate.
  323. *
  324. * This should NOT set properties such as format, channel_layout, etc which
  325. * are negotiated between filters by the filter system using the
  326. * query_formats() callback before this function is called.
  327. *
  328. * For input pads, this should check the properties of the link, and update
  329. * the filter's internal state as necessary.
  330. *
  331. * For both input and output pads, this should return zero on success,
  332. * and another value on error.
  333. */
  334. int (*config_props)(AVFilterLink *link);
  335. /**
  336. * The filter expects a fifo to be inserted on its input link,
  337. * typically because it has a delay.
  338. *
  339. * input pads only.
  340. */
  341. int needs_fifo;
  342. int needs_writable;
  343. };
  344. #endif
  345. /**
  346. * Get the name of an AVFilterPad.
  347. *
  348. * @param pads an array of AVFilterPads
  349. * @param pad_idx index of the pad in the array it; is the caller's
  350. * responsibility to ensure the index is valid
  351. *
  352. * @return name of the pad_idx'th pad in pads
  353. */
  354. const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx);
  355. /**
  356. * Get the type of an AVFilterPad.
  357. *
  358. * @param pads an array of AVFilterPads
  359. * @param pad_idx index of the pad in the array; it is the caller's
  360. * responsibility to ensure the index is valid
  361. *
  362. * @return type of the pad_idx'th pad in pads
  363. */
  364. enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx);
  365. /**
  366. * Filter definition. This defines the pads a filter contains, and all the
  367. * callback functions used to interact with the filter.
  368. */
  369. typedef struct AVFilter {
  370. const char *name; ///< filter name
  371. /**
  372. * A description for the filter. You should use the
  373. * NULL_IF_CONFIG_SMALL() macro to define it.
  374. */
  375. const char *description;
  376. const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
  377. const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
  378. /**
  379. * A class for the private data, used to access filter private
  380. * AVOptions.
  381. */
  382. const AVClass *priv_class;
  383. /*****************************************************************
  384. * All fields below this line are not part of the public API. They
  385. * may not be used outside of libavfilter and can be changed and
  386. * removed at will.
  387. * New public fields should be added right above.
  388. *****************************************************************
  389. */
  390. /**
  391. * Filter initialization function. Args contains the user-supplied
  392. * parameters. FIXME: maybe an AVOption-based system would be better?
  393. */
  394. int (*init)(AVFilterContext *ctx, const char *args);
  395. /**
  396. * Should be set instead of init by the filters that want to pass a
  397. * dictionary of AVOptions to nested contexts that are allocated in
  398. * init.
  399. */
  400. int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
  401. /**
  402. * Filter uninitialization function. Should deallocate any memory held
  403. * by the filter, release any buffer references, etc. This does not need
  404. * to deallocate the AVFilterContext->priv memory itself.
  405. */
  406. void (*uninit)(AVFilterContext *ctx);
  407. /**
  408. * Queries formats/layouts supported by the filter and its pads, and sets
  409. * the in_formats/in_chlayouts for links connected to its output pads,
  410. * and out_formats/out_chlayouts for links connected to its input pads.
  411. *
  412. * @return zero on success, a negative value corresponding to an
  413. * AVERROR code otherwise
  414. */
  415. int (*query_formats)(AVFilterContext *);
  416. int priv_size; ///< size of private data to allocate for the filter
  417. /**
  418. * Make the filter instance process a command.
  419. *
  420. * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
  421. * @param arg the argument for the command
  422. * @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.
  423. * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
  424. * time consuming then a filter should treat it like an unsupported command
  425. *
  426. * @returns >=0 on success otherwise an error code.
  427. * AVERROR(ENOSYS) on unsupported commands
  428. */
  429. int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
  430. /**
  431. * Filter initialization function, alternative to the init()
  432. * callback. Args contains the user-supplied parameters, opaque is
  433. * used for providing binary data.
  434. */
  435. int (*init_opaque)(AVFilterContext *ctx, const char *args, void *opaque);
  436. /**
  437. * Shorthand syntax for init arguments.
  438. * If this field is set (even to an empty list), just before init the
  439. * private class will be set and the arguments string will be parsed
  440. * using av_opt_set_from_string() with "=" and ":" delimiters, and
  441. * av_opt_free() will be called just after uninit.
  442. */
  443. const char *const *shorthand;
  444. } AVFilter;
  445. /** An instance of a filter */
  446. struct AVFilterContext {
  447. const AVClass *av_class; ///< needed for av_log()
  448. AVFilter *filter; ///< the AVFilter of which this is an instance
  449. char *name; ///< name of this filter instance
  450. AVFilterPad *input_pads; ///< array of input pads
  451. AVFilterLink **inputs; ///< array of pointers to input links
  452. #if FF_API_FOO_COUNT
  453. unsigned input_count; ///< @deprecated use nb_inputs
  454. #endif
  455. unsigned nb_inputs; ///< number of input pads
  456. AVFilterPad *output_pads; ///< array of output pads
  457. AVFilterLink **outputs; ///< array of pointers to output links
  458. #if FF_API_FOO_COUNT
  459. unsigned output_count; ///< @deprecated use nb_outputs
  460. #endif
  461. unsigned nb_outputs; ///< number of output pads
  462. void *priv; ///< private data for use by the filter
  463. struct AVFilterCommand *command_queue;
  464. };
  465. /**
  466. * A link between two filters. This contains pointers to the source and
  467. * destination filters between which this link exists, and the indexes of
  468. * the pads involved. In addition, this link also contains the parameters
  469. * which have been negotiated and agreed upon between the filter, such as
  470. * image dimensions, format, etc.
  471. */
  472. struct AVFilterLink {
  473. AVFilterContext *src; ///< source filter
  474. AVFilterPad *srcpad; ///< output pad on the source filter
  475. AVFilterContext *dst; ///< dest filter
  476. AVFilterPad *dstpad; ///< input pad on the dest filter
  477. enum AVMediaType type; ///< filter media type
  478. /* These parameters apply only to video */
  479. int w; ///< agreed upon image width
  480. int h; ///< agreed upon image height
  481. AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
  482. /* These parameters apply only to audio */
  483. uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
  484. int sample_rate; ///< samples per second
  485. int format; ///< agreed upon media format
  486. /**
  487. * Define the time base used by the PTS of the frames/samples
  488. * which will pass through this link.
  489. * During the configuration stage, each filter is supposed to
  490. * change only the output timebase, while the timebase of the
  491. * input link is assumed to be an unchangeable property.
  492. */
  493. AVRational time_base;
  494. /*****************************************************************
  495. * All fields below this line are not part of the public API. They
  496. * may not be used outside of libavfilter and can be changed and
  497. * removed at will.
  498. * New public fields should be added right above.
  499. *****************************************************************
  500. */
  501. /**
  502. * Lists of formats and channel layouts supported by the input and output
  503. * filters respectively. These lists are used for negotiating the format
  504. * to actually be used, which will be loaded into the format and
  505. * channel_layout members, above, when chosen.
  506. *
  507. */
  508. AVFilterFormats *in_formats;
  509. AVFilterFormats *out_formats;
  510. /**
  511. * Lists of channel layouts and sample rates used for automatic
  512. * negotiation.
  513. */
  514. AVFilterFormats *in_samplerates;
  515. AVFilterFormats *out_samplerates;
  516. struct AVFilterChannelLayouts *in_channel_layouts;
  517. struct AVFilterChannelLayouts *out_channel_layouts;
  518. /**
  519. * Audio only, the destination filter sets this to a non-zero value to
  520. * request that buffers with the given number of samples should be sent to
  521. * it. AVFilterPad.needs_fifo must also be set on the corresponding input
  522. * pad.
  523. * Last buffer before EOF will be padded with silence.
  524. */
  525. int request_samples;
  526. /** stage of the initialization of the link properties (dimensions, etc) */
  527. enum {
  528. AVLINK_UNINIT = 0, ///< not started
  529. AVLINK_STARTINIT, ///< started, but incomplete
  530. AVLINK_INIT ///< complete
  531. } init_state;
  532. struct AVFilterPool *pool;
  533. /**
  534. * Graph the filter belongs to.
  535. */
  536. struct AVFilterGraph *graph;
  537. /**
  538. * Current timestamp of the link, as defined by the most recent
  539. * frame(s), in AV_TIME_BASE units.
  540. */
  541. int64_t current_pts;
  542. /**
  543. * Index in the age array.
  544. */
  545. int age_index;
  546. /**
  547. * Frame rate of the stream on the link, or 1/0 if unknown;
  548. * if left to 0/0, will be automatically be copied from the first input
  549. * of the source filter if it exists.
  550. *
  551. * Sources should set it to the best estimation of the real frame rate.
  552. * Filters should update it if necessary depending on their function.
  553. * Sinks can use it to set a default output frame rate.
  554. * It is similar to the r_frame_rate field in AVStream.
  555. */
  556. AVRational frame_rate;
  557. /**
  558. * Buffer partially filled with samples to achieve a fixed/minimum size.
  559. */
  560. AVFrame *partial_buf;
  561. /**
  562. * Size of the partial buffer to allocate.
  563. * Must be between min_samples and max_samples.
  564. */
  565. int partial_buf_size;
  566. /**
  567. * Minimum number of samples to filter at once. If filter_frame() is
  568. * called with fewer samples, it will accumulate them in partial_buf.
  569. * This field and the related ones must not be changed after filtering
  570. * has started.
  571. * If 0, all related fields are ignored.
  572. */
  573. int min_samples;
  574. /**
  575. * Maximum number of samples to filter at once. If filter_frame() is
  576. * called with more samples, it will split them.
  577. */
  578. int max_samples;
  579. /**
  580. * The buffer reference currently being received across the link by the
  581. * destination filter. This is used internally by the filter system to
  582. * allow automatic copying of buffers which do not have sufficient
  583. * permissions for the destination. This should not be accessed directly
  584. * by the filters.
  585. */
  586. AVFilterBufferRef *cur_buf_copy;
  587. /**
  588. * True if the link is closed.
  589. * If set, all attemps of start_frame, filter_frame or request_frame
  590. * will fail with AVERROR_EOF, and if necessary the reference will be
  591. * destroyed.
  592. * If request_frame returns AVERROR_EOF, this flag is set on the
  593. * corresponding link.
  594. * It can be set also be set by either the source or the destination
  595. * filter.
  596. */
  597. int closed;
  598. /**
  599. * Number of channels.
  600. */
  601. int channels;
  602. /**
  603. * True if a frame is being requested on the link.
  604. * Used internally by the framework.
  605. */
  606. unsigned frame_requested;
  607. /**
  608. * Link processing flags.
  609. */
  610. unsigned flags;
  611. };
  612. /**
  613. * Link two filters together.
  614. *
  615. * @param src the source filter
  616. * @param srcpad index of the output pad on the source filter
  617. * @param dst the destination filter
  618. * @param dstpad index of the input pad on the destination filter
  619. * @return zero on success
  620. */
  621. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  622. AVFilterContext *dst, unsigned dstpad);
  623. /**
  624. * Free the link in *link, and set its pointer to NULL.
  625. */
  626. void avfilter_link_free(AVFilterLink **link);
  627. /**
  628. * Get the number of channels of a link.
  629. */
  630. int avfilter_link_get_channels(AVFilterLink *link);
  631. /**
  632. * Set the closed field of a link.
  633. */
  634. void avfilter_link_set_closed(AVFilterLink *link, int closed);
  635. /**
  636. * Negotiate the media format, dimensions, etc of all inputs to a filter.
  637. *
  638. * @param filter the filter to negotiate the properties for its inputs
  639. * @return zero on successful negotiation
  640. */
  641. int avfilter_config_links(AVFilterContext *filter);
  642. #if FF_API_AVFILTERBUFFER
  643. /**
  644. * Create a buffer reference wrapped around an already allocated image
  645. * buffer.
  646. *
  647. * @param data pointers to the planes of the image to reference
  648. * @param linesize linesizes for the planes of the image to reference
  649. * @param perms the required access permissions
  650. * @param w the width of the image specified by the data and linesize arrays
  651. * @param h the height of the image specified by the data and linesize arrays
  652. * @param format the pixel format of the image specified by the data and linesize arrays
  653. */
  654. attribute_deprecated
  655. AVFilterBufferRef *
  656. avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms,
  657. int w, int h, enum AVPixelFormat format);
  658. /**
  659. * Create an audio buffer reference wrapped around an already
  660. * allocated samples buffer.
  661. *
  662. * See avfilter_get_audio_buffer_ref_from_arrays_channels() for a version
  663. * that can handle unknown channel layouts.
  664. *
  665. * @param data pointers to the samples plane buffers
  666. * @param linesize linesize for the samples plane buffers
  667. * @param perms the required access permissions
  668. * @param nb_samples number of samples per channel
  669. * @param sample_fmt the format of each sample in the buffer to allocate
  670. * @param channel_layout the channel layout of the buffer
  671. */
  672. attribute_deprecated
  673. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
  674. int linesize,
  675. int perms,
  676. int nb_samples,
  677. enum AVSampleFormat sample_fmt,
  678. uint64_t channel_layout);
  679. /**
  680. * Create an audio buffer reference wrapped around an already
  681. * allocated samples buffer.
  682. *
  683. * @param data pointers to the samples plane buffers
  684. * @param linesize linesize for the samples plane buffers
  685. * @param perms the required access permissions
  686. * @param nb_samples number of samples per channel
  687. * @param sample_fmt the format of each sample in the buffer to allocate
  688. * @param channels the number of channels of the buffer
  689. * @param channel_layout the channel layout of the buffer,
  690. * must be either 0 or consistent with channels
  691. */
  692. attribute_deprecated
  693. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
  694. int linesize,
  695. int perms,
  696. int nb_samples,
  697. enum AVSampleFormat sample_fmt,
  698. int channels,
  699. uint64_t channel_layout);
  700. #endif
  701. #define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
  702. #define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
  703. /**
  704. * Make the filter instance process a command.
  705. * It is recommended to use avfilter_graph_send_command().
  706. */
  707. int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
  708. /** Initialize the filter system. Register all builtin filters. */
  709. void avfilter_register_all(void);
  710. /** Uninitialize the filter system. Unregister all filters. */
  711. void avfilter_uninit(void);
  712. /**
  713. * Register a filter. This is only needed if you plan to use
  714. * avfilter_get_by_name later to lookup the AVFilter structure by name. A
  715. * filter can still by instantiated with avfilter_open even if it is not
  716. * registered.
  717. *
  718. * @param filter the filter to register
  719. * @return 0 if the registration was successful, a negative value
  720. * otherwise
  721. */
  722. int avfilter_register(AVFilter *filter);
  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. AVFilter *avfilter_get_by_name(const char *name);
  731. /**
  732. * If filter is NULL, returns a pointer to the first registered filter pointer,
  733. * if filter is non-NULL, returns the next pointer after filter.
  734. * If the returned pointer points to NULL, the last registered filter
  735. * was already reached.
  736. */
  737. AVFilter **av_filter_next(AVFilter **filter);
  738. /**
  739. * Create a filter instance.
  740. *
  741. * @param filter_ctx put here a pointer to the created filter context
  742. * on success, NULL on failure
  743. * @param filter the filter to create an instance of
  744. * @param inst_name Name to give to the new instance. Can be NULL for none.
  745. * @return >= 0 in case of success, a negative error code otherwise
  746. */
  747. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
  748. /**
  749. * Initialize a filter.
  750. *
  751. * @param filter the filter to initialize
  752. * @param args A string of parameters to use when initializing the filter.
  753. * The format and meaning of this string varies by filter.
  754. * @param opaque Any extra non-string data needed by the filter. The meaning
  755. * of this parameter varies by filter.
  756. * @return zero on success
  757. */
  758. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  759. /**
  760. * Free a filter context.
  761. *
  762. * @param filter the filter to free
  763. */
  764. void avfilter_free(AVFilterContext *filter);
  765. /**
  766. * Insert a filter in the middle of an existing link.
  767. *
  768. * @param link the link into which the filter should be inserted
  769. * @param filt the filter to be inserted
  770. * @param filt_srcpad_idx the input pad on the filter to connect
  771. * @param filt_dstpad_idx the output pad on the filter to connect
  772. * @return zero on success
  773. */
  774. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  775. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
  776. #if FF_API_AVFILTERBUFFER
  777. /**
  778. * Copy the frame properties of src to dst, without copying the actual
  779. * image data.
  780. *
  781. * @return 0 on success, a negative number on error.
  782. */
  783. attribute_deprecated
  784. int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
  785. /**
  786. * Copy the frame properties and data pointers of src to dst, without copying
  787. * the actual data.
  788. *
  789. * @return 0 on success, a negative number on error.
  790. */
  791. attribute_deprecated
  792. int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
  793. #endif
  794. /**
  795. * @return AVClass for AVFilterContext.
  796. *
  797. * @see av_opt_find().
  798. */
  799. const AVClass *avfilter_get_class(void);
  800. /**
  801. * @}
  802. */
  803. #endif /* AVFILTER_AVFILTER_H */