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.

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