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.

730 lines
28KB

  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. #define LIBAVFILTER_VERSION_MAJOR 1
  25. #define LIBAVFILTER_VERSION_MINOR 34
  26. #define LIBAVFILTER_VERSION_MICRO 1
  27. #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
  28. LIBAVFILTER_VERSION_MINOR, \
  29. LIBAVFILTER_VERSION_MICRO)
  30. #define LIBAVFILTER_VERSION AV_VERSION(LIBAVFILTER_VERSION_MAJOR, \
  31. LIBAVFILTER_VERSION_MINOR, \
  32. LIBAVFILTER_VERSION_MICRO)
  33. #define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT
  34. #include <stddef.h>
  35. #include "libavcodec/avcodec.h"
  36. /**
  37. * Return the LIBAVFILTER_VERSION_INT constant.
  38. */
  39. unsigned avfilter_version(void);
  40. /**
  41. * Return the libavfilter build-time configuration.
  42. */
  43. const char *avfilter_configuration(void);
  44. /**
  45. * Return the libavfilter license.
  46. */
  47. const char *avfilter_license(void);
  48. typedef struct AVFilterContext AVFilterContext;
  49. typedef struct AVFilterLink AVFilterLink;
  50. typedef struct AVFilterPad AVFilterPad;
  51. /**
  52. * A reference-counted buffer data type used by the filter system. Filters
  53. * should not store pointers to this structure directly, but instead use the
  54. * AVFilterBufferRef structure below.
  55. */
  56. typedef struct AVFilterBuffer {
  57. uint8_t *data[8]; ///< buffer data for each plane/channel
  58. int linesize[8]; ///< number of bytes per line
  59. unsigned refcount; ///< number of references to this buffer
  60. /** private data to be used by a custom free function */
  61. void *priv;
  62. /**
  63. * A pointer to the function to deallocate this buffer if the default
  64. * function is not sufficient. This could, for example, add the memory
  65. * back into a memory pool to be reused later without the overhead of
  66. * reallocating it from scratch.
  67. */
  68. void (*free)(struct AVFilterBuffer *buf);
  69. } AVFilterBuffer;
  70. #define AV_PERM_READ 0x01 ///< can read from the buffer
  71. #define AV_PERM_WRITE 0x02 ///< can write to the buffer
  72. #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
  73. #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time
  74. #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time
  75. /**
  76. * Video specific properties in a reference to an AVFilterBuffer. Since
  77. * AVFilterBufferRef is common to different media formats, video specific
  78. * per reference properties must be separated out.
  79. */
  80. typedef struct AVFilterBufferRefVideoProps {
  81. int w; ///< image width
  82. int h; ///< image height
  83. AVRational pixel_aspect; ///< pixel aspect ratio
  84. int interlaced; ///< is frame interlaced
  85. int top_field_first; ///< field order
  86. } AVFilterBufferRefVideoProps;
  87. /**
  88. * A reference to an AVFilterBuffer. Since filters can manipulate the origin of
  89. * a buffer to, for example, crop image without any memcpy, the buffer origin
  90. * and dimensions are per-reference properties. Linesize is also useful for
  91. * image flipping, frame to field filters, etc, and so is also per-reference.
  92. *
  93. * TODO: add anything necessary for frame reordering
  94. */
  95. typedef struct AVFilterBufferRef {
  96. AVFilterBuffer *buf; ///< the buffer that this is a reference to
  97. uint8_t *data[8]; ///< picture data for each plane
  98. int linesize[8]; ///< number of bytes per line
  99. int format; ///< media format
  100. int64_t pts; ///< presentation timestamp in units of 1/AV_TIME_BASE
  101. int64_t pos; ///< byte position in stream, -1 if unknown
  102. int perms; ///< permissions, see the AV_PERM_* flags
  103. enum AVMediaType type; ///< media type of buffer data
  104. AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
  105. } AVFilterBufferRef;
  106. /**
  107. * Copy properties of src to dst, without copying the actual video
  108. * data.
  109. */
  110. static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
  111. {
  112. // copy common properties
  113. dst->pts = src->pts;
  114. dst->pos = src->pos;
  115. switch (src->type) {
  116. case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
  117. }
  118. }
  119. /**
  120. * Add a new reference to a buffer.
  121. * @param ref an existing reference to the buffer
  122. * @param pmask a bitmask containing the allowable permissions in the new
  123. * reference
  124. * @return a new reference to the buffer with the same properties as the
  125. * old, excluding any permissions denied by pmask
  126. */
  127. AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
  128. /**
  129. * Remove a reference to a buffer. If this is the last reference to the
  130. * buffer, the buffer itself is also automatically freed.
  131. * @param ref reference to the buffer
  132. */
  133. void avfilter_unref_buffer(AVFilterBufferRef *ref);
  134. /**
  135. * A list of supported formats for one end of a filter link. This is used
  136. * during the format negotiation process to try to pick the best format to
  137. * use to minimize the number of necessary conversions. Each filter gives a
  138. * list of the formats supported by each input and output pad. The list
  139. * given for each pad need not be distinct - they may be references to the
  140. * same list of formats, as is often the case when a filter supports multiple
  141. * formats, but will always output the same format as it is given in input.
  142. *
  143. * In this way, a list of possible input formats and a list of possible
  144. * output formats are associated with each link. When a set of formats is
  145. * negotiated over a link, the input and output lists are merged to form a
  146. * new list containing only the common elements of each list. In the case
  147. * that there were no common elements, a format conversion is necessary.
  148. * Otherwise, the lists are merged, and all other links which reference
  149. * either of the format lists involved in the merge are also affected.
  150. *
  151. * For example, consider the filter chain:
  152. * filter (a) --> (b) filter (b) --> (c) filter
  153. *
  154. * where the letters in parenthesis indicate a list of formats supported on
  155. * the input or output of the link. Suppose the lists are as follows:
  156. * (a) = {A, B}
  157. * (b) = {A, B, C}
  158. * (c) = {B, C}
  159. *
  160. * First, the first link's lists are merged, yielding:
  161. * filter (a) --> (a) filter (a) --> (c) filter
  162. *
  163. * Notice that format list (b) now refers to the same list as filter list (a).
  164. * Next, the lists for the second link are merged, yielding:
  165. * filter (a) --> (a) filter (a) --> (a) filter
  166. *
  167. * where (a) = {B}.
  168. *
  169. * Unfortunately, when the format lists at the two ends of a link are merged,
  170. * we must ensure that all links which reference either pre-merge format list
  171. * get updated as well. Therefore, we have the format list structure store a
  172. * pointer to each of the pointers to itself.
  173. */
  174. typedef struct AVFilterFormats {
  175. unsigned format_count; ///< number of formats
  176. int *formats; ///< list of media formats
  177. unsigned refcount; ///< number of references to this list
  178. struct AVFilterFormats ***refs; ///< references to this list
  179. } AVFilterFormats;;
  180. /**
  181. * Create a list of supported formats. This is intended for use in
  182. * AVFilter->query_formats().
  183. * @param fmts list of media formats, terminated by -1
  184. * @return the format list, with no existing references
  185. */
  186. AVFilterFormats *avfilter_make_format_list(const int *fmts);
  187. /**
  188. * Add fmt to the list of media formats contained in *avff.
  189. * If *avff is NULL the function allocates the filter formats struct
  190. * and puts its pointer in *avff.
  191. *
  192. * @return a non negative value in case of success, or a negative
  193. * value corresponding to an AVERROR code in case of error
  194. */
  195. int avfilter_add_format(AVFilterFormats **avff, int fmt);
  196. /**
  197. * Return a list of all formats supported by FFmpeg for the given media type.
  198. */
  199. AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
  200. /**
  201. * Return a format list which contains the intersection of the formats of
  202. * a and b. Also, all the references of a, all the references of b, and
  203. * a and b themselves will be deallocated.
  204. *
  205. * If a and b do not share any common formats, neither is modified, and NULL
  206. * is returned.
  207. */
  208. AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
  209. /**
  210. * Add *ref as a new reference to formats.
  211. * That is the pointers will point like in the ascii art below:
  212. * ________
  213. * |formats |<--------.
  214. * | ____ | ____|___________________
  215. * | |refs| | | __|_
  216. * | |* * | | | | | | AVFilterLink
  217. * | |* *--------->|*ref|
  218. * | |____| | | |____|
  219. * |________| |________________________
  220. */
  221. void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
  222. /**
  223. * If *ref is non-NULL, remove *ref as a reference to the format list
  224. * it currently points to, deallocates that list if this was the last
  225. * reference, and sets *ref to NULL.
  226. *
  227. * Before After
  228. * ________ ________ NULL
  229. * |formats |<--------. |formats | ^
  230. * | ____ | ____|________________ | ____ | ____|________________
  231. * | |refs| | | __|_ | |refs| | | __|_
  232. * | |* * | | | | | | AVFilterLink | |* * | | | | | | AVFilterLink
  233. * | |* *--------->|*ref| | |* | | | |*ref|
  234. * | |____| | | |____| | |____| | | |____|
  235. * |________| |_____________________ |________| |_____________________
  236. */
  237. void avfilter_formats_unref(AVFilterFormats **ref);
  238. /**
  239. *
  240. * Before After
  241. * ________ ________
  242. * |formats |<---------. |formats |<---------.
  243. * | ____ | ___|___ | ____ | ___|___
  244. * | |refs| | | | | | |refs| | | | | NULL
  245. * | |* *--------->|*oldref| | |* *--------->|*newref| ^
  246. * | |* * | | |_______| | |* * | | |_______| ___|___
  247. * | |____| | | |____| | | | |
  248. * |________| |________| |*oldref|
  249. * |_______|
  250. */
  251. void avfilter_formats_changeref(AVFilterFormats **oldref,
  252. AVFilterFormats **newref);
  253. /**
  254. * A filter pad used for either input or output.
  255. */
  256. struct AVFilterPad {
  257. /**
  258. * Pad name. The name is unique among inputs and among outputs, but an
  259. * input may have the same name as an output. This may be NULL if this
  260. * pad has no need to ever be referenced by name.
  261. */
  262. const char *name;
  263. /**
  264. * AVFilterPad type. Only video supported now, hopefully someone will
  265. * add audio in the future.
  266. */
  267. enum AVMediaType type;
  268. /**
  269. * Minimum required permissions on incoming buffers. Any buffer with
  270. * insufficient permissions will be automatically copied by the filter
  271. * system to a new buffer which provides the needed access permissions.
  272. *
  273. * Input pads only.
  274. */
  275. int min_perms;
  276. /**
  277. * Permissions which are not accepted on incoming buffers. Any buffer
  278. * which has any of these permissions set will be automatically copied
  279. * by the filter system to a new buffer which does not have those
  280. * permissions. This can be used to easily disallow buffers with
  281. * AV_PERM_REUSE.
  282. *
  283. * Input pads only.
  284. */
  285. int rej_perms;
  286. /**
  287. * Callback called before passing the first slice of a new frame. If
  288. * NULL, the filter layer will default to storing a reference to the
  289. * picture inside the link structure.
  290. *
  291. * Input video pads only.
  292. */
  293. void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
  294. /**
  295. * Callback function to get a buffer. If NULL, the filter system will
  296. * use avfilter_default_get_video_buffer().
  297. *
  298. * Input video pads only.
  299. */
  300. AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
  301. /**
  302. * Callback called after the slices of a frame are completely sent. If
  303. * NULL, the filter layer will default to releasing the reference stored
  304. * in the link structure during start_frame().
  305. *
  306. * Input video pads only.
  307. */
  308. void (*end_frame)(AVFilterLink *link);
  309. /**
  310. * Slice drawing callback. This is where a filter receives video data
  311. * and should do its processing.
  312. *
  313. * Input video pads only.
  314. */
  315. void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  316. /**
  317. * Frame poll callback. This returns the number of immediately available
  318. * frames. It should return a positive value if the next request_frame()
  319. * is guaranteed to return one frame (with no delay).
  320. *
  321. * Defaults to just calling the source poll_frame() method.
  322. *
  323. * Output video pads only.
  324. */
  325. int (*poll_frame)(AVFilterLink *link);
  326. /**
  327. * Frame request callback. A call to this should result in at least one
  328. * frame being output over the given link. This should return zero on
  329. * success, and another value on error.
  330. *
  331. * Output video pads only.
  332. */
  333. int (*request_frame)(AVFilterLink *link);
  334. /**
  335. * Link configuration callback.
  336. *
  337. * For output pads, this should set the link properties such as
  338. * width/height. This should NOT set the format property - that is
  339. * negotiated between filters by the filter system using the
  340. * query_formats() callback before this function is called.
  341. *
  342. * For input pads, this should check the properties of the link, and update
  343. * the filter's internal state as necessary.
  344. *
  345. * For both input and output filters, this should return zero on success,
  346. * and another value on error.
  347. */
  348. int (*config_props)(AVFilterLink *link);
  349. };
  350. /** default handler for start_frame() for video inputs */
  351. void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
  352. /** default handler for draw_slice() for video inputs */
  353. void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
  354. /** default handler for end_frame() for video inputs */
  355. void avfilter_default_end_frame(AVFilterLink *link);
  356. /** default handler for config_props() for video outputs */
  357. int avfilter_default_config_output_link(AVFilterLink *link);
  358. /** default handler for config_props() for video inputs */
  359. int avfilter_default_config_input_link (AVFilterLink *link);
  360. /** default handler for get_video_buffer() for video inputs */
  361. AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
  362. int perms, int w, int h);
  363. /**
  364. * A helper for query_formats() which sets all links to the same list of
  365. * formats. If there are no links hooked to this filter, the list of formats is
  366. * freed.
  367. */
  368. void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
  369. /** Default handler for query_formats() */
  370. int avfilter_default_query_formats(AVFilterContext *ctx);
  371. /** start_frame() handler for filters which simply pass video along */
  372. void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
  373. /** draw_slice() handler for filters which simply pass video along */
  374. void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
  375. /** end_frame() handler for filters which simply pass video along */
  376. void avfilter_null_end_frame(AVFilterLink *link);
  377. /** get_video_buffer() handler for filters which simply pass video along */
  378. AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
  379. int perms, int w, int h);
  380. /**
  381. * Filter definition. This defines the pads a filter contains, and all the
  382. * callback functions used to interact with the filter.
  383. */
  384. typedef struct AVFilter {
  385. const char *name; ///< filter name
  386. int priv_size; ///< size of private data to allocate for the filter
  387. /**
  388. * Filter initialization function. Args contains the user-supplied
  389. * parameters. FIXME: maybe an AVOption-based system would be better?
  390. * opaque is data provided by the code requesting creation of the filter,
  391. * and is used to pass data to the filter.
  392. */
  393. int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
  394. /**
  395. * Filter uninitialization function. Should deallocate any memory held
  396. * by the filter, release any buffer references, etc. This does not need
  397. * to deallocate the AVFilterContext->priv memory itself.
  398. */
  399. void (*uninit)(AVFilterContext *ctx);
  400. /**
  401. * Queries formats supported by the filter and its pads, and sets the
  402. * in_formats for links connected to its output pads, and out_formats
  403. * for links connected to its input pads.
  404. *
  405. * @return zero on success, a negative value corresponding to an
  406. * AVERROR code otherwise
  407. */
  408. int (*query_formats)(AVFilterContext *);
  409. const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none
  410. const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
  411. /**
  412. * A description for the filter. You should use the
  413. * NULL_IF_CONFIG_SMALL() macro to define it.
  414. */
  415. const char *description;
  416. } AVFilter;
  417. /** An instance of a filter */
  418. struct AVFilterContext {
  419. const AVClass *av_class; ///< needed for av_log()
  420. AVFilter *filter; ///< the AVFilter of which this is an instance
  421. char *name; ///< name of this filter instance
  422. unsigned input_count; ///< number of input pads
  423. AVFilterPad *input_pads; ///< array of input pads
  424. AVFilterLink **inputs; ///< array of pointers to input links
  425. unsigned output_count; ///< number of output pads
  426. AVFilterPad *output_pads; ///< array of output pads
  427. AVFilterLink **outputs; ///< array of pointers to output links
  428. void *priv; ///< private data for use by the filter
  429. };
  430. /**
  431. * A link between two filters. This contains pointers to the source and
  432. * destination filters between which this link exists, and the indexes of
  433. * the pads involved. In addition, this link also contains the parameters
  434. * which have been negotiated and agreed upon between the filter, such as
  435. * image dimensions, format, etc.
  436. */
  437. struct AVFilterLink {
  438. AVFilterContext *src; ///< source filter
  439. unsigned int srcpad; ///< index of the output pad on the source filter
  440. AVFilterContext *dst; ///< dest filter
  441. unsigned int dstpad; ///< index of the input pad on the dest filter
  442. /** stage of the initialization of the link properties (dimensions, etc) */
  443. enum {
  444. AVLINK_UNINIT = 0, ///< not started
  445. AVLINK_STARTINIT, ///< started, but incomplete
  446. AVLINK_INIT ///< complete
  447. } init_state;
  448. enum AVMediaType type; ///< filter media type
  449. int w; ///< agreed upon image width
  450. int h; ///< agreed upon image height
  451. int format; ///< agreed upon media format
  452. /**
  453. * Lists of formats supported by the input and output filters respectively.
  454. * These lists are used for negotiating the format to actually be used,
  455. * which will be loaded into the format member, above, when chosen.
  456. */
  457. AVFilterFormats *in_formats;
  458. AVFilterFormats *out_formats;
  459. /**
  460. * The buffer reference currently being sent across the link by the source
  461. * filter. This is used internally by the filter system to allow
  462. * automatic copying of buffers which do not have sufficient permissions
  463. * for the destination. This should not be accessed directly by the
  464. * filters.
  465. */
  466. AVFilterBufferRef *src_buf;
  467. AVFilterBufferRef *cur_buf;
  468. AVFilterBufferRef *out_buf;
  469. };
  470. /**
  471. * Link two filters together.
  472. * @param src the source filter
  473. * @param srcpad index of the output pad on the source filter
  474. * @param dst the destination filter
  475. * @param dstpad index of the input pad on the destination filter
  476. * @return zero on success
  477. */
  478. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  479. AVFilterContext *dst, unsigned dstpad);
  480. /**
  481. * Negotiate the media format, dimensions, etc of all inputs to a filter.
  482. * @param filter the filter to negotiate the properties for its inputs
  483. * @return zero on successful negotiation
  484. */
  485. int avfilter_config_links(AVFilterContext *filter);
  486. /**
  487. * Request a picture buffer with a specific set of permissions.
  488. * @param link the output link to the filter from which the buffer will
  489. * be requested
  490. * @param perms the required access permissions
  491. * @param w the minimum width of the buffer to allocate
  492. * @param h the minimum height of the buffer to allocate
  493. * @return A reference to the buffer. This must be unreferenced with
  494. * avfilter_unref_buffer when you are finished with it.
  495. */
  496. AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
  497. int w, int h);
  498. /**
  499. * Request an input frame from the filter at the other end of the link.
  500. * @param link the input link
  501. * @return zero on success
  502. */
  503. int avfilter_request_frame(AVFilterLink *link);
  504. /**
  505. * Poll a frame from the filter chain.
  506. * @param link the input link
  507. * @return the number of immediately available frames, a negative
  508. * number in case of error
  509. */
  510. int avfilter_poll_frame(AVFilterLink *link);
  511. /**
  512. * Notifie the next filter of the start of a frame.
  513. * @param link the output link the frame will be sent over
  514. * @param picref A reference to the frame about to be sent. The data for this
  515. * frame need only be valid once draw_slice() is called for that
  516. * portion. The receiving filter will free this reference when
  517. * it no longer needs it.
  518. */
  519. void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
  520. /**
  521. * Notifie the next filter that the current frame has finished.
  522. * @param link the output link the frame was sent over
  523. */
  524. void avfilter_end_frame(AVFilterLink *link);
  525. /**
  526. * Send a slice to the next filter.
  527. *
  528. * Slices have to be provided in sequential order, either in
  529. * top-bottom or bottom-top order. If slices are provided in
  530. * non-sequential order the behavior of the function is undefined.
  531. *
  532. * @param link the output link over which the frame is being sent
  533. * @param y offset in pixels from the top of the image for this slice
  534. * @param h height of this slice in pixels
  535. * @param slice_dir the assumed direction for sending slices,
  536. * from the top slice to the bottom slice if the value is 1,
  537. * from the bottom slice to the top slice if the value is -1,
  538. * for other values the behavior of the function is undefined.
  539. */
  540. void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
  541. /** Initialize the filter system. Register all builtin filters. */
  542. void avfilter_register_all(void);
  543. /** Uninitialize the filter system. Unregister all filters. */
  544. void avfilter_uninit(void);
  545. /**
  546. * Register a filter. This is only needed if you plan to use
  547. * avfilter_get_by_name later to lookup the AVFilter structure by name. A
  548. * filter can still by instantiated with avfilter_open even if it is not
  549. * registered.
  550. * @param filter the filter to register
  551. * @return 0 if the registration was succesfull, a negative value
  552. * otherwise
  553. */
  554. int avfilter_register(AVFilter *filter);
  555. /**
  556. * Get a filter definition matching the given name.
  557. * @param name the filter name to find
  558. * @return the filter definition, if any matching one is registered.
  559. * NULL if none found.
  560. */
  561. AVFilter *avfilter_get_by_name(const char *name);
  562. /**
  563. * If filter is NULL, returns a pointer to the first registered filter pointer,
  564. * if filter is non-NULL, returns the next pointer after filter.
  565. * If the returned pointer points to NULL, the last registered filter
  566. * was already reached.
  567. */
  568. AVFilter **av_filter_next(AVFilter **filter);
  569. /**
  570. * Create a filter instance.
  571. *
  572. * @param filter_ctx put here a pointer to the created filter context
  573. * on success, NULL on failure
  574. * @param filter the filter to create an instance of
  575. * @param inst_name Name to give to the new instance. Can be NULL for none.
  576. * @return >= 0 in case of success, a negative error code otherwise
  577. */
  578. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name);
  579. /**
  580. * Initialize a filter.
  581. * @param filter the filter to initialize
  582. * @param args A string of parameters to use when initializing the filter.
  583. * The format and meaning of this string varies by filter.
  584. * @param opaque Any extra non-string data needed by the filter. The meaning
  585. * of this parameter varies by filter.
  586. * @return zero on success
  587. */
  588. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  589. /**
  590. * Destroy a filter.
  591. * @param filter the filter to destroy
  592. */
  593. void avfilter_destroy(AVFilterContext *filter);
  594. /**
  595. * Insert a filter in the middle of an existing link.
  596. * @param link the link into which the filter should be inserted
  597. * @param filt the filter to be inserted
  598. * @param in the input pad on the filter to connect
  599. * @param out the output pad on the filter to connect
  600. * @return zero on success
  601. */
  602. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  603. unsigned in, unsigned out);
  604. /**
  605. * Insert a new pad.
  606. * @param idx Insertion point. Pad is inserted at the end if this point
  607. * is beyond the end of the list of pads.
  608. * @param count Pointer to the number of pads in the list
  609. * @param padidx_off Offset within an AVFilterLink structure to the element
  610. * to increment when inserting a new pad causes link
  611. * numbering to change
  612. * @param pads Pointer to the pointer to the beginning of the list of pads
  613. * @param links Pointer to the pointer to the beginning of the list of links
  614. * @param newpad The new pad to add. A copy is made when adding.
  615. */
  616. void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  617. AVFilterPad **pads, AVFilterLink ***links,
  618. AVFilterPad *newpad);
  619. /** Insert a new input pad for the filter. */
  620. static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
  621. AVFilterPad *p)
  622. {
  623. avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
  624. &f->input_pads, &f->inputs, p);
  625. }
  626. /** Insert a new output pad for the filter. */
  627. static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
  628. AVFilterPad *p)
  629. {
  630. avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
  631. &f->output_pads, &f->outputs, p);
  632. }
  633. #endif /* AVFILTER_AVFILTER_H */