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.

244 lines
7.9KB

  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 FFMPEG_AVFILTER_H
  22. #define FFMPEG_AVFILTER_H
  23. #include "avcodec.h"
  24. typedef struct AVFilterContext AVFilterContext;
  25. typedef struct AVFilterLink AVFilterLink;
  26. typedef struct AVFilterPad AVFilterPad;
  27. /* TODO: look for other flags which may be useful in this structure (interlace
  28. * flags, etc)
  29. */
  30. /**
  31. * A reference-counted picture data type used by the filter system. Filters
  32. * should not store pointers to this structure directly, but instead use the
  33. * AVFilterPicRef structure below
  34. */
  35. typedef struct AVFilterPic
  36. {
  37. uint8_t *data[4];
  38. int linesize[4]; ///< number of bytes per line
  39. enum PixelFormat format;
  40. unsigned refcount;
  41. void *priv;
  42. void (*free)(struct AVFilterPic *pic);
  43. } AVFilterPic;
  44. /**
  45. * A reference to an AVFilterPic. Since filters can manipulate the origin of
  46. * a picture to, for example, crop image without any memcpy, the picture origin
  47. * and dimensions are per-reference properties. Linesize is also useful for
  48. * image flipping, frame to field filters, etc, and so is also per-reference.
  49. *
  50. * TODO: add anything necessary for frame reordering
  51. */
  52. typedef struct AVFilterPicRef
  53. {
  54. AVFilterPic *pic;
  55. uint8_t *data[4];
  56. int linesize[4];
  57. int w, h;
  58. int64_t pts; ///< presentation timestamp in milliseconds
  59. int perms; ///< permissions
  60. #define AV_PERM_READ 0x01 ///< can read from the buffer
  61. #define AV_PERM_WRITE 0x02 ///< can write to the buffer
  62. #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
  63. #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times
  64. } AVFilterPicRef;
  65. /**
  66. * Add a new reference to a picture.
  67. * @param ref An existing reference to the picture
  68. * @param pmask A bitmask containing the allowable permissions in the new reference
  69. * @return A new reference to the picture with the same properties as the old
  70. */
  71. AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask);
  72. /**
  73. * Remove a reference to a picture. If this is the last reference to the
  74. * picture, the picture itself is also automatically freed.
  75. * @param ref Reference to the picture.
  76. */
  77. void avfilter_unref_pic(AVFilterPicRef *ref);
  78. struct AVFilterPad
  79. {
  80. /**
  81. * Pad name. The name is unique among inputs and among oututs, but an
  82. * input may have the same name as an output.
  83. */
  84. char *name;
  85. /**
  86. * AVFilterPad type. Only video supported now, hopefully someone will
  87. * add audio in the future.
  88. */
  89. int type;
  90. #define AV_PAD_VIDEO 0
  91. /**
  92. * Callback to get a list of supported formats. The returned list should
  93. * be terminated by -1. This is used for both input and output pads and
  94. * is required for both.
  95. */
  96. int *(*query_formats)(AVFilterLink *link);
  97. /**
  98. * Callback called before passing the first slice of a new frame. If
  99. * NULL, the filter layer will default to storing a reference to the
  100. * picture inside the link structure.
  101. */
  102. void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref);
  103. /**
  104. * Callback function to get a buffer. If NULL, the filter system will
  105. * handle buffer requests. Only required for input video pads.
  106. */
  107. AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms);
  108. /**
  109. * Callback called after the slices of a frame are completely sent. If
  110. * NULL, the filter layer will default to releasing the reference stored
  111. * in the link structure during start_frame().
  112. */
  113. void (*end_frame)(AVFilterLink *link);
  114. /**
  115. * Slice drawing callback. This is where a filter receives video data
  116. * and should do its processing. Only required for input video pads.
  117. */
  118. void (*draw_slice)(AVFilterLink *link, uint8_t *data[4], int y, int height);
  119. /**
  120. * Frame request callback. A call to this should result in at least one
  121. * frame being output over the given link. Video output pads only.
  122. */
  123. void (*request_frame)(AVFilterLink *link);
  124. /**
  125. * Link configuration callback. For output pads, this should set the link
  126. * properties such as width/height. NOTE: this should not set the format
  127. * property - that is negotiated between filters by the filter system using
  128. * the query_formats() callback.
  129. *
  130. * For input pads, this should check the properties of the link, and update
  131. * the filter's internal state as necessary.
  132. */
  133. int (*config_props)(AVFilterLink *link);
  134. };
  135. /* the default implementations of filter entry points */
  136. void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
  137. void avfilter_default_end_frame(AVFilterLink *link);
  138. int avfilter_default_config_output_link(AVFilterLink *link);
  139. int avfilter_default_config_input_link (AVFilterLink *link);
  140. int *avfilter_default_query_output_formats(AVFilterLink *link);
  141. AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link,
  142. int perms);
  143. typedef struct
  144. {
  145. char *name;
  146. char *author;
  147. int priv_size;
  148. /**
  149. * Filter initialization function. Args contains the user-supplied
  150. * parameters. FIXME: maybe an AVOption-based system would be better?
  151. * opaque is data provided by the code requesting creation of the filter,
  152. * and is used to pass data to the filter.
  153. */
  154. int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
  155. void (*uninit)(AVFilterContext *ctx);
  156. const AVFilterPad *inputs; /// NULL terminated list of inputs. NULL if none
  157. const AVFilterPad *outputs; /// NULL terminated list of outputs. NULL if none
  158. } AVFilter;
  159. struct AVFilterContext
  160. {
  161. AVClass *av_class;
  162. AVFilter *filter;
  163. char *name;
  164. unsigned input_count;
  165. AVFilterPad *input_pads;
  166. AVFilterLink **inputs;
  167. unsigned output_count;
  168. AVFilterPad *output_pads;
  169. AVFilterLink **outputs;
  170. void *priv;
  171. };
  172. struct AVFilterLink
  173. {
  174. AVFilterContext *src;
  175. unsigned int srcpad;
  176. AVFilterContext *dst;
  177. unsigned int dstpad;
  178. int w, h;
  179. enum PixelFormat format;
  180. AVFilterPicRef *cur_pic;
  181. AVFilterPicRef *outpic;
  182. };
  183. /** Link two filters together */
  184. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  185. AVFilterContext *dst, unsigned dstpad);
  186. /** Configure the colorspace, dimensions, etc of a link */
  187. int avfilter_config_link(AVFilterLink *link);
  188. AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms);
  189. void avfilter_request_frame(AVFilterLink *link);
  190. void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
  191. void avfilter_end_frame(AVFilterLink *link);
  192. void avfilter_draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h);
  193. void avfilter_init(void);
  194. void avfilter_uninit(void);
  195. void avfilter_register(AVFilter *filter);
  196. AVFilter *avfilter_get_by_name(char *name);
  197. AVFilterContext *avfilter_create(AVFilter *filter, char *inst_name);
  198. AVFilterContext *avfilter_create_by_name(char *name, char *inst_name);
  199. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
  200. void avfilter_destroy(AVFilterContext *filter);
  201. int *avfilter_make_format_list(int len, ...);
  202. #endif /* FFMPEG_AVFILTER_H */