1
0

reference-libobs-media-io.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. Media I/O API Reference (libobs/media-io)
  2. =========================================
  3. .. code:: cpp
  4. #include <obs.h>
  5. Video Handler
  6. -------------
  7. .. type:: video_t
  8. Video output handler object
  9. ---------------------
  10. .. type:: enum video_format
  11. Video format. Can be one of the following values:
  12. - VIDEO_FORMAT_I420
  13. - VIDEO_FORMAT_NV12
  14. - VIDEO_FORMAT_YVYU
  15. - VIDEO_FORMAT_YUY2
  16. - VIDEO_FORMAT_UYVY
  17. - VIDEO_FORMAT_RGBA
  18. - VIDEO_FORMAT_BGRA
  19. - VIDEO_FORMAT_BGRX
  20. - VIDEO_FORMAT_Y800
  21. - VIDEO_FORMAT_I444
  22. ---------------------
  23. .. type:: enum video_colorspace
  24. YUV color space. Can be one of the following values:
  25. - VIDEO_CS_DEFAULT - Equivalent to VIDEO_CS_709
  26. - VIDEO_CS_601 - 601 color space
  27. - VIDEO_CS_709 - 709 color space
  28. - VIDEO_CS_SRGB - sRGB color space
  29. ---------------------
  30. .. type:: enum video_range_type
  31. YUV color range.
  32. - VIDEO_RANGE_DEFAULT - Equivalent to VIDEO_RANGE_PARTIAL
  33. - VIDEO_RANGE_PARTIAL - Partial range
  34. - VIDEO_RANGE_FULL - Full range
  35. ---------------------
  36. .. type:: struct video_data
  37. Video frame structure.
  38. .. member:: uint8_t *video_data.data[MAX_AV_PLANES]
  39. .. member:: uint32_t video_data.linesize[MAX_AV_PLANES]
  40. .. member:: uint64_t video_data.timestamp
  41. ---------------------
  42. .. type:: struct video_output_info
  43. Video output handler information
  44. .. member:: const char *video_output_info.name
  45. .. member:: enum video_format video_output_info.format
  46. .. member:: uint32_t video_output_info.fps_num
  47. .. member:: uint32_t video_output_info.fps_den
  48. .. member:: uint32_t video_output_info.width
  49. .. member:: uint32_t video_output_info.height
  50. .. member:: size_t video_output_info.cache_size
  51. .. member:: enum video_colorspace video_output_info.colorspace
  52. .. member:: enum video_range_type video_output_info.range
  53. ---------------------
  54. .. function:: enum video_format video_format_from_fourcc(uint32_t fourcc)
  55. Converts a fourcc value to a video format.
  56. :param forcecc: Fourcc value
  57. :return: Video format
  58. ---------------------
  59. .. function:: bool video_format_get_parameters(enum video_colorspace color_space, enum video_range_type range, float matrix[16], float min_range[3], float max_range[3])
  60. Converts a color space/range to matrix/min/max values.
  61. :param color_space: Color space to convert
  62. :param range: Color range to convert
  63. :param matrix: Pointer to the matrix
  64. :param min_range: Pointer to get the minimum range value
  65. :param max_range: Pointer to get the maximum range value
  66. ---------------------
  67. .. function:: bool video_output_connect(video_t *video, const struct video_scale_info *conversion, void (*callback)(void *param, struct video_data *frame), void *param)
  68. Connects a raw video callback to the video output handler.
  69. :param video: Video output handler object
  70. :param callback: Callback to receive video data
  71. :param param: Private data to pass to the callback
  72. ---------------------
  73. .. function:: void video_output_disconnect(video_t *video, void (*callback)(void *param, struct video_data *frame), void *param)
  74. Disconnects a raw video callback from the video output handler.
  75. :param video: Video output handler object
  76. :param callback: Callback
  77. :param param: Private data
  78. ---------------------
  79. .. function:: const struct video_output_info *video_output_get_info(const video_t *video)
  80. Gets the full video information of the video output handler.
  81. :param video: Video output handler object
  82. :return: Video output info structure pointer
  83. ---------------------
  84. .. function:: uint64_t video_output_get_frame_time(const video_t *video)
  85. Gets the frame interval of the video output handler.
  86. :param video: Video output handler object
  87. :return: Video frame interval in nanoseconds
  88. ---------------------
  89. .. function:: enum video_format video_output_get_format(const video_t *video)
  90. Gets the video format of the video output handler.
  91. :param video: Video output handler object
  92. :return: Video format
  93. ---------------------
  94. .. function:: uint32_t video_output_get_width(const video_t *video)
  95. .. function:: uint32_t video_output_get_height(const video_t *video)
  96. Gets the width/height of the video output handler.
  97. :param video: Video output handler object
  98. :return: Width/height
  99. ---------------------
  100. .. function:: double video_output_get_frame_rate(const video_t *video)
  101. Gets the frame rate (as a floating point) of the video output
  102. handler.
  103. :param video: Video output handler object
  104. :return: Frame rate
  105. ---------------------
  106. .. function:: uint32_t video_output_get_skipped_frames(const video_t *video)
  107. Gets the skipped frame count of the video output handler.
  108. :param video: Video output handler object
  109. :return: Skipped frame count
  110. ---------------------
  111. .. function:: uint32_t video_output_get_total_frames(const video_t *video)
  112. Gets the total frames processed of the video output handler.
  113. :param video: Video output handler object
  114. :return: Total frames processed
  115. ---------------------
  116. Audio Handler
  117. -------------
  118. .. type:: audio_t
  119. ---------------------
  120. .. type:: enum audio_format
  121. Audio format. Can be one of the following values:
  122. - AUDIO_FORMAT_UNKNOWN
  123. - AUDIO_FORMAT_U8BIT
  124. - AUDIO_FORMAT_16BIT
  125. - AUDIO_FORMAT_32BIT
  126. - AUDIO_FORMAT_FLOAT
  127. - AUDIO_FORMAT_U8BIT_PLANAR
  128. - AUDIO_FORMAT_16BIT_PLANAR
  129. - AUDIO_FORMAT_32BIT_PLANAR
  130. - AUDIO_FORMAT_FLOAT_PLANAR
  131. ---------------------
  132. .. type:: enum speaker_layout
  133. Speaker layout. Can be one of the following values:
  134. - SPEAKERS_UNKNOWN
  135. - SPEAKERS_MONO
  136. - SPEAKERS_STEREO
  137. - SPEAKERS_2POINT1
  138. - SPEAKERS_4POINT0
  139. - SPEAKERS_4POINT1
  140. - SPEAKERS_5POINT1
  141. - SPEAKERS_5POINT1_SURROUND
  142. - SPEAKERS_7POINT1
  143. - SPEAKERS_7POINT1_SURROUND
  144. - SPEAKERS_SURROUND
  145. ---------------------
  146. .. type:: struct audio_data
  147. Audio data structure.
  148. .. member:: uint8_t *audio_data.data[MAX_AV_PLANES]
  149. .. member:: uint32_t audio_data.frames
  150. .. member:: uint64_t audio_data.timestamp
  151. ---------------------
  152. .. type:: struct audio_output_data
  153. .. member:: float *audio_output_data.data[MAX_AUDIO_CHANNELS]
  154. ---------------------
  155. .. type:: struct audio_output_info
  156. .. member:: const char *audio_output_info.name
  157. .. member:: uint32_t audio_output_info.samples_per_sec
  158. .. member:: enum audio_format audio_output_info.format
  159. .. member:: enum speaker_layout audio_output_info.speakers
  160. .. member:: audio_input_callback_t audio_output_info.input_callback
  161. .. member:: void *audio_output_info.input_param
  162. ---------------------
  163. .. type:: struct audio_convert_info
  164. .. member:: uint32_t audio_convert_info.samples_per_sec
  165. .. member:: enum audio_format audio_convert_info.format
  166. .. member:: enum speaker_layout audio_convert_info.speakers
  167. ---------------------
  168. .. type:: typedef bool (*audio_input_callback_t)(void *param, uint64_t start_ts, uint64_t end_ts, uint64_t *new_ts, uint32_t active_mixers, struct audio_output_data *mixes)
  169. Audio input callback (typically used internally).
  170. ---------------------
  171. .. function:: uint32_t get_audio_channels(enum speaker_layout speakers)
  172. Converts a speaker layout to its audio channel count.
  173. :param speakers: Speaker layout enumeration
  174. :return: Channel count
  175. ---------------------
  176. .. function:: size_t get_audio_bytes_per_channel(enum audio_format format)
  177. Gets the audio bytes per channel for a specific audio format.
  178. :param format: Audio format
  179. :return: Bytes per channel
  180. ---------------------
  181. .. function:: bool is_audio_planar(enum audio_format format)
  182. Returns whether the audio format is a planar format.
  183. :param format: Audio format
  184. :return: *true* if audio is planar, *false* otherwise
  185. ---------------------
  186. .. function:: size_t get_audio_planes(enum audio_format format, enum speaker_layout speakers)
  187. Gets the number of audio planes for a specific audio format and
  188. speaker layout.
  189. :param format: Audio format
  190. :param speakers: Speaker layout
  191. :return: Number of audio planes
  192. ---------------------
  193. .. function:: size_t get_audio_size(enum audio_format format, enum speaker_layout speakers, uint32_t frames)
  194. Gets the audio block size for a specific frame out with the given
  195. format and speaker layout.
  196. :param format: Audio format
  197. :param speakers: Speaker layout
  198. :param frames: Audio frame count
  199. :return: Audio block size
  200. ---------------------
  201. .. function:: uint64_t audio_frames_to_ns(size_t sample_rate, uint64_t frames)
  202. Helper function to convert a specific number of audio frames to
  203. nanoseconds based upon its sample rate.
  204. :param sample_rate: Sample rate
  205. :param frames: Frame count
  206. :return: Nanoseconds
  207. ---------------------
  208. .. function:: uint64_t ns_to_audio_frames(size_t sample_rate, uint64_t ns)
  209. Helper function to convert a specific number of nanoseconds to audio
  210. frame count based upon its sample rate.
  211. :param sample_rate: Sample rate
  212. :param ns: Nanoseconds
  213. :return: Frame count
  214. ---------------------
  215. .. type:: typedef void (*audio_output_callback_t)(void *param, size_t mix_idx, struct audio_data *data)
  216. Audio output callback. Typically used internally.
  217. ---------------------
  218. .. function:: bool audio_output_connect(audio_t *audio, size_t mix_idx, const struct audio_convert_info *conversion, audio_output_callback_t callback, void *param)
  219. Connects a raw audio callback to the audio output handler.
  220. Optionally allows audio conversion if necessary.
  221. :param audio: Audio output handler object
  222. :param mix_idx: Mix index to get raw audio from
  223. :param conversion: Audio conversion information, or *NULL* for no
  224. conversion
  225. :param callback: Raw audio callback
  226. :param param: Private data to pass to the callback
  227. ---------------------
  228. .. function:: void audio_output_disconnect(audio_t *audio, size_t mix_idx, audio_output_callback_t callback, void *param)
  229. Disconnects a raw audio callback from the audio output handler.
  230. :param audio: Audio output handler object
  231. :param mix_idx: Mix index to get raw audio from
  232. :param callback: Raw audio callback
  233. :param param: Private data to pass to the callback
  234. ---------------------
  235. .. function:: size_t audio_output_get_block_size(const audio_t *audio)
  236. Gets the audio block size of an audio output handler.
  237. :param audio: Audio output handler object
  238. :return: Audio block size
  239. ---------------------
  240. .. function:: size_t audio_output_get_planes(const audio_t *audio)
  241. Gets the plane count of an audio output handler.
  242. :param audio: Audio output handler object
  243. :return: Audio plane count
  244. ---------------------
  245. .. function:: size_t audio_output_get_channels(const audio_t *audio)
  246. Gets the channel count of an audio output handler.
  247. :param audio: Audio output handler object
  248. :return: Audio channel count
  249. ---------------------
  250. .. function:: uint32_t audio_output_get_sample_rate(const audio_t *audio)
  251. Gets the sample rate of an audio output handler.
  252. :param audio: Audio output handler object
  253. :return: Audio sample rate
  254. ---------------------
  255. .. function:: const struct audio_output_info *audio_output_get_info(const audio_t *audio)
  256. Gets all audio information for an audio output handler.
  257. :param audio: Audio output handler object
  258. :return: Pointer to audio output information structure
  259. ---------------------
  260. Resampler
  261. ---------
  262. FFmpeg wrapper to resample audio.
  263. .. type:: typedef struct audio_resampler audio_resampler_t
  264. ---------------------
  265. .. type:: struct resample_info
  266. .. member:: uint32_t resample_info.samples_per_sec
  267. .. member:: enum audio_format resample_info.format
  268. .. member:: enum speaker_layout resample_info.speakers
  269. ---------------------
  270. .. function:: audio_resampler_t *audio_resampler_create(const struct resample_info *dst, const struct resample_info *src)
  271. Creates an audio resampler.
  272. :param dst: Destination audio information
  273. :param src: Source audio information
  274. :return: Audio resampler object
  275. ---------------------
  276. .. function:: void audio_resampler_destroy(audio_resampler_t *resampler)
  277. Destroys an audio resampler.
  278. :param resampler: Audio resampler object
  279. ---------------------
  280. .. function:: bool audio_resampler_resample(audio_resampler_t *resampler, uint8_t *output[], uint32_t *out_frames, uint64_t *ts_offset, const uint8_t *const input[], uint32_t in_frames)
  281. Resamples audio frames.
  282. :param resampler: Audio resampler object
  283. :param output: Pointer to receive converted audio frames
  284. :param out_frames: Pointer to receive converted audio frame count
  285. :param ts_offset: Pointer to receive timestamp offset (in
  286. nanoseconds)
  287. :param const input: Input frames to convert
  288. :param in_frames: Input frame count