video-io.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. };
  40. enum video_colorspace {
  41. VIDEO_CS_DEFAULT,
  42. VIDEO_CS_601,
  43. VIDEO_CS_709,
  44. };
  45. enum video_range_type {
  46. VIDEO_RANGE_DEFAULT,
  47. VIDEO_RANGE_PARTIAL,
  48. VIDEO_RANGE_FULL
  49. };
  50. struct video_data {
  51. uint8_t *data[MAX_AV_PLANES];
  52. uint32_t linesize[MAX_AV_PLANES];
  53. uint64_t timestamp;
  54. };
  55. struct video_output_info {
  56. const char *name;
  57. enum video_format format;
  58. uint32_t fps_num;
  59. uint32_t fps_den;
  60. uint32_t width;
  61. uint32_t height;
  62. size_t cache_size;
  63. enum video_colorspace colorspace;
  64. enum video_range_type range;
  65. };
  66. static inline bool format_is_yuv(enum video_format format)
  67. {
  68. switch (format) {
  69. case VIDEO_FORMAT_I420:
  70. case VIDEO_FORMAT_NV12:
  71. case VIDEO_FORMAT_YVYU:
  72. case VIDEO_FORMAT_YUY2:
  73. case VIDEO_FORMAT_UYVY:
  74. case VIDEO_FORMAT_I444:
  75. return true;
  76. case VIDEO_FORMAT_NONE:
  77. case VIDEO_FORMAT_RGBA:
  78. case VIDEO_FORMAT_BGRA:
  79. case VIDEO_FORMAT_BGRX:
  80. case VIDEO_FORMAT_Y800:
  81. return false;
  82. }
  83. return false;
  84. }
  85. static inline const char *get_video_format_name(enum video_format format)
  86. {
  87. switch (format) {
  88. case VIDEO_FORMAT_I420: return "I420";
  89. case VIDEO_FORMAT_NV12: return "NV12";
  90. case VIDEO_FORMAT_YVYU: return "YVYU";
  91. case VIDEO_FORMAT_YUY2: return "YUY2";
  92. case VIDEO_FORMAT_UYVY: return "UYVY";
  93. case VIDEO_FORMAT_RGBA: return "RGBA";
  94. case VIDEO_FORMAT_BGRA: return "BGRA";
  95. case VIDEO_FORMAT_BGRX: return "BGRX";
  96. case VIDEO_FORMAT_I444: return "I444";
  97. case VIDEO_FORMAT_Y800: return "Y800";
  98. case VIDEO_FORMAT_NONE:;
  99. }
  100. return "None";
  101. }
  102. static inline const char *get_video_colorspace_name(enum video_colorspace cs)
  103. {
  104. switch (cs) {
  105. case VIDEO_CS_709: return "709";
  106. case VIDEO_CS_601:
  107. case VIDEO_CS_DEFAULT:;
  108. }
  109. return "601";
  110. }
  111. static inline enum video_range_type resolve_video_range(
  112. enum video_format format, enum video_range_type range)
  113. {
  114. if (range == VIDEO_RANGE_DEFAULT) {
  115. range = format_is_yuv(format)
  116. ? VIDEO_RANGE_PARTIAL
  117. : VIDEO_RANGE_FULL;
  118. }
  119. return range;
  120. }
  121. static inline const char *get_video_range_name(enum video_format format,
  122. enum video_range_type range)
  123. {
  124. range = resolve_video_range(format, range);
  125. return range == VIDEO_RANGE_FULL ? "Full" : "Partial";
  126. }
  127. enum video_scale_type {
  128. VIDEO_SCALE_DEFAULT,
  129. VIDEO_SCALE_POINT,
  130. VIDEO_SCALE_FAST_BILINEAR,
  131. VIDEO_SCALE_BILINEAR,
  132. VIDEO_SCALE_BICUBIC,
  133. };
  134. struct video_scale_info {
  135. enum video_format format;
  136. uint32_t width;
  137. uint32_t height;
  138. enum video_range_type range;
  139. enum video_colorspace colorspace;
  140. };
  141. EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc);
  142. EXPORT bool video_format_get_parameters(enum video_colorspace color_space,
  143. enum video_range_type range, float matrix[16],
  144. float min_range[3], float max_range[3]);
  145. #define VIDEO_OUTPUT_SUCCESS 0
  146. #define VIDEO_OUTPUT_INVALIDPARAM -1
  147. #define VIDEO_OUTPUT_FAIL -2
  148. EXPORT int video_output_open(video_t **video, struct video_output_info *info);
  149. EXPORT void video_output_close(video_t *video);
  150. EXPORT bool video_output_connect(video_t *video,
  151. const struct video_scale_info *conversion,
  152. void (*callback)(void *param, struct video_data *frame),
  153. void *param);
  154. EXPORT void video_output_disconnect(video_t *video,
  155. void (*callback)(void *param, struct video_data *frame),
  156. void *param);
  157. EXPORT bool video_output_active(const video_t *video);
  158. EXPORT const struct video_output_info *video_output_get_info(
  159. const video_t *video);
  160. EXPORT bool video_output_lock_frame(video_t *video, struct video_frame *frame,
  161. int count, uint64_t timestamp);
  162. EXPORT void video_output_unlock_frame(video_t *video);
  163. EXPORT uint64_t video_output_get_frame_time(const video_t *video);
  164. EXPORT void video_output_stop(video_t *video);
  165. EXPORT bool video_output_stopped(video_t *video);
  166. EXPORT enum video_format video_output_get_format(const video_t *video);
  167. EXPORT uint32_t video_output_get_width(const video_t *video);
  168. EXPORT uint32_t video_output_get_height(const video_t *video);
  169. EXPORT double video_output_get_frame_rate(const video_t *video);
  170. EXPORT uint32_t video_output_get_skipped_frames(const video_t *video);
  171. EXPORT uint32_t video_output_get_total_frames(const video_t *video);
  172. extern void video_output_inc_texture_encoders(video_t *video);
  173. extern void video_output_dec_texture_encoders(video_t *video);
  174. extern void video_output_inc_texture_frames(video_t *video);
  175. extern void video_output_inc_texture_skipped_frames(video_t *video);
  176. #ifdef __cplusplus
  177. }
  178. #endif