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.

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