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.

170 lines
6.2KB

  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. /**
  32. * Get a frame with filtered data from sink and put it in frame.
  33. *
  34. * @param ctx pointer to a buffersink or abuffersink filter context.
  35. * @param frame pointer to an allocated frame that will be filled with data.
  36. * The data must be freed using av_frame_unref() / av_frame_free()
  37. * @param flags a combination of AV_BUFFERSINK_FLAG_* flags
  38. *
  39. * @return >= 0 in for success, a negative AVERROR code for failure.
  40. */
  41. int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags);
  42. /**
  43. * Tell av_buffersink_get_buffer_ref() to read video/samples buffer
  44. * reference, but not remove it from the buffer. This is useful if you
  45. * need only to read a video/samples buffer, without to fetch it.
  46. */
  47. #define AV_BUFFERSINK_FLAG_PEEK 1
  48. /**
  49. * Tell av_buffersink_get_buffer_ref() not to request a frame from its input.
  50. * If a frame is already buffered, it is read (and removed from the buffer),
  51. * but if no frame is present, return AVERROR(EAGAIN).
  52. */
  53. #define AV_BUFFERSINK_FLAG_NO_REQUEST 2
  54. #if FF_API_NEXT
  55. /**
  56. * Struct to use for initializing a buffersink context.
  57. */
  58. typedef struct AVBufferSinkParams {
  59. const enum AVPixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by AV_PIX_FMT_NONE
  60. } AVBufferSinkParams;
  61. /**
  62. * Create an AVBufferSinkParams structure.
  63. *
  64. * Must be freed with av_free().
  65. */
  66. attribute_deprecated
  67. AVBufferSinkParams *av_buffersink_params_alloc(void);
  68. /**
  69. * Struct to use for initializing an abuffersink context.
  70. */
  71. typedef struct AVABufferSinkParams {
  72. const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
  73. const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1
  74. const int *channel_counts; ///< list of allowed channel counts, terminated by -1
  75. int all_channel_counts; ///< if not 0, accept any channel count or layout
  76. int *sample_rates; ///< list of allowed sample rates, terminated by -1
  77. } AVABufferSinkParams;
  78. /**
  79. * Create an AVABufferSinkParams structure.
  80. *
  81. * Must be freed with av_free().
  82. */
  83. attribute_deprecated
  84. AVABufferSinkParams *av_abuffersink_params_alloc(void);
  85. #endif
  86. /**
  87. * Set the frame size for an audio buffer sink.
  88. *
  89. * All calls to av_buffersink_get_buffer_ref will return a buffer with
  90. * exactly the specified number of samples, or AVERROR(EAGAIN) if there is
  91. * not enough. The last buffer at EOF will be padded with 0.
  92. */
  93. void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size);
  94. /**
  95. * @defgroup lavfi_buffersink_accessors Buffer sink accessors
  96. * Get the properties of the stream
  97. * @{
  98. */
  99. enum AVMediaType av_buffersink_get_type (const AVFilterContext *ctx);
  100. AVRational av_buffersink_get_time_base (const AVFilterContext *ctx);
  101. int av_buffersink_get_format (const AVFilterContext *ctx);
  102. AVRational av_buffersink_get_frame_rate (const AVFilterContext *ctx);
  103. int av_buffersink_get_w (const AVFilterContext *ctx);
  104. int av_buffersink_get_h (const AVFilterContext *ctx);
  105. AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
  106. int av_buffersink_get_channels (const AVFilterContext *ctx);
  107. uint64_t av_buffersink_get_channel_layout (const AVFilterContext *ctx);
  108. int av_buffersink_get_sample_rate (const AVFilterContext *ctx);
  109. AVBufferRef * av_buffersink_get_hw_frames_ctx (const AVFilterContext *ctx);
  110. /** @} */
  111. /**
  112. * Get a frame with filtered data from sink and put it in frame.
  113. *
  114. * @param ctx pointer to a context of a buffersink or abuffersink AVFilter.
  115. * @param frame pointer to an allocated frame that will be filled with data.
  116. * The data must be freed using av_frame_unref() / av_frame_free()
  117. *
  118. * @return
  119. * - >= 0 if a frame was successfully returned.
  120. * - AVERROR(EAGAIN) if no frames are available at this point; more
  121. * input frames must be added to the filtergraph to get more output.
  122. * - AVERROR_EOF if there will be no more output frames on this sink.
  123. * - A different negative AVERROR code in other failure cases.
  124. */
  125. int av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame);
  126. /**
  127. * Same as av_buffersink_get_frame(), but with the ability to specify the number
  128. * of samples read. This function is less efficient than
  129. * av_buffersink_get_frame(), because it copies the data around.
  130. *
  131. * @param ctx pointer to a context of the abuffersink AVFilter.
  132. * @param frame pointer to an allocated frame that will be filled with data.
  133. * The data must be freed using av_frame_unref() / av_frame_free()
  134. * frame will contain exactly nb_samples audio samples, except at
  135. * the end of stream, when it can contain less than nb_samples.
  136. *
  137. * @return The return codes have the same meaning as for
  138. * av_buffersink_get_frame().
  139. *
  140. * @warning do not mix this function with av_buffersink_get_frame(). Use only one or
  141. * the other with a single sink, not both.
  142. */
  143. int av_buffersink_get_samples(AVFilterContext *ctx, AVFrame *frame, int nb_samples);
  144. /**
  145. * @}
  146. */
  147. #endif /* AVFILTER_BUFFERSINK_H */