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.

187 lines
6.9KB

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