video-io.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "../util/c99defs.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* Base video output component. Use this to create an video output track. */
  20. #define MAX_VIDEO_PLANES 8
  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. };
  37. struct video_frame {
  38. const uint8_t *data[MAX_VIDEO_PLANES];
  39. uint32_t linesize[MAX_VIDEO_PLANES];
  40. uint64_t timestamp;
  41. };
  42. struct video_output_info {
  43. const char *name;
  44. enum video_format format;
  45. uint32_t fps_num;
  46. uint32_t fps_den;
  47. uint32_t width;
  48. uint32_t height;
  49. };
  50. struct video_convert_info {
  51. enum video_format format;
  52. uint32_t width;
  53. uint32_t height;
  54. };
  55. static inline bool format_is_yuv(enum video_format format)
  56. {
  57. switch (format) {
  58. case VIDEO_FORMAT_I420:
  59. case VIDEO_FORMAT_NV12:
  60. case VIDEO_FORMAT_YVYU:
  61. case VIDEO_FORMAT_YUY2:
  62. case VIDEO_FORMAT_UYVY:
  63. return true;
  64. case VIDEO_FORMAT_NONE:
  65. case VIDEO_FORMAT_RGBA:
  66. case VIDEO_FORMAT_BGRA:
  67. case VIDEO_FORMAT_BGRX:
  68. return false;
  69. }
  70. return false;
  71. }
  72. #define VIDEO_OUTPUT_SUCCESS 0
  73. #define VIDEO_OUTPUT_INVALIDPARAM -1
  74. #define VIDEO_OUTPUT_FAIL -2
  75. EXPORT int video_output_open(video_t *video, struct video_output_info *info);
  76. EXPORT void video_output_close(video_t video);
  77. EXPORT void video_output_connect(video_t video,
  78. struct video_convert_info *conversion,
  79. void (*callback)(void *param, const struct video_frame *frame),
  80. void *param);
  81. EXPORT void video_output_disconnect(video_t video,
  82. void (*callback)(void *param, const struct video_frame *frame),
  83. void *param);
  84. EXPORT const struct video_output_info *video_output_getinfo(video_t video);
  85. EXPORT void video_output_frame(video_t video, struct video_frame *frame);
  86. EXPORT bool video_output_wait(video_t video);
  87. EXPORT uint64_t video_getframetime(video_t video);
  88. EXPORT uint64_t video_gettime(video_t video);
  89. EXPORT void video_output_stop(video_t video);
  90. #ifdef __cplusplus
  91. }
  92. #endif