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.

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