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.

235 lines
7.4KB

  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 "libavutil/internal.h"
  25. #include "avfilter.h"
  26. #include "thread.h"
  27. #include "version.h"
  28. #if !FF_API_AVFILTERPAD_PUBLIC
  29. /**
  30. * A filter pad used for either input or output.
  31. */
  32. struct AVFilterPad {
  33. /**
  34. * Pad name. The name is unique among inputs and among outputs, but an
  35. * input may have the same name as an output. This may be NULL if this
  36. * pad has no need to ever be referenced by name.
  37. */
  38. const char *name;
  39. /**
  40. * AVFilterPad type.
  41. */
  42. enum AVMediaType type;
  43. /**
  44. * Callback function to get a video buffer. If NULL, the filter system will
  45. * use avfilter_default_get_video_buffer().
  46. *
  47. * Input video pads only.
  48. */
  49. AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
  50. /**
  51. * Callback function to get an audio buffer. If NULL, the filter system will
  52. * use avfilter_default_get_audio_buffer().
  53. *
  54. * Input audio pads only.
  55. */
  56. AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
  57. /**
  58. * Filtering callback. This is where a filter receives a frame with
  59. * audio/video data and should do its processing.
  60. *
  61. * Input pads only.
  62. *
  63. * @return >= 0 on success, a negative AVERROR on error. This function
  64. * must ensure that samplesref is properly unreferenced on error if it
  65. * hasn't been passed on to another filter.
  66. */
  67. int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
  68. /**
  69. * Frame poll callback. This returns the number of immediately available
  70. * samples. It should return a positive value if the next request_frame()
  71. * is guaranteed to return one frame (with no delay).
  72. *
  73. * Defaults to just calling the source poll_frame() method.
  74. *
  75. * Output pads only.
  76. */
  77. int (*poll_frame)(AVFilterLink *link);
  78. /**
  79. * Frame request callback. A call to this should result in at least one
  80. * frame being output over the given link. This should return zero on
  81. * success, and another value on error.
  82. *
  83. * Output pads only.
  84. */
  85. int (*request_frame)(AVFilterLink *link);
  86. /**
  87. * Link configuration callback.
  88. *
  89. * For output pads, this should set the link properties such as
  90. * width/height. This should NOT set the format property - that is
  91. * negotiated between filters by the filter system using the
  92. * query_formats() callback before this function is called.
  93. *
  94. * For input pads, this should check the properties of the link, and update
  95. * the filter's internal state as necessary.
  96. *
  97. * For both input and output filters, this should return zero on success,
  98. * and another value on error.
  99. */
  100. int (*config_props)(AVFilterLink *link);
  101. /**
  102. * The filter expects a fifo to be inserted on its input link,
  103. * typically because it has a delay.
  104. *
  105. * input pads only.
  106. */
  107. int needs_fifo;
  108. };
  109. #endif
  110. struct AVFilterGraphInternal {
  111. void *thread;
  112. int (*thread_execute)(AVFilterContext *ctx, action_func *func, void *arg,
  113. int *ret, int nb_jobs);
  114. };
  115. struct AVFilterInternal {
  116. int (*execute)(AVFilterContext *ctx, action_func *func, void *arg,
  117. int *ret, int nb_jobs);
  118. };
  119. #if FF_API_AVFILTERBUFFER
  120. /** default handler for freeing audio/video buffer when there are no references left */
  121. void ff_avfilter_default_free_buffer(AVFilterBuffer *buf);
  122. #endif
  123. /** Tell is a format is contained in the provided list terminated by -1. */
  124. int ff_fmt_is_in(int fmt, const int *fmts);
  125. #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
  126. void ff_dlog_link(void *ctx, AVFilterLink *link, int end);
  127. /**
  128. * Insert a new pad.
  129. *
  130. * @param idx Insertion point. Pad is inserted at the end if this point
  131. * is beyond the end of the list of pads.
  132. * @param count Pointer to the number of pads in the list
  133. * @param padidx_off Offset within an AVFilterLink structure to the element
  134. * to increment when inserting a new pad causes link
  135. * numbering to change
  136. * @param pads Pointer to the pointer to the beginning of the list of pads
  137. * @param links Pointer to the pointer to the beginning of the list of links
  138. * @param newpad The new pad to add. A copy is made when adding.
  139. */
  140. void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  141. AVFilterPad **pads, AVFilterLink ***links,
  142. AVFilterPad *newpad);
  143. /** Insert a new input pad for the filter. */
  144. static inline void ff_insert_inpad(AVFilterContext *f, unsigned index,
  145. AVFilterPad *p)
  146. {
  147. ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad),
  148. &f->input_pads, &f->inputs, p);
  149. #if FF_API_FOO_COUNT
  150. FF_DISABLE_DEPRECATION_WARNINGS
  151. f->input_count = f->nb_inputs;
  152. FF_ENABLE_DEPRECATION_WARNINGS
  153. #endif
  154. }
  155. /** Insert a new output pad for the filter. */
  156. static inline void ff_insert_outpad(AVFilterContext *f, unsigned index,
  157. AVFilterPad *p)
  158. {
  159. ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad),
  160. &f->output_pads, &f->outputs, p);
  161. #if FF_API_FOO_COUNT
  162. FF_DISABLE_DEPRECATION_WARNINGS
  163. f->output_count = f->nb_outputs;
  164. FF_ENABLE_DEPRECATION_WARNINGS
  165. #endif
  166. }
  167. /**
  168. * Poll a frame from the filter chain.
  169. *
  170. * @param link the input link
  171. * @return the number of immediately available frames, a negative
  172. * number in case of error
  173. */
  174. int ff_poll_frame(AVFilterLink *link);
  175. /**
  176. * Request an input frame from the filter at the other end of the link.
  177. *
  178. * @param link the input link
  179. * @return zero on success
  180. */
  181. int ff_request_frame(AVFilterLink *link);
  182. /**
  183. * Send a frame of data to the next filter.
  184. *
  185. * @param link the output link over which the data is being sent
  186. * @param frame a reference to the buffer of data being sent. The
  187. * receiving filter will free this reference when it no longer
  188. * needs it or pass it on to the next filter.
  189. *
  190. * @return >= 0 on success, a negative AVERROR on error. The receiving filter
  191. * is responsible for unreferencing frame in case of error.
  192. */
  193. int ff_filter_frame(AVFilterLink *link, AVFrame *frame);
  194. /**
  195. * Allocate a new filter context and return it.
  196. *
  197. * @param filter what filter to create an instance of
  198. * @param inst_name name to give to the new filter context
  199. *
  200. * @return newly created filter context or NULL on failure
  201. */
  202. AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name);
  203. /**
  204. * Remove a filter from a graph;
  205. */
  206. void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter);
  207. #endif /* AVFILTER_INTERNAL_H */