internal.h 7.0 KB

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