video-io.h 7.7 KB

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