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.

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