video-io.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "media-io-defs.h"
  16. #include "../util/c99defs.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct video_frame;
  21. /* Base video output component. Use this to create a video output track. */
  22. struct video_output;
  23. typedef struct video_output video_t;
  24. enum video_format {
  25. VIDEO_FORMAT_NONE,
  26. /* planar 4:2:0 formats */
  27. VIDEO_FORMAT_I420, /* three-plane */
  28. VIDEO_FORMAT_NV12, /* two-plane, luma and packed chroma */
  29. /* packed 4:2:2 formats */
  30. VIDEO_FORMAT_YVYU,
  31. VIDEO_FORMAT_YUY2, /* YUYV */
  32. VIDEO_FORMAT_UYVY,
  33. /* packed uncompressed formats */
  34. VIDEO_FORMAT_RGBA,
  35. VIDEO_FORMAT_BGRA,
  36. VIDEO_FORMAT_BGRX,
  37. VIDEO_FORMAT_Y800, /* grayscale */
  38. /* planar 4:4:4 */
  39. VIDEO_FORMAT_I444,
  40. /* more packed uncompressed formats */
  41. VIDEO_FORMAT_BGR3,
  42. /* planar 4:2:2 */
  43. VIDEO_FORMAT_I422,
  44. /* planar 4:2:0 with alpha */
  45. VIDEO_FORMAT_I40A,
  46. /* planar 4:2:2 with alpha */
  47. VIDEO_FORMAT_I42A,
  48. /* planar 4:4:4 with alpha */
  49. VIDEO_FORMAT_YUVA,
  50. /* packed 4:4:4 with alpha */
  51. VIDEO_FORMAT_AYUV,
  52. /* planar 4:2:0 format, 10 bpp */
  53. VIDEO_FORMAT_I010, /* three-plane */
  54. VIDEO_FORMAT_P010, /* two-plane, luma and packed chroma */
  55. };
  56. enum video_trc {
  57. VIDEO_TRC_DEFAULT,
  58. VIDEO_TRC_SRGB,
  59. VIDEO_TRC_PQ,
  60. VIDEO_TRC_HLG,
  61. };
  62. enum video_colorspace {
  63. VIDEO_CS_DEFAULT,
  64. VIDEO_CS_601,
  65. VIDEO_CS_709,
  66. VIDEO_CS_SRGB,
  67. VIDEO_CS_2020_PQ,
  68. VIDEO_CS_2020_HLG,
  69. };
  70. enum video_range_type {
  71. VIDEO_RANGE_DEFAULT,
  72. VIDEO_RANGE_PARTIAL,
  73. VIDEO_RANGE_FULL,
  74. };
  75. struct video_data {
  76. uint8_t *data[MAX_AV_PLANES];
  77. uint32_t linesize[MAX_AV_PLANES];
  78. uint64_t timestamp;
  79. };
  80. struct video_output_info {
  81. const char *name;
  82. enum video_format format;
  83. uint32_t fps_num;
  84. uint32_t fps_den;
  85. uint32_t width;
  86. uint32_t height;
  87. size_t cache_size;
  88. enum video_colorspace colorspace;
  89. enum video_range_type range;
  90. };
  91. static inline bool format_is_yuv(enum video_format format)
  92. {
  93. switch (format) {
  94. case VIDEO_FORMAT_I420:
  95. case VIDEO_FORMAT_NV12:
  96. case VIDEO_FORMAT_I422:
  97. case VIDEO_FORMAT_YVYU:
  98. case VIDEO_FORMAT_YUY2:
  99. case VIDEO_FORMAT_UYVY:
  100. case VIDEO_FORMAT_I444:
  101. case VIDEO_FORMAT_I40A:
  102. case VIDEO_FORMAT_I42A:
  103. case VIDEO_FORMAT_YUVA:
  104. case VIDEO_FORMAT_AYUV:
  105. case VIDEO_FORMAT_I010:
  106. case VIDEO_FORMAT_P010:
  107. return true;
  108. case VIDEO_FORMAT_NONE:
  109. case VIDEO_FORMAT_RGBA:
  110. case VIDEO_FORMAT_BGRA:
  111. case VIDEO_FORMAT_BGRX:
  112. case VIDEO_FORMAT_Y800:
  113. case VIDEO_FORMAT_BGR3:
  114. return false;
  115. }
  116. return false;
  117. }
  118. static inline const char *get_video_format_name(enum video_format format)
  119. {
  120. switch (format) {
  121. case VIDEO_FORMAT_I420:
  122. return "I420";
  123. case VIDEO_FORMAT_NV12:
  124. return "NV12";
  125. case VIDEO_FORMAT_I422:
  126. return "I422";
  127. case VIDEO_FORMAT_YVYU:
  128. return "YVYU";
  129. case VIDEO_FORMAT_YUY2:
  130. return "YUY2";
  131. case VIDEO_FORMAT_UYVY:
  132. return "UYVY";
  133. case VIDEO_FORMAT_RGBA:
  134. return "RGBA";
  135. case VIDEO_FORMAT_BGRA:
  136. return "BGRA";
  137. case VIDEO_FORMAT_BGRX:
  138. return "BGRX";
  139. case VIDEO_FORMAT_I444:
  140. return "I444";
  141. case VIDEO_FORMAT_Y800:
  142. return "Y800";
  143. case VIDEO_FORMAT_BGR3:
  144. return "BGR3";
  145. case VIDEO_FORMAT_I40A:
  146. return "I40A";
  147. case VIDEO_FORMAT_I42A:
  148. return "I42A";
  149. case VIDEO_FORMAT_YUVA:
  150. return "YUVA";
  151. case VIDEO_FORMAT_AYUV:
  152. return "AYUV";
  153. case VIDEO_FORMAT_I010:
  154. return "I010";
  155. case VIDEO_FORMAT_P010:
  156. return "P010";
  157. case VIDEO_FORMAT_NONE:;
  158. }
  159. return "None";
  160. }
  161. static inline const char *get_video_colorspace_name(enum video_colorspace cs)
  162. {
  163. switch (cs) {
  164. case VIDEO_CS_DEFAULT:
  165. case VIDEO_CS_709:
  166. return "Rec. 709";
  167. case VIDEO_CS_SRGB:
  168. return "sRGB";
  169. case VIDEO_CS_601:
  170. return "Rec. 601";
  171. case VIDEO_CS_2020_PQ:
  172. return "Rec. 2020 (PQ)";
  173. case VIDEO_CS_2020_HLG:
  174. return "Rec. 2020 (HLG)";
  175. }
  176. return "Unknown";
  177. }
  178. static inline enum video_range_type
  179. resolve_video_range(enum video_format format, enum video_range_type range)
  180. {
  181. if (range == VIDEO_RANGE_DEFAULT) {
  182. range = format_is_yuv(format) ? VIDEO_RANGE_PARTIAL
  183. : VIDEO_RANGE_FULL;
  184. }
  185. return range;
  186. }
  187. static inline const char *get_video_range_name(enum video_format format,
  188. enum video_range_type range)
  189. {
  190. range = resolve_video_range(format, range);
  191. return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
  192. }
  193. enum video_scale_type {
  194. VIDEO_SCALE_DEFAULT,
  195. VIDEO_SCALE_POINT,
  196. VIDEO_SCALE_FAST_BILINEAR,
  197. VIDEO_SCALE_BILINEAR,
  198. VIDEO_SCALE_BICUBIC,
  199. };
  200. struct video_scale_info {
  201. enum video_format format;
  202. uint32_t width;
  203. uint32_t height;
  204. enum video_range_type range;
  205. enum video_colorspace colorspace;
  206. };
  207. EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc);
  208. EXPORT bool video_format_get_parameters(enum video_colorspace color_space,
  209. enum video_range_type range,
  210. float matrix[16], float min_range[3],
  211. float max_range[3]);
  212. EXPORT bool video_format_get_parameters_for_format(
  213. enum video_colorspace color_space, enum video_range_type range,
  214. enum video_format format, float matrix[16], float min_range[3],
  215. float max_range[3]);
  216. #define VIDEO_OUTPUT_SUCCESS 0
  217. #define VIDEO_OUTPUT_INVALIDPARAM -1
  218. #define VIDEO_OUTPUT_FAIL -2
  219. EXPORT int video_output_open(video_t **video, struct video_output_info *info);
  220. EXPORT void video_output_close(video_t *video);
  221. EXPORT bool
  222. video_output_connect(video_t *video, const struct video_scale_info *conversion,
  223. void (*callback)(void *param, struct video_data *frame),
  224. void *param);
  225. EXPORT void video_output_disconnect(video_t *video,
  226. void (*callback)(void *param,
  227. struct video_data *frame),
  228. void *param);
  229. EXPORT bool video_output_active(const video_t *video);
  230. EXPORT const struct video_output_info *
  231. video_output_get_info(const video_t *video);
  232. EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame,
  233. int count, uint64_t timestamp);
  234. EXPORT void video_output_unlock_frame(video_t *video);
  235. EXPORT uint64_t video_output_get_frame_time(const video_t *video);
  236. EXPORT void video_output_stop(video_t *video);
  237. EXPORT bool video_output_stopped(video_t *video);
  238. EXPORT enum video_format video_output_get_format(const video_t *video);
  239. EXPORT uint32_t video_output_get_width(const video_t *video);
  240. EXPORT uint32_t video_output_get_height(const video_t *video);
  241. EXPORT double video_output_get_frame_rate(const video_t *video);
  242. EXPORT uint32_t video_output_get_skipped_frames(const video_t *video);
  243. EXPORT uint32_t video_output_get_total_frames(const video_t *video);
  244. extern void video_output_inc_texture_encoders(video_t *video);
  245. extern void video_output_dec_texture_encoders(video_t *video);
  246. extern void video_output_inc_texture_frames(video_t *video);
  247. extern void video_output_inc_texture_skipped_frames(video_t *video);
  248. #ifdef __cplusplus
  249. }
  250. #endif