video-io.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. struct video_frame;
  20. /* Base video output component. Use this to create a video output track. */
  21. struct video_output;
  22. typedef struct video_output video_t;
  23. enum video_format {
  24. VIDEO_FORMAT_NONE,
  25. /* planar 420 format */
  26. VIDEO_FORMAT_I420, /* three-plane */
  27. VIDEO_FORMAT_NV12, /* two-plane, luma and packed chroma */
  28. /* packed 422 formats */
  29. VIDEO_FORMAT_YVYU,
  30. VIDEO_FORMAT_YUY2, /* YUYV */
  31. VIDEO_FORMAT_UYVY,
  32. /* packed uncompressed formats */
  33. VIDEO_FORMAT_RGBA,
  34. VIDEO_FORMAT_BGRA,
  35. VIDEO_FORMAT_BGRX,
  36. VIDEO_FORMAT_Y800, /* grayscale */
  37. /* planar 4:4:4 */
  38. VIDEO_FORMAT_I444,
  39. /* more packed uncompressed formats */
  40. VIDEO_FORMAT_BGR3,
  41. /* planar 4:2:2 */
  42. VIDEO_FORMAT_I422,
  43. /* planar 4:2:0 with alpha */
  44. VIDEO_FORMAT_I40A,
  45. /* planar 4:2:2 with alpha */
  46. VIDEO_FORMAT_I42A,
  47. /* planar 4:4:4 with alpha */
  48. VIDEO_FORMAT_YUVA,
  49. /* packed 4:4:4 with alpha */
  50. VIDEO_FORMAT_AYUV,
  51. };
  52. enum video_colorspace {
  53. VIDEO_CS_DEFAULT,
  54. VIDEO_CS_601,
  55. VIDEO_CS_709,
  56. VIDEO_CS_SRGB,
  57. };
  58. enum video_range_type {
  59. VIDEO_RANGE_DEFAULT,
  60. VIDEO_RANGE_PARTIAL,
  61. VIDEO_RANGE_FULL
  62. };
  63. struct video_data {
  64. uint8_t *data[MAX_AV_PLANES];
  65. uint32_t linesize[MAX_AV_PLANES];
  66. uint64_t timestamp;
  67. };
  68. struct video_output_info {
  69. const char *name;
  70. enum video_format format;
  71. uint32_t fps_num;
  72. uint32_t fps_den;
  73. uint32_t width;
  74. uint32_t height;
  75. size_t cache_size;
  76. enum video_colorspace colorspace;
  77. enum video_range_type range;
  78. };
  79. static inline bool format_is_yuv(enum video_format format)
  80. {
  81. switch (format) {
  82. case VIDEO_FORMAT_I420:
  83. case VIDEO_FORMAT_NV12:
  84. case VIDEO_FORMAT_I422:
  85. case VIDEO_FORMAT_YVYU:
  86. case VIDEO_FORMAT_YUY2:
  87. case VIDEO_FORMAT_UYVY:
  88. case VIDEO_FORMAT_I444:
  89. case VIDEO_FORMAT_I40A:
  90. case VIDEO_FORMAT_I42A:
  91. case VIDEO_FORMAT_YUVA:
  92. case VIDEO_FORMAT_AYUV:
  93. return true;
  94. case VIDEO_FORMAT_NONE:
  95. case VIDEO_FORMAT_RGBA:
  96. case VIDEO_FORMAT_BGRA:
  97. case VIDEO_FORMAT_BGRX:
  98. case VIDEO_FORMAT_Y800:
  99. case VIDEO_FORMAT_BGR3:
  100. return false;
  101. }
  102. return false;
  103. }
  104. static inline const char *get_video_format_name(enum video_format format)
  105. {
  106. switch (format) {
  107. case VIDEO_FORMAT_I420:
  108. return "I420";
  109. case VIDEO_FORMAT_NV12:
  110. return "NV12";
  111. case VIDEO_FORMAT_I422:
  112. return "I422";
  113. case VIDEO_FORMAT_YVYU:
  114. return "YVYU";
  115. case VIDEO_FORMAT_YUY2:
  116. return "YUY2";
  117. case VIDEO_FORMAT_UYVY:
  118. return "UYVY";
  119. case VIDEO_FORMAT_RGBA:
  120. return "RGBA";
  121. case VIDEO_FORMAT_BGRA:
  122. return "BGRA";
  123. case VIDEO_FORMAT_BGRX:
  124. return "BGRX";
  125. case VIDEO_FORMAT_I444:
  126. return "I444";
  127. case VIDEO_FORMAT_Y800:
  128. return "Y800";
  129. case VIDEO_FORMAT_BGR3:
  130. return "BGR3";
  131. case VIDEO_FORMAT_I40A:
  132. return "I40A";
  133. case VIDEO_FORMAT_I42A:
  134. return "I42A";
  135. case VIDEO_FORMAT_YUVA:
  136. return "YUVA";
  137. case VIDEO_FORMAT_AYUV:
  138. return "AYUV";
  139. case VIDEO_FORMAT_NONE:;
  140. }
  141. return "None";
  142. }
  143. static inline const char *get_video_colorspace_name(enum video_colorspace cs)
  144. {
  145. switch (cs) {
  146. case VIDEO_CS_709:
  147. return "709";
  148. case VIDEO_CS_601:
  149. case VIDEO_CS_DEFAULT:
  150. case VIDEO_CS_SRGB:;
  151. }
  152. return "601";
  153. }
  154. static inline enum video_range_type
  155. resolve_video_range(enum video_format format, enum video_range_type range)
  156. {
  157. if (range == VIDEO_RANGE_DEFAULT) {
  158. range = format_is_yuv(format) ? VIDEO_RANGE_PARTIAL
  159. : VIDEO_RANGE_FULL;
  160. }
  161. return range;
  162. }
  163. static inline const char *get_video_range_name(enum video_format format,
  164. enum video_range_type range)
  165. {
  166. range = resolve_video_range(format, range);
  167. return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
  168. }
  169. enum video_scale_type {
  170. VIDEO_SCALE_DEFAULT,
  171. VIDEO_SCALE_POINT,
  172. VIDEO_SCALE_FAST_BILINEAR,
  173. VIDEO_SCALE_BILINEAR,
  174. VIDEO_SCALE_BICUBIC,
  175. };
  176. struct video_scale_info {
  177. enum video_format format;
  178. uint32_t width;
  179. uint32_t height;
  180. enum video_range_type range;
  181. enum video_colorspace colorspace;
  182. };
  183. EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc);
  184. EXPORT bool video_format_get_parameters(enum video_colorspace color_space,
  185. enum video_range_type range,
  186. float matrix[16], float min_range[3],
  187. float max_range[3]);
  188. #define VIDEO_OUTPUT_SUCCESS 0
  189. #define VIDEO_OUTPUT_INVALIDPARAM -1
  190. #define VIDEO_OUTPUT_FAIL -2
  191. EXPORT int video_output_open(video_t **video, struct video_output_info *info);
  192. EXPORT void video_output_close(video_t *video);
  193. EXPORT bool
  194. video_output_connect(video_t *video, const struct video_scale_info *conversion,
  195. void (*callback)(void *param, struct video_data *frame),
  196. void *param);
  197. EXPORT void video_output_disconnect(video_t *video,
  198. void (*callback)(void *param,
  199. struct video_data *frame),
  200. void *param);
  201. EXPORT bool video_output_active(const video_t *video);
  202. EXPORT const struct video_output_info *
  203. video_output_get_info(const video_t *video);
  204. EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame,
  205. int count, uint64_t timestamp);
  206. EXPORT void video_output_unlock_frame(video_t *video);
  207. EXPORT uint64_t video_output_get_frame_time(const video_t *video);
  208. EXPORT void video_output_stop(video_t *video);
  209. EXPORT bool video_output_stopped(video_t *video);
  210. EXPORT enum video_format video_output_get_format(const video_t *video);
  211. EXPORT uint32_t video_output_get_width(const video_t *video);
  212. EXPORT uint32_t video_output_get_height(const video_t *video);
  213. EXPORT double video_output_get_frame_rate(const video_t *video);
  214. EXPORT uint32_t video_output_get_skipped_frames(const video_t *video);
  215. EXPORT uint32_t video_output_get_total_frames(const video_t *video);
  216. extern void video_output_inc_texture_encoders(video_t *video);
  217. extern void video_output_dec_texture_encoders(video_t *video);
  218. extern void video_output_inc_texture_frames(video_t *video);
  219. extern void video_output_inc_texture_skipped_frames(video_t *video);
  220. #ifdef __cplusplus
  221. }
  222. #endif