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.

206 lines
7.8KB

  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. * The buffersink and abuffersink filters are there to connect filter graphs
  32. * to applications. They have a single input, connected to the graph, and no
  33. * output. Frames must be extracted using av_buffersink_get_frame() or
  34. * av_buffersink_get_samples().
  35. *
  36. * The format negotiated by the graph during configuration can be obtained
  37. * using the accessor functions:
  38. * - av_buffersink_get_time_base(),
  39. * - av_buffersink_get_format(),
  40. * - av_buffersink_get_frame_rate(),
  41. * - av_buffersink_get_w(),
  42. * - av_buffersink_get_h(),
  43. * - av_buffersink_get_sample_aspect_ratio(),
  44. * - av_buffersink_get_channels(),
  45. * - av_buffersink_get_channel_layout(),
  46. * - av_buffersink_get_sample_rate().
  47. *
  48. * The format can be constrained by setting options, using av_opt_set() and
  49. * related functions with the AV_OPT_SEARCH_CHILDREN flag.
  50. * - pix_fmts (int list),
  51. * - sample_fmts (int list),
  52. * - sample_rates (int list),
  53. * - channel_layouts (int64_t),
  54. * - channel_counts (int list),
  55. * - all_channel_counts (bool).
  56. * Most of these options are of type binary, and should be set using
  57. * av_opt_set_int_list() or av_opt_set_bin(). If they are not set, all
  58. * corresponding formats are accepted.
  59. *
  60. * As a special case, if neither channel_layouts nor channel_counts is set,
  61. * all valid channel layouts are accepted, but channel counts without a
  62. * layout are not, unless all_channel_counts is set.
  63. * Also, channel_layouts must not contain a channel layout already accepted
  64. * by a value in channel_counts; for example, if channel_counts contains 2,
  65. * then channel_layouts must not contain stereo.
  66. */
  67. /**
  68. * Get a frame with filtered data from sink and put it in frame.
  69. *
  70. * @param ctx pointer to a buffersink or abuffersink filter context.
  71. * @param frame pointer to an allocated frame that will be filled with data.
  72. * The data must be freed using av_frame_unref() / av_frame_free()
  73. * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
  74. *
  75. * @return >= 0 in for success, a negative AVERROR code for failure.
  76. */
  77. int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags);
  78. /**
  79. * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
  80. * reference, but not remove it from the buffer. This is useful if you
  81. * need only to read a video/samples buffer, without to fetch it.
  82. */
  83. #define AV_BUFFERSINK_FLAG_PEEK 1
  84. /**
  85. * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
  86. * If a frame is already buffered, it is read (and removed from the buffer),
  87. * but if no frame is present, return AVERROR(EAGAIN).
  88. */
  89. #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
  90. #if FF_API_BUFFERSINK_ALLOC
  91. /**
  92. * Deprecated and unused struct to use for initializing a buffersink context.
  93. */
  94. typedef struct AVBufferSinkParams {
  95. const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
  96. } AVBufferSinkParams;
  97. /**
  98. * Create an AVBufferSinkParams structure.
  99. *
  100. * Must be freed with av_free().
  101. */
  102. attribute_deprecated
  103. AVBufferSinkParams *av_buffersink_params_alloc(void);
  104. /**
  105. * Deprecated and unused struct to use for initializing an abuffersink context.
  106. */
  107. typedef struct AVABufferSinkParams {
  108. const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
  109. const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
  110. const int *channel_counts; ///< list of allowed channel counts, terminated by -1
  111. int all_channel_counts; ///< if not 0, accept any channel count or layout
  112. int *sample_rates; ///< list of allowed sample rates, terminated by -1
  113. } AVABufferSinkParams;
  114. /**
  115. * Create an AVABufferSinkParams structure.
  116. *
  117. * Must be freed with av_free().
  118. */
  119. attribute_deprecated
  120. AVABufferSinkParams *av_abuffersink_params_alloc(void);
  121. #endif
  122. /**
  123. * Set the frame size for an audio buffer sink.
  124. *
  125. * All calls to av_buffersink_get_buffer_ref will return a buffer with
  126. * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
  127. * not enough. The last buffer at EOF will be padded with 0.
  128. */
  129. void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
  130. /**
  131. * @defgroup lavfi_buffersink_accessors Buffer sink accessors
  132. * Get the properties of the stream
  133. * @{
  134. */
  135. enum AVMediaType av_buffersink_get_type (const AVFilterContext *ctx);
  136. AVRational av_buffersink_get_time_base (const AVFilterContext *ctx);
  137. int av_buffersink_get_format (const AVFilterContext *ctx);
  138. AVRational av_buffersink_get_frame_rate (const AVFilterContext *ctx);
  139. int av_buffersink_get_w (const AVFilterContext *ctx);
  140. int av_buffersink_get_h (const AVFilterContext *ctx);
  141. AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
  142. int av_buffersink_get_channels (const AVFilterContext *ctx);
  143. uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx);
  144. int av_buffersink_get_sample_rate (const AVFilterContext *ctx);
  145. AVBufferRef * av_buffersink_get_hw_frames_ctx (const AVFilterContext *ctx);
  146. /** @} */
  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_frame().
  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 */