buffersrc.h 6.2 KB

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