video-io.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. /* Base video output component. Use this to create a video output track. */
  20. struct video_output;
  21. typedef struct video_output *video_t;
  22. enum video_format {
  23. VIDEO_FORMAT_NONE,
  24. /* planar 420 format */
  25. VIDEO_FORMAT_I420, /* three-plane */
  26. VIDEO_FORMAT_NV12, /* two-plane, luma and packed chroma */
  27. /* packed 422 formats */
  28. VIDEO_FORMAT_YVYU,
  29. VIDEO_FORMAT_YUY2, /* YUYV */
  30. VIDEO_FORMAT_UYVY,
  31. /* packed uncompressed formats */
  32. VIDEO_FORMAT_RGBA,
  33. VIDEO_FORMAT_BGRA,
  34. VIDEO_FORMAT_BGRX,
  35. };
  36. struct video_data {
  37. uint8_t *data[MAX_AV_PLANES];
  38. uint32_t linesize[MAX_AV_PLANES];
  39. uint64_t timestamp;
  40. };
  41. struct video_output_info {
  42. const char *name;
  43. enum video_format format;
  44. uint32_t fps_num;
  45. uint32_t fps_den;
  46. uint32_t width;
  47. uint32_t height;
  48. };
  49. static inline bool format_is_yuv(enum video_format format)
  50. {
  51. switch (format) {
  52. case VIDEO_FORMAT_I420:
  53. case VIDEO_FORMAT_NV12:
  54. case VIDEO_FORMAT_YVYU:
  55. case VIDEO_FORMAT_YUY2:
  56. case VIDEO_FORMAT_UYVY:
  57. return true;
  58. case VIDEO_FORMAT_NONE:
  59. case VIDEO_FORMAT_RGBA:
  60. case VIDEO_FORMAT_BGRA:
  61. case VIDEO_FORMAT_BGRX:
  62. return false;
  63. }
  64. return false;
  65. }
  66. enum video_scale_type {
  67. VIDEO_SCALE_DEFAULT,
  68. VIDEO_SCALE_POINT,
  69. VIDEO_SCALE_FAST_BILINEAR,
  70. VIDEO_SCALE_BILINEAR,
  71. VIDEO_SCALE_BICUBIC,
  72. };
  73. enum video_colorspace {
  74. VIDEO_CS_DEFAULT,
  75. VIDEO_CS_601,
  76. VIDEO_CS_709,
  77. };
  78. enum video_range_type {
  79. VIDEO_RANGE_DEFAULT,
  80. VIDEO_RANGE_PARTIAL,
  81. VIDEO_RANGE_FULL
  82. };
  83. struct video_scale_info {
  84. enum video_format format;
  85. uint32_t width;
  86. uint32_t height;
  87. enum video_range_type range;
  88. enum video_colorspace colorspace;
  89. };
  90. EXPORT enum video_format video_format_from_fourcc(uint32_t fourcc);
  91. EXPORT bool video_format_get_parameters(enum video_colorspace color_space,
  92. enum video_range_type range, float matrix[16],
  93. float min_range[3], float max_range[3]);
  94. #define VIDEO_OUTPUT_SUCCESS 0
  95. #define VIDEO_OUTPUT_INVALIDPARAM -1
  96. #define VIDEO_OUTPUT_FAIL -2
  97. EXPORT int video_output_open(video_t *video, struct video_output_info *info);
  98. EXPORT void video_output_close(video_t video);
  99. EXPORT bool video_output_connect(video_t video,
  100. const struct video_scale_info *conversion,
  101. void (*callback)(void *param, struct video_data *frame),
  102. void *param);
  103. EXPORT void video_output_disconnect(video_t video,
  104. void (*callback)(void *param, struct video_data *frame),
  105. void *param);
  106. EXPORT bool video_output_active(video_t video);
  107. EXPORT const struct video_output_info *video_output_get_info(video_t video);
  108. EXPORT void video_output_swap_frame(video_t video, struct video_data *frame);
  109. EXPORT bool video_output_wait(video_t video);
  110. EXPORT uint64_t video_output_get_frame_time(video_t video);
  111. EXPORT uint64_t video_output_get_time(video_t video);
  112. EXPORT void video_output_stop(video_t video);
  113. EXPORT enum video_format video_output_get_format(video_t video);
  114. EXPORT uint32_t video_output_get_width(video_t video);
  115. EXPORT uint32_t video_output_get_height(video_t video);
  116. EXPORT double video_output_get_frame_rate(video_t video);
  117. EXPORT uint32_t video_output_get_skipped_frames(video_t video);
  118. EXPORT uint32_t video_output_get_total_frames(video_t video);
  119. #ifdef __cplusplus
  120. }
  121. #endif