video-io.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. /* planar 4:2:2 format, 10 bpp */
  56. VIDEO_FORMAT_I210,
  57. /* planar 4:4:4 format, 12 bpp */
  58. VIDEO_FORMAT_I412,
  59. /* planar 4:4:4:4 format, 12 bpp */
  60. VIDEO_FORMAT_YA2L,
  61. /* planar 4:2:2 format, 16 bpp */
  62. VIDEO_FORMAT_P216, /* two-plane, luma and packed chroma */
  63. /* planar 4:4:4 format, 16 bpp */
  64. VIDEO_FORMAT_P416, /* two-plane, luma and packed chroma */
  65. /* packed 4:2:2 format, 10 bpp */
  66. VIDEO_FORMAT_V210,
  67. };
  68. enum video_trc {
  69. VIDEO_TRC_DEFAULT,
  70. VIDEO_TRC_SRGB,
  71. VIDEO_TRC_PQ,
  72. VIDEO_TRC_HLG,
  73. };
  74. enum video_colorspace {
  75. VIDEO_CS_DEFAULT,
  76. VIDEO_CS_601,
  77. VIDEO_CS_709,
  78. VIDEO_CS_SRGB,
  79. VIDEO_CS_2100_PQ,
  80. VIDEO_CS_2100_HLG,
  81. };
  82. enum video_range_type {
  83. VIDEO_RANGE_DEFAULT,
  84. VIDEO_RANGE_PARTIAL,
  85. VIDEO_RANGE_FULL,
  86. };
  87. struct video_data {
  88. uint8_t *data[MAX_AV_PLANES];
  89. uint32_t linesize[MAX_AV_PLANES];
  90. uint64_t timestamp;
  91. };
  92. struct video_output_info {
  93. const char *name;
  94. enum video_format format;
  95. uint32_t fps_num;
  96. uint32_t fps_den;
  97. uint32_t width;
  98. uint32_t height;
  99. size_t cache_size;
  100. enum video_colorspace colorspace;
  101. enum video_range_type range;
  102. };
  103. static inline bool format_is_yuv(enum video_format format)
  104. {
  105. switch (format) {
  106. case VIDEO_FORMAT_I420:
  107. case VIDEO_FORMAT_NV12:
  108. case VIDEO_FORMAT_I422:
  109. case VIDEO_FORMAT_I210:
  110. case VIDEO_FORMAT_YVYU:
  111. case VIDEO_FORMAT_YUY2:
  112. case VIDEO_FORMAT_UYVY:
  113. case VIDEO_FORMAT_I444:
  114. case VIDEO_FORMAT_I412:
  115. case VIDEO_FORMAT_I40A:
  116. case VIDEO_FORMAT_I42A:
  117. case VIDEO_FORMAT_YUVA:
  118. case VIDEO_FORMAT_YA2L:
  119. case VIDEO_FORMAT_AYUV:
  120. case VIDEO_FORMAT_I010:
  121. case VIDEO_FORMAT_P010:
  122. case VIDEO_FORMAT_P216:
  123. case VIDEO_FORMAT_P416:
  124. case VIDEO_FORMAT_V210:
  125. return true;
  126. case VIDEO_FORMAT_NONE:
  127. case VIDEO_FORMAT_RGBA:
  128. case VIDEO_FORMAT_BGRA:
  129. case VIDEO_FORMAT_BGRX:
  130. case VIDEO_FORMAT_Y800:
  131. case VIDEO_FORMAT_BGR3:
  132. return false;
  133. }
  134. return false;
  135. }
  136. static inline const char *get_video_format_name(enum video_format format)
  137. {
  138. switch (format) {
  139. case VIDEO_FORMAT_I420:
  140. return "I420";
  141. case VIDEO_FORMAT_NV12:
  142. return "NV12";
  143. case VIDEO_FORMAT_I422:
  144. return "I422";
  145. case VIDEO_FORMAT_I210:
  146. return "I210";
  147. case VIDEO_FORMAT_YVYU:
  148. return "YVYU";
  149. case VIDEO_FORMAT_YUY2:
  150. return "YUY2";
  151. case VIDEO_FORMAT_UYVY:
  152. return "UYVY";
  153. case VIDEO_FORMAT_RGBA:
  154. return "RGBA";
  155. case VIDEO_FORMAT_BGRA:
  156. return "BGRA";
  157. case VIDEO_FORMAT_BGRX:
  158. return "BGRX";
  159. case VIDEO_FORMAT_I444:
  160. return "I444";
  161. case VIDEO_FORMAT_I412:
  162. return "I412";
  163. case VIDEO_FORMAT_Y800:
  164. return "Y800";
  165. case VIDEO_FORMAT_BGR3:
  166. return "BGR3";
  167. case VIDEO_FORMAT_I40A:
  168. return "I40A";
  169. case VIDEO_FORMAT_I42A:
  170. return "I42A";
  171. case VIDEO_FORMAT_YUVA:
  172. return "YUVA";
  173. case VIDEO_FORMAT_YA2L:
  174. return "YA2L";
  175. case VIDEO_FORMAT_AYUV:
  176. return "AYUV";
  177. case VIDEO_FORMAT_I010:
  178. return "I010";
  179. case VIDEO_FORMAT_P010:
  180. return "P010";
  181. case VIDEO_FORMAT_P216:
  182. return "P216";
  183. case VIDEO_FORMAT_P416:
  184. return "P416";
  185. case VIDEO_FORMAT_V210:
  186. return "v210";
  187. case VIDEO_FORMAT_NONE:;
  188. }
  189. return "None";
  190. }
  191. static inline const char *get_video_colorspace_name(enum video_colorspace cs)
  192. {
  193. switch (cs) {
  194. case VIDEO_CS_DEFAULT:
  195. case VIDEO_CS_709:
  196. return "Rec. 709";
  197. case VIDEO_CS_SRGB:
  198. return "sRGB";
  199. case VIDEO_CS_601:
  200. return "Rec. 601";
  201. case VIDEO_CS_2100_PQ:
  202. return "Rec. 2100 (PQ)";
  203. case VIDEO_CS_2100_HLG:
  204. return "Rec. 2100 (HLG)";
  205. }
  206. return "Unknown";
  207. }
  208. static inline enum video_range_type
  209. resolve_video_range(enum video_format format, enum video_range_type range)
  210. {
  211. if (range == VIDEO_RANGE_DEFAULT) {
  212. range = format_is_yuv(format) ? VIDEO_RANGE_PARTIAL
  213. : VIDEO_RANGE_FULL;
  214. }
  215. return range;
  216. }
  217. static inline const char *get_video_range_name(enum video_format format,
  218. enum video_range_type range)
  219. {
  220. range = resolve_video_range(format, range);
  221. return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
  222. }
  223. enum video_scale_type {
  224. VIDEO_SCALE_DEFAULT,
  225. VIDEO_SCALE_POINT,
  226. VIDEO_SCALE_FAST_BILINEAR,
  227. VIDEO_SCALE_BILINEAR,
  228. VIDEO_SCALE_BICUBIC,
  229. };
  230. struct video_scale_info {
  231. enum video_format format;
  232. uint32_t width;
  233. uint32_t height;
  234. enum video_range_type range;
  235. enum video_colorspace colorspace;
  236. };
  237. EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc);
  238. EXPORT bool video_format_get_parameters(enum video_colorspace color_space,
  239. enum video_range_type range,
  240. float matrix[16], float min_range[3],
  241. float max_range[3]);
  242. EXPORT bool video_format_get_parameters_for_format(
  243. enum video_colorspace color_space, enum video_range_type range,
  244. enum video_format format, float matrix[16], float min_range[3],
  245. float max_range[3]);
  246. #define VIDEO_OUTPUT_SUCCESS 0
  247. #define VIDEO_OUTPUT_INVALIDPARAM -1
  248. #define VIDEO_OUTPUT_FAIL -2
  249. EXPORT int video_output_open(video_t **video, struct video_output_info *info);
  250. EXPORT void video_output_close(video_t *video);
  251. EXPORT bool
  252. video_output_connect(video_t *video, const struct video_scale_info *conversion,
  253. void (*callback)(void *param, struct video_data *frame),
  254. void *param);
  255. EXPORT void video_output_disconnect(video_t *video,
  256. void (*callback)(void *param,
  257. struct video_data *frame),
  258. void *param);
  259. EXPORT bool video_output_active(const video_t *video);
  260. EXPORT const struct video_output_info *
  261. video_output_get_info(const video_t *video);
  262. EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame,
  263. int count, uint64_t timestamp);
  264. EXPORT void video_output_unlock_frame(video_t *video);
  265. EXPORT uint64_t video_output_get_frame_time(const video_t *video);
  266. EXPORT void video_output_stop(video_t *video);
  267. EXPORT bool video_output_stopped(video_t *video);
  268. EXPORT enum video_format video_output_get_format(const video_t *video);
  269. EXPORT uint32_t video_output_get_width(const video_t *video);
  270. EXPORT uint32_t video_output_get_height(const video_t *video);
  271. EXPORT double video_output_get_frame_rate(const video_t *video);
  272. EXPORT uint32_t video_output_get_skipped_frames(const video_t *video);
  273. EXPORT uint32_t video_output_get_total_frames(const video_t *video);
  274. extern void video_output_inc_texture_encoders(video_t *video);
  275. extern void video_output_dec_texture_encoders(video_t *video);
  276. extern void video_output_inc_texture_frames(video_t *video);
  277. extern void video_output_inc_texture_skipped_frames(video_t *video);
  278. #ifdef __cplusplus
  279. }
  280. #endif