buffersrc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_BUFFERSRC_H
  19. #define AVFILTER_BUFFERSRC_H
  20. /**
  21. * @file
  22. * @ingroup lavfi_buffersrc
  23. * Memory buffer source API.
  24. */
  25. #include "avfilter.h"
  26. /**
  27. * @defgroup lavfi_buffersrc Buffer source API
  28. * @ingroup lavfi
  29. * @{
  30. */
  31. enum {
  32. /**
  33. * Do not check for format changes.
  34. */
  35. AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT = 1,
  36. /**
  37. * Immediately push the frame to the output.
  38. */
  39. AV_BUFFERSRC_FLAG_PUSH = 4,
  40. /**
  41. * Keep a reference to the frame.
  42. * If the frame if reference-counted, create a new reference; otherwise
  43. * copy the frame data.
  44. */
  45. AV_BUFFERSRC_FLAG_KEEP_REF = 8,
  46. };
  47. /**
  48. * Get the number of failed requests.
  49. *
  50. * A failed request is when the request_frame method is called while no
  51. * frame is present in the buffer.
  52. * The number is reset when a frame is added.
  53. */
  54. unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src);
  55. /**
  56. * This structure contains the parameters describing the frames that will be
  57. * passed to this filter.
  58. *
  59. * It should be allocated with av_buffersrc_parameters_alloc() and freed with
  60. * av_free(). All the allocated fields in it remain owned by the caller.
  61. */
  62. typedef struct AVBufferSrcParameters {
  63. /**
  64. * video: the pixel format, value corresponds to enum AVPixelFormat
  65. * audio: the sample format, value corresponds to enum AVSampleFormat
  66. */
  67. int format;
  68. /**
  69. * The timebase to be used for the timestamps on the input frames.
  70. */
  71. AVRational time_base;
  72. /**
  73. * Video only, the display dimensions of the input frames.
  74. */
  75. int width, height;
  76. /**
  77. * Video only, the sample (pixel) aspect ratio.
  78. */
  79. AVRational sample_aspect_ratio;
  80. /**
  81. * Video only, the frame rate of the input video. This field must only be
  82. * set to a non-zero value if input stream has a known constant framerate
  83. * and should be left at its initial value if the framerate is variable or
  84. * unknown.
  85. */
  86. AVRational frame_rate;
  87. /**
  88. * Video with a hwaccel pixel format only. This should be a reference to an
  89. * AVHWFramesContext instance describing the input frames.
  90. */
  91. AVBufferRef *hw_frames_ctx;
  92. /**
  93. * Audio only, the audio sampling rate in samples per second.
  94. */
  95. int sample_rate;
  96. /**
  97. * Audio only, the audio channel layout
  98. */
  99. uint64_t channel_layout;
  100. } AVBufferSrcParameters;
  101. /**
  102. * Allocate a new AVBufferSrcParameters instance. It should be freed by the
  103. * caller with av_free().
  104. */
  105. AVBufferSrcParameters *av_buffersrc_parameters_alloc(void);
  106. /**
  107. * Initialize the buffersrc or abuffersrc filter with the provided parameters.
  108. * This function may be called multiple times, the later calls override the
  109. * previous ones. Some of the parameters may also be set through AVOptions, then
  110. * whatever method is used last takes precedence.
  111. *
  112. * @param ctx an instance of the buffersrc or abuffersrc filter
  113. * @param param the stream parameters. The frames later passed to this filter
  114. * must conform to those parameters. All the allocated fields in
  115. * param remain owned by the caller, libavfilter will make internal
  116. * copies or references when necessary.
  117. * @return 0 on success, a negative AVERROR code on failure.
  118. */
  119. int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param);
  120. /**
  121. * Add a frame to the buffer source.
  122. *
  123. * @param ctx an instance of the buffersrc filter
  124. * @param frame frame to be added. If the frame is reference counted, this
  125. * function will make a new reference to it. Otherwise the frame data will be
  126. * copied.
  127. *
  128. * @return 0 on success, a negative AVERROR on error
  129. *
  130. * This function is equivalent to av_buffersrc_add_frame_flags() with the
  131. * AV_BUFFERSRC_FLAG_KEEP_REF flag.
  132. */
  133. av_warn_unused_result
  134. int av_buffersrc_write_frame(AVFilterContext *ctx, const AVFrame *frame);
  135. /**
  136. * Add a frame to the buffer source.
  137. *
  138. * @param ctx an instance of the buffersrc filter
  139. * @param frame frame to be added. If the frame is reference counted, this
  140. * function will take ownership of the reference(s) and reset the frame.
  141. * Otherwise the frame data will be copied. If this function returns an error,
  142. * the input frame is not touched.
  143. *
  144. * @return 0 on success, a negative AVERROR on error.
  145. *
  146. * @note the difference between this function and av_buffersrc_write_frame() is
  147. * that av_buffersrc_write_frame() creates a new reference to the input frame,
  148. * while this function takes ownership of the reference passed to it.
  149. *
  150. * This function is equivalent to av_buffersrc_add_frame_flags() without the
  151. * AV_BUFFERSRC_FLAG_KEEP_REF flag.
  152. */
  153. av_warn_unused_result
  154. int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame);
  155. /**
  156. * Add a frame to the buffer source.
  157. *
  158. * By default, if the frame is reference-counted, this function will take
  159. * ownership of the reference(s) and reset the frame. This can be controlled
  160. * using the flags.
  161. *
  162. * If this function returns an error, the input frame is not touched.
  163. *
  164. * @param buffer_src pointer to a buffer source context
  165. * @param frame a frame, or NULL to mark EOF
  166. * @param flags a combination of AV_BUFFERSRC_FLAG_*
  167. * @return >= 0 in case of success, a negative AVERROR code
  168. * in case of failure
  169. */
  170. av_warn_unused_result
  171. int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
  172. AVFrame *frame, int flags);
  173. /**
  174. * Close the buffer source after EOF.
  175. *
  176. * This is similar to passing NULL to av_buffersrc_add_frame_flags()
  177. * except it takes the timestamp of the EOF, i.e. the timestamp of the end
  178. * of the last frame.
  179. */
  180. int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
  181. /**
  182. * @}
  183. */
  184. #endif /* AVFILTER_BUFFERSRC_H */