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.

1001 lines
35KB

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