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.

237 lines
7.7KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVFILTER_INTERNAL_H
  19. #define AVFILTER_INTERNAL_H
  20. /**
  21. * @file
  22. * internal API functions
  23. */
  24. #include "avfilter.h"
  25. #if !FF_API_AVFILTERPAD_PUBLIC
  26. /**
  27. * A filter pad used for either input or output.
  28. */
  29. struct AVFilterPad {
  30. /**
  31. * Pad name. The name is unique among inputs and among outputs, but an
  32. * input may have the same name as an output. This may be NULL if this
  33. * pad has no need to ever be referenced by name.
  34. */
  35. const char *name;
  36. /**
  37. * AVFilterPad type.
  38. */
  39. enum AVMediaType type;
  40. /**
  41. * Minimum required permissions on incoming buffers. Any buffer with
  42. * insufficient permissions will be automatically copied by the filter
  43. * system to a new buffer which provides the needed access permissions.
  44. *
  45. * Input pads only.
  46. */
  47. int min_perms;
  48. /**
  49. * Permissions which are not accepted on incoming buffers. Any buffer
  50. * which has any of these permissions set will be automatically copied
  51. * by the filter system to a new buffer which does not have those
  52. * permissions. This can be used to easily disallow buffers with
  53. * AV_PERM_REUSE.
  54. *
  55. * Input pads only.
  56. */
  57. int rej_perms;
  58. /**
  59. * Callback called before passing the first slice of a new frame. If
  60. * NULL, the filter layer will default to storing a reference to the
  61. * picture inside the link structure.
  62. *
  63. * Input video pads only.
  64. *
  65. * @return >= 0 on success, a negative AVERROR on error. picref will be
  66. * unreferenced by the caller in case of error.
  67. */
  68. void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
  69. /**
  70. * Callback function to get a video buffer. If NULL, the filter system will
  71. * use avfilter_default_get_video_buffer().
  72. *
  73. * Input video pads only.
  74. */
  75. AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
  76. /**
  77. * Callback function to get an audio buffer. If NULL, the filter system will
  78. * use avfilter_default_get_audio_buffer().
  79. *
  80. * Input audio pads only.
  81. */
  82. AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
  83. int nb_samples);
  84. /**
  85. * Callback called after the slices of a frame are completely sent. If
  86. * NULL, the filter layer will default to releasing the reference stored
  87. * in the link structure during start_frame().
  88. *
  89. * Input video pads only.
  90. */
  91. void (*end_frame)(AVFilterLink *link);
  92. /**
  93. * Slice drawing callback. This is where a filter receives video data
  94. * and should do its processing.
  95. *
  96. * Input video pads only.
  97. */
  98. void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  99. /**
  100. * Samples filtering callback. This is where a filter receives audio data
  101. * and should do its processing.
  102. *
  103. * Input audio pads only.
  104. *
  105. * @return >= 0 on success, a negative AVERROR on error. This function
  106. * must ensure that samplesref is properly unreferenced on error if it
  107. * hasn't been passed on to another filter.
  108. */
  109. int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
  110. /**
  111. * Frame poll callback. This returns the number of immediately available
  112. * samples. It should return a positive value if the next request_frame()
  113. * is guaranteed to return one frame (with no delay).
  114. *
  115. * Defaults to just calling the source poll_frame() method.
  116. *
  117. * Output pads only.
  118. */
  119. int (*poll_frame)(AVFilterLink *link);
  120. /**
  121. * Frame request callback. A call to this should result in at least one
  122. * frame being output over the given link. This should return zero on
  123. * success, and another value on error.
  124. *
  125. * Output pads only.
  126. */
  127. int (*request_frame)(AVFilterLink *link);
  128. /**
  129. * Link configuration callback.
  130. *
  131. * For output pads, this should set the link properties such as
  132. * width/height. This should NOT set the format property - that is
  133. * negotiated between filters by the filter system using the
  134. * query_formats() callback before this function is called.
  135. *
  136. * For input pads, this should check the properties of the link, and update
  137. * the filter's internal state as necessary.
  138. *
  139. * For both input and output filters, this should return zero on success,
  140. * and another value on error.
  141. */
  142. int (*config_props)(AVFilterLink *link);
  143. /**
  144. * The filter expects a fifo to be inserted on its input link,
  145. * typically because it has a delay.
  146. *
  147. * input pads only.
  148. */
  149. int needs_fifo;
  150. };
  151. #endif
  152. /** default handler for freeing audio/video buffer when there are no references left */
  153. void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
  154. /** Tell is a format is contained in the provided list terminated by -1. */
  155. int ff_fmt_is_in(int fmt, const int *fmts);
  156. #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
  157. void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
  158. /**
  159. * Insert a new pad.
  160. *
  161. * @param idx Insertion point. Pad is inserted at the end if this point
  162. * is beyond the end of the list of pads.
  163. * @param count Pointer to the number of pads in the list
  164. * @param padidx_off Offset within an AVFilterLink structure to the element
  165. * to increment when inserting a new pad causes link
  166. * numbering to change
  167. * @param pads Pointer to the pointer to the beginning of the list of pads
  168. * @param links Pointer to the pointer to the beginning of the list of links
  169. * @param newpad The new pad to add. A copy is made when adding.
  170. */
  171. void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  172. AVFilterPad **pads, AVFilterLink ***links,
  173. AVFilterPad *newpad);
  174. /** Insert a new input pad for the filter. */
  175. static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
  176. AVFilterPad *p)
  177. {
  178. ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
  179. &f->input_pads, &f->inputs, p);
  180. #if FF_API_FOO_COUNT
  181. f->input_count = f->nb_inputs;
  182. #endif
  183. }
  184. /** Insert a new output pad for the filter. */
  185. static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
  186. AVFilterPad *p)
  187. {
  188. ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
  189. &f->output_pads, &f->outputs, p);
  190. #if FF_API_FOO_COUNT
  191. f->output_count = f->nb_outputs;
  192. #endif
  193. }
  194. /**
  195. * Poll a frame from the filter chain.
  196. *
  197. * @param link the input link
  198. * @return the number of immediately available frames, a negative
  199. * number in case of error
  200. */
  201. int ff_poll_frame(AVFilterLink *link);
  202. /**
  203. * Request an input frame from the filter at the other end of the link.
  204. *
  205. * @param link the input link
  206. * @return zero on success
  207. */
  208. int ff_request_frame(AVFilterLink *link);
  209. #endif /* AVFILTER_INTERNAL_H */