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.

241 lines
7.8KB

  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. * @return >= 0 on success, a negative AVERROR on error.
  92. */
  93. int (*end_frame)(AVFilterLink *link);
  94. /**
  95. * Slice drawing callback. This is where a filter receives video data
  96. * and should do its processing.
  97. *
  98. * Input video pads only.
  99. *
  100. * @return >= 0 on success, a negative AVERROR on error.
  101. */
  102. int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
  103. /**
  104. * Samples filtering callback. This is where a filter receives audio data
  105. * and should do its processing.
  106. *
  107. * Input audio pads only.
  108. *
  109. * @return >= 0 on success, a negative AVERROR on error. This function
  110. * must ensure that samplesref is properly unreferenced on error if it
  111. * hasn't been passed on to another filter.
  112. */
  113. int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
  114. /**
  115. * Frame poll callback. This returns the number of immediately available
  116. * samples. It should return a positive value if the next request_frame()
  117. * is guaranteed to return one frame (with no delay).
  118. *
  119. * Defaults to just calling the source poll_frame() method.
  120. *
  121. * Output pads only.
  122. */
  123. int (*poll_frame)(AVFilterLink *link);
  124. /**
  125. * Frame request callback. A call to this should result in at least one
  126. * frame being output over the given link. This should return zero on
  127. * success, and another value on error.
  128. *
  129. * Output pads only.
  130. */
  131. int (*request_frame)(AVFilterLink *link);
  132. /**
  133. * Link configuration callback.
  134. *
  135. * For output pads, this should set the link properties such as
  136. * width/height. This should NOT set the format property - that is
  137. * negotiated between filters by the filter system using the
  138. * query_formats() callback before this function is called.
  139. *
  140. * For input pads, this should check the properties of the link, and update
  141. * the filter's internal state as necessary.
  142. *
  143. * For both input and output filters, this should return zero on success,
  144. * and another value on error.
  145. */
  146. int (*config_props)(AVFilterLink *link);
  147. /**
  148. * The filter expects a fifo to be inserted on its input link,
  149. * typically because it has a delay.
  150. *
  151. * input pads only.
  152. */
  153. int needs_fifo;
  154. };
  155. #endif
  156. /** default handler for freeing audio/video buffer when there are no references left */
  157. void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
  158. /** Tell is a format is contained in the provided list terminated by -1. */
  159. int ff_fmt_is_in(int fmt, const int *fmts);
  160. #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
  161. void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
  162. /**
  163. * Insert a new pad.
  164. *
  165. * @param idx Insertion point. Pad is inserted at the end if this point
  166. * is beyond the end of the list of pads.
  167. * @param count Pointer to the number of pads in the list
  168. * @param padidx_off Offset within an AVFilterLink structure to the element
  169. * to increment when inserting a new pad causes link
  170. * numbering to change
  171. * @param pads Pointer to the pointer to the beginning of the list of pads
  172. * @param links Pointer to the pointer to the beginning of the list of links
  173. * @param newpad The new pad to add. A copy is made when adding.
  174. */
  175. void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  176. AVFilterPad **pads, AVFilterLink ***links,
  177. AVFilterPad *newpad);
  178. /** Insert a new input pad for the filter. */
  179. static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
  180. AVFilterPad *p)
  181. {
  182. ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
  183. &f->input_pads, &f->inputs, p);
  184. #if FF_API_FOO_COUNT
  185. f->input_count = f->nb_inputs;
  186. #endif
  187. }
  188. /** Insert a new output pad for the filter. */
  189. static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
  190. AVFilterPad *p)
  191. {
  192. ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
  193. &f->output_pads, &f->outputs, p);
  194. #if FF_API_FOO_COUNT
  195. f->output_count = f->nb_outputs;
  196. #endif
  197. }
  198. /**
  199. * Poll a frame from the filter chain.
  200. *
  201. * @param link the input link
  202. * @return the number of immediately available frames, a negative
  203. * number in case of error
  204. */
  205. int ff_poll_frame(AVFilterLink *link);
  206. /**
  207. * Request an input frame from the filter at the other end of the link.
  208. *
  209. * @param link the input link
  210. * @return zero on success
  211. */
  212. int ff_request_frame(AVFilterLink *link);
  213. #endif /* AVFILTER_INTERNAL_H */