buffersink.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVFILTER_BUFFERSINK_H
  19. #define AVFILTER_BUFFERSINK_H
  20. /**
  21. * @file
  22. * @ingroup lavfi_buffersink
  23. * memory buffer sink API for audio and video
  24. */
  25. #include "avfilter.h"
  26. /**
  27. * @defgroup lavfi_buffersink Buffer sink API
  28. * @ingroup lavfi
  29. * @{
  30. */
  31. #if FF_API_AVFILTERBUFFER
  32. /**
  33. * Get an audio/video buffer data from buffer_sink and put it in bufref.
  34. *
  35. * This function works with both audio and video buffer sinks.
  36. *
  37. * @param buffer_sink pointer to a buffersink or abuffersink context
  38. * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
  39. * @return >= 0 in case of success, a negative AVERROR code in case of
  40. * failure
  41. */
  42. attribute_deprecated
  43. int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink,
  44. AVFilterBufferRef **bufref, int flags);
  45. /**
  46. * Get the number of immediately available frames.
  47. */
  48. attribute_deprecated
  49. int av_buffersink_poll_frame(AVFilterContext *ctx);
  50. /**
  51. * Get a buffer with filtered data from sink and put it in buf.
  52. *
  53. * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
  54. * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
  55. * must be freed by the caller using avfilter_unref_buffer().
  56. * Buf may also be NULL to query whether a buffer is ready to be
  57. * output.
  58. *
  59. * @return >= 0 in case of success, a negative AVERROR code in case of
  60. * failure.
  61. */
  62. attribute_deprecated
  63. int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf);
  64. /**
  65. * Same as av_buffersink_read, but with the ability to specify the number of
  66. * samples read. This function is less efficient than av_buffersink_read(),
  67. * because it copies the data around.
  68. *
  69. * @param ctx pointer to a context of the abuffersink AVFilter.
  70. * @param buf pointer to the buffer will be written here if buf is non-NULL. buf
  71. * must be freed by the caller using avfilter_unref_buffer(). buf
  72. * will contain exactly nb_samples audio samples, except at the end
  73. * of stream, when it can contain less than nb_samples.
  74. * Buf may also be NULL to query whether a buffer is ready to be
  75. * output.
  76. *
  77. * @warning do not mix this function with av_buffersink_read(). Use only one or
  78. * the other with a single sink, not both.
  79. */
  80. attribute_deprecated
  81. int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
  82. int nb_samples);
  83. #endif
  84. /**
  85. * Get a frame with filtered data from sink and put it in frame.
  86. *
  87. * @param ctx pointer to a buffersink or abuffersink filter context.
  88. * @param frame pointer to an allocated frame that will be filled with data.
  89. * The data must be freed using av_frame_unref() / av_frame_free()
  90. * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
  91. *
  92. * @return >= 0 in for success, a negative AVERROR code for failure.
  93. */
  94. int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags);
  95. /**
  96. * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
  97. * reference, but not remove it from the buffer. This is useful if you
  98. * need only to read a video/samples buffer, without to fetch it.
  99. */
  100. #define AV_BUFFERSINK_FLAG_PEEK 1
  101. /**
  102. * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
  103. * If a frame is already buffered, it is read (and removed from the buffer),
  104. * but if no frame is present, return AVERROR(EAGAIN).
  105. */
  106. #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
  107. /**
  108. * Struct to use for initializing a buffersink context.
  109. */
  110. typedef struct {
  111. const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
  112. } AVBufferSinkParams;
  113. /**
  114. * Create an AVBufferSinkParams structure.
  115. *
  116. * Must be freed with av_free().
  117. */
  118. AVBufferSinkParams *av_buffersink_params_alloc(void);
  119. /**
  120. * Struct to use for initializing an abuffersink context.
  121. */
  122. typedef struct {
  123. const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
  124. const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
  125. const int *channel_counts; ///< list of allowed channel counts, terminated by -1
  126. int all_channel_counts; ///< if not 0, accept any channel count or layout
  127. int *sample_rates; ///< list of allowed sample rates, terminated by -1
  128. } AVABufferSinkParams;
  129. /**
  130. * Create an AVABufferSinkParams structure.
  131. *
  132. * Must be freed with av_free().
  133. */
  134. AVABufferSinkParams *av_abuffersink_params_alloc(void);
  135. /**
  136. * Set the frame size for an audio buffer sink.
  137. *
  138. * All calls to av_buffersink_get_buffer_ref will return a buffer with
  139. * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
  140. * not enough. The last buffer at EOF will be padded with 0.
  141. */
  142. void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
  143. /**
  144. * Get the frame rate of the input.
  145. */
  146. AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx);
  147. /**
  148. * Get a frame with filtered data from sink and put it in frame.
  149. *
  150. * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
  151. * @param frame pointer to an allocated frame that will be filled with data.
  152. * The data must be freed using av_frame_unref() / av_frame_free()
  153. *
  154. * @return
  155. * - >= 0 if a frame was successfully returned.
  156. * - AVERROR(EAGAIN) if no frames are available at this point; more
  157. * input frames must be added to the filtergraph to get more output.
  158. * - AVERROR_EOF if there will be no more output frames on this sink.
  159. * - A different negative AVERROR code in other failure cases.
  160. */
  161. int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame);
  162. /**
  163. * Same as av_buffersink_get_frame(), but with the ability to specify the number
  164. * of samples read. This function is less efficient than
  165. * av_buffersink_get_frame(), because it copies the data around.
  166. *
  167. * @param ctx pointer to a context of the abuffersink AVFilter.
  168. * @param frame pointer to an allocated frame that will be filled with data.
  169. * The data must be freed using av_frame_unref() / av_frame_free()
  170. * frame will contain exactly nb_samples audio samples, except at
  171. * the end of stream, when it can contain less than nb_samples.
  172. *
  173. * @return The return codes have the same meaning as for
  174. * av_buffersink_get_samples().
  175. *
  176. * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
  177. * the other with a single sink, not both.
  178. */
  179. int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples);
  180. /**
  181. * @}
  182. */
  183. #endif /* AVFILTER_BUFFERSINK_H */