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.

1171 lines
41KB

  1. /*
  2. * filter layer
  3. * Copyright (c) 2007 Bobby Bingham
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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 "libavutil/attributes.h"
  33. #include "libavutil/avutil.h"
  34. #include "libavutil/frame.h"
  35. #include "libavutil/log.h"
  36. #include "libavutil/samplefmt.h"
  37. #include "libavutil/pixfmt.h"
  38. #include "libavutil/rational.h"
  39. #include <stddef.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. /**
  101. * Audio specific properties in a reference to an AVFilterBuffer. Since
  102. * AVFilterBufferRef is common to different media formats, audio specific
  103. * per reference properties must be separated out.
  104. */
  105. typedef struct AVFilterBufferRefAudioProps {
  106. uint64_t channel_layout; ///< channel layout of audio buffer
  107. int nb_samples; ///< number of audio samples
  108. int sample_rate; ///< audio buffer sample rate
  109. int planar; ///< audio buffer - planar or packed
  110. } AVFilterBufferRefAudioProps;
  111. /**
  112. * Video specific properties in a reference to an AVFilterBuffer. Since
  113. * AVFilterBufferRef is common to different media formats, video specific
  114. * per reference properties must be separated out.
  115. */
  116. typedef struct AVFilterBufferRefVideoProps {
  117. int w; ///< image width
  118. int h; ///< image height
  119. AVRational pixel_aspect; ///< pixel aspect ratio
  120. int interlaced; ///< is frame interlaced
  121. int top_field_first; ///< field order
  122. enum AVPictureType pict_type; ///< picture type of the frame
  123. int key_frame; ///< 1 -> keyframe, 0-> not
  124. } AVFilterBufferRefVideoProps;
  125. /**
  126. * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
  127. * a buffer to, for example, crop image without any memcpy, the buffer origin
  128. * and dimensions are per-reference properties. Linesize is also useful for
  129. * image flipping, frame to field filters, etc, and so is also per-reference.
  130. *
  131. * TODO: add anything necessary for frame reordering
  132. */
  133. typedef struct AVFilterBufferRef {
  134. AVFilterBuffer *buf; ///< the buffer that this is a reference to
  135. uint8_t *data[8]; ///< picture/audio data for each plane
  136. /**
  137. * pointers to the data planes/channels.
  138. *
  139. * For video, this should simply point to data[].
  140. *
  141. * For planar audio, each channel has a separate data pointer, and
  142. * linesize[0] contains the size of each channel buffer.
  143. * For packed audio, there is just one data pointer, and linesize[0]
  144. * contains the total size of the buffer for all channels.
  145. *
  146. * Note: Both data and extended_data will always be set, but for planar
  147. * audio with more channels that can fit in data, extended_data must be used
  148. * in order to access all channels.
  149. */
  150. uint8_t **extended_data;
  151. int linesize[8]; ///< number of bytes per line
  152. AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
  153. AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
  154. /**
  155. * presentation timestamp. The time unit may change during
  156. * filtering, as it is specified in the link and the filter code
  157. * may need to rescale the PTS accordingly.
  158. */
  159. int64_t pts;
  160. int64_t pos; ///< byte position in stream, -1 if unknown
  161. int format; ///< media format
  162. int perms; ///< permissions, see the AV_PERM_* flags
  163. enum AVMediaType type; ///< media type of buffer data
  164. } AVFilterBufferRef;
  165. /**
  166. * Copy properties of src to dst, without copying the actual data
  167. */
  168. attribute_deprecated
  169. void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
  170. /**
  171. * Add a new reference to a buffer.
  172. *
  173. * @param ref an existing reference to the buffer
  174. * @param pmask a bitmask containing the allowable permissions in the new
  175. * reference
  176. * @return a new reference to the buffer with the same properties as the
  177. * old, excluding any permissions denied by pmask
  178. */
  179. attribute_deprecated
  180. AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
  181. /**
  182. * Remove a reference to a buffer. If this is the last reference to the
  183. * buffer, the buffer itself is also automatically freed.
  184. *
  185. * @param ref reference to the buffer, may be NULL
  186. *
  187. * @note it is recommended to use avfilter_unref_bufferp() instead of this
  188. * function
  189. */
  190. attribute_deprecated
  191. void avfilter_unref_buffer(AVFilterBufferRef *ref);
  192. /**
  193. * Remove a reference to a buffer and set the pointer to NULL.
  194. * If this is the last reference to the buffer, the buffer itself
  195. * is also automatically freed.
  196. *
  197. * @param ref pointer to the buffer reference
  198. */
  199. attribute_deprecated
  200. void avfilter_unref_bufferp(AVFilterBufferRef **ref);
  201. #endif
  202. #if FF_API_AVFILTERPAD_PUBLIC
  203. /**
  204. * A filter pad used for either input or output.
  205. *
  206. * @warning this struct will be removed from public API.
  207. * users should call avfilter_pad_get_name() and avfilter_pad_get_type()
  208. * to access the name and type fields; there should be no need to access
  209. * any other fields from outside of libavfilter.
  210. */
  211. struct AVFilterPad {
  212. /**
  213. * Pad name. The name is unique among inputs and among outputs, but an
  214. * input may have the same name as an output. This may be NULL if this
  215. * pad has no need to ever be referenced by name.
  216. */
  217. const char *name;
  218. /**
  219. * AVFilterPad type.
  220. */
  221. enum AVMediaType type;
  222. /**
  223. * Minimum required permissions on incoming buffers. Any buffer with
  224. * insufficient permissions will be automatically copied by the filter
  225. * system to a new buffer which provides the needed access permissions.
  226. *
  227. * Input pads only.
  228. */
  229. attribute_deprecated int min_perms;
  230. /**
  231. * Permissions which are not accepted on incoming buffers. Any buffer
  232. * which has any of these permissions set will be automatically copied
  233. * by the filter system to a new buffer which does not have those
  234. * permissions. This can be used to easily disallow buffers with
  235. * AV_PERM_REUSE.
  236. *
  237. * Input pads only.
  238. */
  239. attribute_deprecated int rej_perms;
  240. /**
  241. * @deprecated unused
  242. */
  243. int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
  244. /**
  245. * Callback function to get a video buffer. If NULL, the filter system will
  246. * use avfilter_default_get_video_buffer().
  247. *
  248. * Input video pads only.
  249. */
  250. AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
  251. /**
  252. * Callback function to get an audio buffer. If NULL, the filter system will
  253. * use avfilter_default_get_audio_buffer().
  254. *
  255. * Input audio pads only.
  256. */
  257. AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
  258. /**
  259. * @deprecated unused
  260. */
  261. int (*end_frame)(AVFilterLink *link);
  262. /**
  263. * @deprecated unused
  264. */
  265. int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  266. /**
  267. * Filtering callback. This is where a filter receives a frame with
  268. * audio/video data and should do its processing.
  269. *
  270. * Input pads only.
  271. *
  272. * @return >= 0 on success, a negative AVERROR on error. This function
  273. * must ensure that samplesref is properly unreferenced on error if it
  274. * hasn't been passed on to another filter.
  275. */
  276. int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
  277. /**
  278. * Frame poll callback. This returns the number of immediately available
  279. * samples. It should return a positive value if the next request_frame()
  280. * is guaranteed to return one frame (with no delay).
  281. *
  282. * Defaults to just calling the source poll_frame() method.
  283. *
  284. * Output pads only.
  285. */
  286. int (*poll_frame)(AVFilterLink *link);
  287. /**
  288. * Frame request callback. A call to this should result in at least one
  289. * frame being output over the given link. This should return zero on
  290. * success, and another value on error.
  291. *
  292. * Output pads only.
  293. */
  294. int (*request_frame)(AVFilterLink *link);
  295. /**
  296. * Link configuration callback.
  297. *
  298. * For output pads, this should set the link properties such as
  299. * width/height. This should NOT set the format property - that is
  300. * negotiated between filters by the filter system using the
  301. * query_formats() callback before this function is called.
  302. *
  303. * For input pads, this should check the properties of the link, and update
  304. * the filter's internal state as necessary.
  305. *
  306. * For both input and output filters, this should return zero on success,
  307. * and another value on error.
  308. */
  309. int (*config_props)(AVFilterLink *link);
  310. /**
  311. * The filter expects a fifo to be inserted on its input link,
  312. * typically because it has a delay.
  313. *
  314. * input pads only.
  315. */
  316. int needs_fifo;
  317. /**
  318. * The filter expects writable frames from its input link,
  319. * duplicating data buffers if needed.
  320. *
  321. * input pads only.
  322. */
  323. int needs_writable;
  324. };
  325. #endif
  326. /**
  327. * Get the number of elements in a NULL-terminated array of AVFilterPads (e.g.
  328. * AVFilter.inputs/outputs).
  329. */
  330. int avfilter_pad_count(const AVFilterPad *pads);
  331. /**
  332. * Get the name of an AVFilterPad.
  333. *
  334. * @param pads an array of AVFilterPads
  335. * @param pad_idx index of the pad in the array it; is the caller's
  336. * responsibility to ensure the index is valid
  337. *
  338. * @return name of the pad_idx'th pad in pads
  339. */
  340. const char *avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx);
  341. /**
  342. * Get the type of an AVFilterPad.
  343. *
  344. * @param pads an array of AVFilterPads
  345. * @param pad_idx index of the pad in the array; it is the caller's
  346. * responsibility to ensure the index is valid
  347. *
  348. * @return type of the pad_idx'th pad in pads
  349. */
  350. enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx);
  351. /**
  352. * The number of the filter inputs is not determined just by AVFilter.inputs.
  353. * The filter might add additional inputs during initialization depending on the
  354. * options supplied to it.
  355. */
  356. #define AVFILTER_FLAG_DYNAMIC_INPUTS (1 << 0)
  357. /**
  358. * The number of the filter outputs is not determined just by AVFilter.outputs.
  359. * The filter might add additional outputs during initialization depending on
  360. * the options supplied to it.
  361. */
  362. #define AVFILTER_FLAG_DYNAMIC_OUTPUTS (1 << 1)
  363. /**
  364. * The filter supports multithreading by splitting frames into multiple parts
  365. * and processing them concurrently.
  366. */
  367. #define AVFILTER_FLAG_SLICE_THREADS (1 << 2)
  368. /**
  369. * Filter definition. This defines the pads a filter contains, and all the
  370. * callback functions used to interact with the filter.
  371. */
  372. typedef struct AVFilter {
  373. /**
  374. * Filter name. Must be non-NULL and unique among filters.
  375. */
  376. const char *name;
  377. /**
  378. * A description of the filter. May be NULL.
  379. *
  380. * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
  381. */
  382. const char *description;
  383. /**
  384. * List of inputs, terminated by a zeroed element.
  385. *
  386. * NULL if there are no (static) inputs. Instances of filters with
  387. * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
  388. * this list.
  389. */
  390. const AVFilterPad *inputs;
  391. /**
  392. * List of outputs, terminated by a zeroed element.
  393. *
  394. * NULL if there are no (static) outputs. Instances of filters with
  395. * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
  396. * this list.
  397. */
  398. const AVFilterPad *outputs;
  399. /**
  400. * A class for the private data, used to declare filter private AVOptions.
  401. * This field is NULL for filters that do not declare any options.
  402. *
  403. * If this field is non-NULL, the first member of the filter private data
  404. * must be a pointer to AVClass, which will be set by libavfilter generic
  405. * code to this class.
  406. */
  407. const AVClass *priv_class;
  408. /**
  409. * A combination of AVFILTER_FLAG_*
  410. */
  411. int flags;
  412. /*****************************************************************
  413. * All fields below this line are not part of the public API. They
  414. * may not be used outside of libavfilter and can be changed and
  415. * removed at will.
  416. * New public fields should be added right above.
  417. *****************************************************************
  418. */
  419. /**
  420. * Filter initialization function.
  421. *
  422. * This callback will be called only once during the filter lifetime, after
  423. * all the options have been set, but before links between filters are
  424. * established and format negotiation is done.
  425. *
  426. * Basic filter initialization should be done here. Filters with dynamic
  427. * inputs and/or outputs should create those inputs/outputs here based on
  428. * provided options. No more changes to this filter's inputs/outputs can be
  429. * done after this callback.
  430. *
  431. * This callback must not assume that the filter links exist or frame
  432. * parameters are known.
  433. *
  434. * @ref AVFilter.uninit "uninit" is guaranteed to be called even if
  435. * initialization fails, so this callback does not have to clean up on
  436. * failure.
  437. *
  438. * @return 0 on success, a negative AVERROR on failure
  439. */
  440. int (*init)(AVFilterContext *ctx);
  441. /**
  442. * Should be set instead of @ref AVFilter.init "init" by the filters that
  443. * want to pass a dictionary of AVOptions to nested contexts that are
  444. * allocated during init.
  445. *
  446. * On return, the options dict should be freed and replaced with one that
  447. * contains all the options which could not be processed by this filter (or
  448. * with NULL if all the options were processed).
  449. *
  450. * Otherwise the semantics is the same as for @ref AVFilter.init "init".
  451. */
  452. int (*init_dict)(AVFilterContext *ctx, AVDictionary **options);
  453. /**
  454. * Filter uninitialization function.
  455. *
  456. * Called only once right before the filter is freed. Should deallocate any
  457. * memory held by the filter, release any buffer references, etc. It does
  458. * not need to deallocate the AVFilterContext.priv memory itself.
  459. *
  460. * This callback may be called even if @ref AVFilter.init "init" was not
  461. * called or failed, so it must be prepared to handle such a situation.
  462. */
  463. void (*uninit)(AVFilterContext *ctx);
  464. /**
  465. * Query formats supported by the filter on its inputs and outputs.
  466. *
  467. * This callback is called after the filter is initialized (so the inputs
  468. * and outputs are fixed), shortly before the format negotiation. This
  469. * callback may be called more than once.
  470. *
  471. * This callback must set AVFilterLink.out_formats on every input link and
  472. * AVFilterLink.in_formats on every output link to a list of pixel/sample
  473. * formats that the filter supports on that link. For audio links, this
  474. * filter must also set @ref AVFilterLink.in_samplerates "in_samplerates" /
  475. * @ref AVFilterLink.out_samplerates "out_samplerates" and
  476. * @ref AVFilterLink.in_channel_layouts "in_channel_layouts" /
  477. * @ref AVFilterLink.out_channel_layouts "out_channel_layouts" analogously.
  478. *
  479. * This callback may be NULL for filters with one input, in which case
  480. * libavfilter assumes that it supports all input formats and preserves
  481. * them on output.
  482. *
  483. * @return zero on success, a negative value corresponding to an
  484. * AVERROR code otherwise
  485. */
  486. int (*query_formats)(AVFilterContext *);
  487. int priv_size; ///< size of private data to allocate for the filter
  488. /**
  489. * Used by the filter registration system. Must not be touched by any other
  490. * code.
  491. */
  492. struct AVFilter *next;
  493. } AVFilter;
  494. /**
  495. * Process multiple parts of the frame concurrently.
  496. */
  497. #define AVFILTER_THREAD_SLICE (1 << 0)
  498. typedef struct AVFilterInternal AVFilterInternal;
  499. /** An instance of a filter */
  500. struct AVFilterContext {
  501. const AVClass *av_class; ///< needed for av_log()
  502. const AVFilter *filter; ///< the AVFilter of which this is an instance
  503. char *name; ///< name of this filter instance
  504. AVFilterPad *input_pads; ///< array of input pads
  505. AVFilterLink **inputs; ///< array of pointers to input links
  506. #if FF_API_FOO_COUNT
  507. attribute_deprecated unsigned input_count; ///< @deprecated use nb_inputs
  508. #endif
  509. unsigned nb_inputs; ///< number of input pads
  510. AVFilterPad *output_pads; ///< array of output pads
  511. AVFilterLink **outputs; ///< array of pointers to output links
  512. #if FF_API_FOO_COUNT
  513. attribute_deprecated unsigned output_count; ///< @deprecated use nb_outputs
  514. #endif
  515. unsigned nb_outputs; ///< number of output pads
  516. void *priv; ///< private data for use by the filter
  517. struct AVFilterGraph *graph; ///< filtergraph this filter belongs to
  518. /**
  519. * Type of multithreading being allowed/used. A combination of
  520. * AVFILTER_THREAD_* flags.
  521. *
  522. * May be set by the caller before initializing the filter to forbid some
  523. * or all kinds of multithreading for this filter. The default is allowing
  524. * everything.
  525. *
  526. * When the filter is initialized, this field is combined using bit AND with
  527. * AVFilterGraph.thread_type to get the final mask used for determining
  528. * allowed threading types. I.e. a threading type needs to be set in both
  529. * to be allowed.
  530. *
  531. * After the filter is initialzed, libavfilter sets this field to the
  532. * threading type that is actually used (0 for no multithreading).
  533. */
  534. int thread_type;
  535. /**
  536. * An opaque struct for libavfilter internal use.
  537. */
  538. AVFilterInternal *internal;
  539. };
  540. /**
  541. * A link between two filters. This contains pointers to the source and
  542. * destination filters between which this link exists, and the indexes of
  543. * the pads involved. In addition, this link also contains the parameters
  544. * which have been negotiated and agreed upon between the filter, such as
  545. * image dimensions, format, etc.
  546. */
  547. struct AVFilterLink {
  548. AVFilterContext *src; ///< source filter
  549. AVFilterPad *srcpad; ///< output pad on the source filter
  550. AVFilterContext *dst; ///< dest filter
  551. AVFilterPad *dstpad; ///< input pad on the dest filter
  552. enum AVMediaType type; ///< filter media type
  553. /* These parameters apply only to video */
  554. int w; ///< agreed upon image width
  555. int h; ///< agreed upon image height
  556. AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
  557. /* These two parameters apply only to audio */
  558. uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/channel_layout.h)
  559. int sample_rate; ///< samples per second
  560. int format; ///< agreed upon media format
  561. /**
  562. * Define the time base used by the PTS of the frames/samples
  563. * which will pass through this link.
  564. * During the configuration stage, each filter is supposed to
  565. * change only the output timebase, while the timebase of the
  566. * input link is assumed to be an unchangeable property.
  567. */
  568. AVRational time_base;
  569. /*****************************************************************
  570. * All fields below this line are not part of the public API. They
  571. * may not be used outside of libavfilter and can be changed and
  572. * removed at will.
  573. * New public fields should be added right above.
  574. *****************************************************************
  575. */
  576. /**
  577. * Lists of formats supported by the input and output filters respectively.
  578. * These lists are used for negotiating the format to actually be used,
  579. * which will be loaded into the format member, above, when chosen.
  580. */
  581. AVFilterFormats *in_formats;
  582. AVFilterFormats *out_formats;
  583. /**
  584. * Lists of channel layouts and sample rates used for automatic
  585. * negotiation.
  586. */
  587. AVFilterFormats *in_samplerates;
  588. AVFilterFormats *out_samplerates;
  589. struct AVFilterChannelLayouts *in_channel_layouts;
  590. struct AVFilterChannelLayouts *out_channel_layouts;
  591. /**
  592. * Audio only, the destination filter sets this to a non-zero value to
  593. * request that buffers with the given number of samples should be sent to
  594. * it. AVFilterPad.needs_fifo must also be set on the corresponding input
  595. * pad.
  596. * Last buffer before EOF will be padded with silence.
  597. */
  598. int request_samples;
  599. /** stage of the initialization of the link properties (dimensions, etc) */
  600. enum {
  601. AVLINK_UNINIT = 0, ///< not started
  602. AVLINK_STARTINIT, ///< started, but incomplete
  603. AVLINK_INIT ///< complete
  604. } init_state;
  605. };
  606. /**
  607. * Link two filters together.
  608. *
  609. * @param src the source filter
  610. * @param srcpad index of the output pad on the source filter
  611. * @param dst the destination filter
  612. * @param dstpad index of the input pad on the destination filter
  613. * @return zero on success
  614. */
  615. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  616. AVFilterContext *dst, unsigned dstpad);
  617. /**
  618. * Negotiate the media format, dimensions, etc of all inputs to a filter.
  619. *
  620. * @param filter the filter to negotiate the properties for its inputs
  621. * @return zero on successful negotiation
  622. */
  623. int avfilter_config_links(AVFilterContext *filter);
  624. #if FF_API_AVFILTERBUFFER
  625. /**
  626. * Create a buffer reference wrapped around an already allocated image
  627. * buffer.
  628. *
  629. * @param data pointers to the planes of the image to reference
  630. * @param linesize linesizes for the planes of the image to reference
  631. * @param perms the required access permissions
  632. * @param w the width of the image specified by the data and linesize arrays
  633. * @param h the height of the image specified by the data and linesize arrays
  634. * @param format the pixel format of the image specified by the data and linesize arrays
  635. */
  636. attribute_deprecated
  637. AVFilterBufferRef *
  638. avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
  639. int w, int h, enum AVPixelFormat format);
  640. /**
  641. * Create an audio buffer reference wrapped around an already
  642. * allocated samples buffer.
  643. *
  644. * @param data pointers to the samples plane buffers
  645. * @param linesize linesize for the samples plane buffers
  646. * @param perms the required access permissions
  647. * @param nb_samples number of samples per channel
  648. * @param sample_fmt the format of each sample in the buffer to allocate
  649. * @param channel_layout the channel layout of the buffer
  650. */
  651. attribute_deprecated
  652. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
  653. int linesize,
  654. int perms,
  655. int nb_samples,
  656. enum AVSampleFormat sample_fmt,
  657. uint64_t channel_layout);
  658. #endif
  659. /** Initialize the filter system. Register all builtin filters. */
  660. void avfilter_register_all(void);
  661. #if FF_API_OLD_FILTER_REGISTER
  662. /** Uninitialize the filter system. Unregister all filters. */
  663. attribute_deprecated
  664. void avfilter_uninit(void);
  665. #endif
  666. /**
  667. * Register a filter. This is only needed if you plan to use
  668. * avfilter_get_by_name later to lookup the AVFilter structure by name. A
  669. * filter can still by instantiated with avfilter_graph_alloc_filter even if it
  670. * is not registered.
  671. *
  672. * @param filter the filter to register
  673. * @return 0 if the registration was succesfull, a negative value
  674. * otherwise
  675. */
  676. int avfilter_register(AVFilter *filter);
  677. /**
  678. * Get a filter definition matching the given name.
  679. *
  680. * @param name the filter name to find
  681. * @return the filter definition, if any matching one is registered.
  682. * NULL if none found.
  683. */
  684. #if !FF_API_NOCONST_GET_NAME
  685. const
  686. #endif
  687. AVFilter *avfilter_get_by_name(const char *name);
  688. /**
  689. * Iterate over all registered filters.
  690. * @return If prev is non-NULL, next registered filter after prev or NULL if
  691. * prev is the last filter. If prev is NULL, return the first registered filter.
  692. */
  693. const AVFilter *avfilter_next(const AVFilter *prev);
  694. #if FF_API_OLD_FILTER_REGISTER
  695. /**
  696. * If filter is NULL, returns a pointer to the first registered filter pointer,
  697. * if filter is non-NULL, returns the next pointer after filter.
  698. * If the returned pointer points to NULL, the last registered filter
  699. * was already reached.
  700. * @deprecated use avfilter_next()
  701. */
  702. attribute_deprecated
  703. AVFilter **av_filter_next(AVFilter **filter);
  704. #endif
  705. #if FF_API_AVFILTER_OPEN
  706. /**
  707. * Create a filter instance.
  708. *
  709. * @param filter_ctx put here a pointer to the created filter context
  710. * on success, NULL on failure
  711. * @param filter the filter to create an instance of
  712. * @param inst_name Name to give to the new instance. Can be NULL for none.
  713. * @return >= 0 in case of success, a negative error code otherwise
  714. * @deprecated use avfilter_graph_alloc_filter() instead
  715. */
  716. attribute_deprecated
  717. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
  718. #endif
  719. #if FF_API_AVFILTER_INIT_FILTER
  720. /**
  721. * Initialize a filter.
  722. *
  723. * @param filter the filter to initialize
  724. * @param args A string of parameters to use when initializing the filter.
  725. * The format and meaning of this string varies by filter.
  726. * @param opaque Any extra non-string data needed by the filter. The meaning
  727. * of this parameter varies by filter.
  728. * @return zero on success
  729. */
  730. attribute_deprecated
  731. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  732. #endif
  733. /**
  734. * Initialize a filter with the supplied parameters.
  735. *
  736. * @param ctx uninitialized filter context to initialize
  737. * @param args Options to initialize the filter with. This must be a
  738. * ':'-separated list of options in the 'key=value' form.
  739. * May be NULL if the options have been set directly using the
  740. * AVOptions API or there are no options that need to be set.
  741. * @return 0 on success, a negative AVERROR on failure
  742. */
  743. int avfilter_init_str(AVFilterContext *ctx, const char *args);
  744. /**
  745. * Initialize a filter with the supplied dictionary of options.
  746. *
  747. * @param ctx uninitialized filter context to initialize
  748. * @param options An AVDictionary filled with options for this filter. On
  749. * return this parameter will be destroyed and replaced with
  750. * a dict containing options that were not found. This dictionary
  751. * must be freed by the caller.
  752. * May be NULL, then this function is equivalent to
  753. * avfilter_init_str() with the second parameter set to NULL.
  754. * @return 0 on success, a negative AVERROR on failure
  755. *
  756. * @note This function and avfilter_init_str() do essentially the same thing,
  757. * the difference is in manner in which the options are passed. It is up to the
  758. * calling code to choose whichever is more preferable. The two functions also
  759. * behave differently when some of the provided options are not declared as
  760. * supported by the filter. In such a case, avfilter_init_str() will fail, but
  761. * this function will leave those extra options in the options AVDictionary and
  762. * continue as usual.
  763. */
  764. int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options);
  765. /**
  766. * Free a filter context. This will also remove the filter from its
  767. * filtergraph's list of filters.
  768. *
  769. * @param filter the filter to free
  770. */
  771. void avfilter_free(AVFilterContext *filter);
  772. /**
  773. * Insert a filter in the middle of an existing link.
  774. *
  775. * @param link the link into which the filter should be inserted
  776. * @param filt the filter to be inserted
  777. * @param filt_srcpad_idx the input pad on the filter to connect
  778. * @param filt_dstpad_idx the output pad on the filter to connect
  779. * @return zero on success
  780. */
  781. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  782. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
  783. #if FF_API_AVFILTERBUFFER
  784. /**
  785. * Copy the frame properties of src to dst, without copying the actual
  786. * image data.
  787. *
  788. * @return 0 on success, a negative number on error.
  789. */
  790. attribute_deprecated
  791. int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
  792. /**
  793. * Copy the frame properties and data pointers of src to dst, without copying
  794. * the actual data.
  795. *
  796. * @return 0 on success, a negative number on error.
  797. */
  798. attribute_deprecated
  799. int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
  800. #endif
  801. /**
  802. * @return AVClass for AVFilterContext.
  803. *
  804. * @see av_opt_find().
  805. */
  806. const AVClass *avfilter_get_class(void);
  807. typedef struct AVFilterGraphInternal AVFilterGraphInternal;
  808. /**
  809. * A function pointer passed to the @ref AVFilterGraph.execute callback to be
  810. * executed multiple times, possibly in parallel.
  811. *
  812. * @param ctx the filter context the job belongs to
  813. * @param arg an opaque parameter passed through from @ref
  814. * AVFilterGraph.execute
  815. * @param jobnr the index of the job being executed
  816. * @param nb_jobs the total number of jobs
  817. *
  818. * @return 0 on success, a negative AVERROR on error
  819. */
  820. typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
  821. /**
  822. * A function executing multiple jobs, possibly in parallel.
  823. *
  824. * @param ctx the filter context to which the jobs belong
  825. * @param func the function to be called multiple times
  826. * @param arg the argument to be passed to func
  827. * @param ret a nb_jobs-sized array to be filled with return values from each
  828. * invocation of func
  829. * @param nb_jobs the number of jobs to execute
  830. *
  831. * @return 0 on success, a negative AVERROR on error
  832. */
  833. typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
  834. void *arg, int *ret, int nb_jobs);
  835. typedef struct AVFilterGraph {
  836. const AVClass *av_class;
  837. #if FF_API_FOO_COUNT
  838. attribute_deprecated
  839. unsigned filter_count;
  840. #endif
  841. AVFilterContext **filters;
  842. #if !FF_API_FOO_COUNT
  843. unsigned nb_filters;
  844. #endif
  845. char *scale_sws_opts; ///< sws options to use for the auto-inserted scale filters
  846. char *resample_lavr_opts; ///< libavresample options to use for the auto-inserted resample filters
  847. #if FF_API_FOO_COUNT
  848. unsigned nb_filters;
  849. #endif
  850. /**
  851. * Type of multithreading allowed for filters in this graph. A combination
  852. * of AVFILTER_THREAD_* flags.
  853. *
  854. * May be set by the caller at any point, the setting will apply to all
  855. * filters initialized after that. The default is allowing everything.
  856. *
  857. * When a filter in this graph is initialized, this field is combined using
  858. * bit AND with AVFilterContext.thread_type to get the final mask used for
  859. * determining allowed threading types. I.e. a threading type needs to be
  860. * set in both to be allowed.
  861. */
  862. int thread_type;
  863. /**
  864. * Maximum number of threads used by filters in this graph. May be set by
  865. * the caller before adding any filters to the filtergraph. Zero (the
  866. * default) means that the number of threads is determined automatically.
  867. */
  868. int nb_threads;
  869. /**
  870. * Opaque object for libavfilter internal use.
  871. */
  872. AVFilterGraphInternal *internal;
  873. /**
  874. * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
  875. * be used from callbacks like @ref AVFilterGraph.execute.
  876. * Libavfilter will not touch this field in any way.
  877. */
  878. void *opaque;
  879. /**
  880. * This callback may be set by the caller immediately after allocating the
  881. * graph and before adding any filters to it, to provide a custom
  882. * multithreading implementation.
  883. *
  884. * If set, filters with slice threading capability will call this callback
  885. * to execute multiple jobs in parallel.
  886. *
  887. * If this field is left unset, libavfilter will use its internal
  888. * implementation, which may or may not be multithreaded depending on the
  889. * platform and build options.
  890. */
  891. avfilter_execute_func *execute;
  892. } AVFilterGraph;
  893. /**
  894. * Allocate a filter graph.
  895. *
  896. * @return the allocated filter graph on success or NULL.
  897. */
  898. AVFilterGraph *avfilter_graph_alloc(void);
  899. /**
  900. * Create a new filter instance in a filter graph.
  901. *
  902. * @param graph graph in which the new filter will be used
  903. * @param filter the filter to create an instance of
  904. * @param name Name to give to the new instance (will be copied to
  905. * AVFilterContext.name). This may be used by the caller to identify
  906. * different filters, libavfilter itself assigns no semantics to
  907. * this parameter. May be NULL.
  908. *
  909. * @return the context of the newly created filter instance (note that it is
  910. * also retrievable directly through AVFilterGraph.filters or with
  911. * avfilter_graph_get_filter()) on success or NULL or failure.
  912. */
  913. AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
  914. const AVFilter *filter,
  915. const char *name);
  916. /**
  917. * Get a filter instance with name name from graph.
  918. *
  919. * @return the pointer to the found filter instance or NULL if it
  920. * cannot be found.
  921. */
  922. AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, char *name);
  923. #if FF_API_AVFILTER_OPEN
  924. /**
  925. * Add an existing filter instance to a filter graph.
  926. *
  927. * @param graphctx the filter graph
  928. * @param filter the filter to be added
  929. *
  930. * @deprecated use avfilter_graph_alloc_filter() to allocate a filter in a
  931. * filter graph
  932. */
  933. attribute_deprecated
  934. int avfilter_graph_add_filter(AVFilterGraph *graphctx, AVFilterContext *filter);
  935. #endif
  936. /**
  937. * Create and add a filter instance into an existing graph.
  938. * The filter instance is created from the filter filt and inited
  939. * with the parameters args and opaque.
  940. *
  941. * In case of success put in *filt_ctx the pointer to the created
  942. * filter instance, otherwise set *filt_ctx to NULL.
  943. *
  944. * @param name the instance name to give to the created filter instance
  945. * @param graph_ctx the filter graph
  946. * @return a negative AVERROR error code in case of failure, a non
  947. * negative value otherwise
  948. */
  949. int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
  950. const char *name, const char *args, void *opaque,
  951. AVFilterGraph *graph_ctx);
  952. /**
  953. * Check validity and configure all the links and formats in the graph.
  954. *
  955. * @param graphctx the filter graph
  956. * @param log_ctx context used for logging
  957. * @return 0 in case of success, a negative AVERROR code otherwise
  958. */
  959. int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx);
  960. /**
  961. * Free a graph, destroy its links, and set *graph to NULL.
  962. * If *graph is NULL, do nothing.
  963. */
  964. void avfilter_graph_free(AVFilterGraph **graph);
  965. /**
  966. * A linked-list of the inputs/outputs of the filter chain.
  967. *
  968. * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
  969. * where it is used to communicate open (unlinked) inputs and outputs from and
  970. * to the caller.
  971. * This struct specifies, per each not connected pad contained in the graph, the
  972. * filter context and the pad index required for establishing a link.
  973. */
  974. typedef struct AVFilterInOut {
  975. /** unique name for this input/output in the list */
  976. char *name;
  977. /** filter context associated to this input/output */
  978. AVFilterContext *filter_ctx;
  979. /** index of the filt_ctx pad to use for linking */
  980. int pad_idx;
  981. /** next input/input in the list, NULL if this is the last */
  982. struct AVFilterInOut *next;
  983. } AVFilterInOut;
  984. /**
  985. * Allocate a single AVFilterInOut entry.
  986. * Must be freed with avfilter_inout_free().
  987. * @return allocated AVFilterInOut on success, NULL on failure.
  988. */
  989. AVFilterInOut *avfilter_inout_alloc(void);
  990. /**
  991. * Free the supplied list of AVFilterInOut and set *inout to NULL.
  992. * If *inout is NULL, do nothing.
  993. */
  994. void avfilter_inout_free(AVFilterInOut **inout);
  995. /**
  996. * Add a graph described by a string to a graph.
  997. *
  998. * @param graph the filter graph where to link the parsed graph context
  999. * @param filters string to be parsed
  1000. * @param inputs linked list to the inputs of the graph
  1001. * @param outputs linked list to the outputs of the graph
  1002. * @return zero on success, a negative AVERROR code on error
  1003. */
  1004. int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
  1005. AVFilterInOut *inputs, AVFilterInOut *outputs,
  1006. void *log_ctx);
  1007. /**
  1008. * Add a graph described by a string to a graph.
  1009. *
  1010. * @param[in] graph the filter graph where to link the parsed graph context
  1011. * @param[in] filters string to be parsed
  1012. * @param[out] inputs a linked list of all free (unlinked) inputs of the
  1013. * parsed graph will be returned here. It is to be freed
  1014. * by the caller using avfilter_inout_free().
  1015. * @param[out] outputs a linked list of all free (unlinked) outputs of the
  1016. * parsed graph will be returned here. It is to be freed by the
  1017. * caller using avfilter_inout_free().
  1018. * @return zero on success, a negative AVERROR code on error
  1019. *
  1020. * @note the difference between avfilter_graph_parse2() and
  1021. * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
  1022. * the lists of inputs and outputs, which therefore must be known before calling
  1023. * the function. On the other hand, avfilter_graph_parse2() \em returns the
  1024. * inputs and outputs that are left unlinked after parsing the graph and the
  1025. * caller then deals with them. Another difference is that in
  1026. * avfilter_graph_parse(), the inputs parameter describes inputs of the
  1027. * <em>already existing</em> part of the graph; i.e. from the point of view of
  1028. * the newly created part, they are outputs. Similarly the outputs parameter
  1029. * describes outputs of the already existing filters, which are provided as
  1030. * inputs to the parsed filters.
  1031. * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
  1032. * whatsoever to already existing parts of the graph and the inputs parameter
  1033. * will on return contain inputs of the newly parsed part of the graph.
  1034. * Analogously the outputs parameter will contain outputs of the newly created
  1035. * filters.
  1036. */
  1037. int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
  1038. AVFilterInOut **inputs,
  1039. AVFilterInOut **outputs);
  1040. /**
  1041. * @}
  1042. */
  1043. #endif /* AVFILTER_AVFILTER_H */