ivideocaptureinterface.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #pragma once
  2. #ifdef _WIN32
  3. #ifdef LIBVIDEOCAPTURE_EXPORTS
  4. #define LIBVIDEOCAPTURE_API __declspec(dllexport)
  5. #else
  6. #define LIBVIDEOCAPTURE_API __declspec(dllimport)
  7. #endif
  8. # elif ( defined(__GNUC__) && __GNUC__ >= 4 )
  9. #define LIBVIDEOCAPTURE_API __attribute__((visibility("default")))
  10. #else // RVC_OS_WIN
  11. #define LIBVIDEOCAPTURE_API
  12. #endif // RVC_OS_WIN
  13. #include <stdarg.h>
  14. /**
  15. * video capture header file
  16. *
  17. * caution:
  18. * (1) the thread use these functions must call CoInitialize at first
  19. * (2) only tackle RGB24
  20. */
  21. /** function return values */
  22. #define VIDEOCAP_OK 0
  23. #define VIDEOCAP_ERROR -1
  24. /** frame size mode, we only support eight currently */
  25. #define VIDEOCAP_FRAME_SQCIF 0x00
  26. #define VIDEOCAP_FRAME_QQVGA 0x01
  27. #define VIDEOCAP_FRAME_QCIF 0x02
  28. #define VIDEOCAP_FRAME_QVGA 0x03
  29. #define VIDEOCAP_FRAME_CIF 0x04
  30. #define VIDEOCAP_FRAME_VGA 0x05
  31. #define VIDEOCAP_FRAME_4CIF 0x06
  32. #define VIDEOCAP_FRAME_SVGA 0x07
  33. #define VIDEOCAP_FRAME_NHD 0x08
  34. #define VIDEOCAP_FRAME_SXGA 0x09
  35. #define VIDEOCAP_FRAME_720P 0x0A
  36. #define VIDEOCAP_FRAME_1080P 0x0B
  37. //#define VIDEOCAP_CS_YUV420 0x01
  38. //#define VIDEOCAP_CS_RGB24 0x02
  39. /* width and height */
  40. #define VIDEOCAP_SQCIF_WIDTH 128
  41. #define VIDEOCAP_SQCIF_HEIGHT 96
  42. #define VIDEOCAP_QQVGA_WIDTH 160
  43. #define VIDEOCAP_QQVGA_HEIGHT 120
  44. #define VIDEOCAP_QCIF_WIDTH 176
  45. #define VIDEOCAP_QCIF_HEIGHT 144
  46. #define VIDEOCAP_QVGA_WIDTH 320
  47. #define VIDEOCAP_QVGA_HEIGHT 240
  48. #define VIDEOCAP_CIF_WIDTH 352
  49. #define VIDEOCAP_CIF_HEIGHT 288
  50. #define VIDEOCAP_VGA_WIDTH 640
  51. #define VIDEOCAP_VGA_HEIGHT 480
  52. #define VIDEOCAP_4CIF_WIDTH 704
  53. #define VIDEOCAP_4CIF_HEIGHT 576
  54. #define VIDEOCAP_SVGA_WIDTH 800
  55. #define VIDEOCAP_SVGA_HEIGHT 600
  56. #define VIDEOCAP_NHD_WIDTH 640
  57. #define VIDEOCAP_NHD_HEIGHT 360
  58. #define VIDEOCAP_SXGA_WIDTH 1280
  59. #define VIDEOCAP_SXGA_HEIGHT 960
  60. #define VIDEOCAP_720P_WIDTH 1280
  61. #define VIDEOCAP_720P_HEIGHT 720
  62. #define VIDEOCAP_1080P_WIDTH 1920
  63. #define VIDEOCAP_1080P_HEIGHT 1080
  64. #define VIDEOCAP_OPT_ENABLE_GRAB 0x01
  65. #define VIDEOCAP_OPT_EANBLE_RESIZE 0x02
  66. #define VIDEOCAP_OPT_ENABLE_FLIP 0x04
  67. #define VIDEOCAP_OPT_ENABLE_ASYNC_GRAB 0x08
  68. #define VIDEOCAP_OPT_HOZFLIP 0x10
  69. #define VIDEOCAP_MAX_MODE 12
  70. /* video device capability */
  71. typedef struct videocap_device_cap_s {
  72. int mode[VIDEOCAP_MAX_MODE]; /* VIDEOCAP_FRAME_XXX */
  73. int mode_cnt;
  74. int max_frame_interval[VIDEOCAP_MAX_MODE]; /* max frame interval for each mode */
  75. int min_frame_interval[VIDEOCAP_MAX_MODE]; /* min frame interval for each mode */
  76. }videocap_device_cap_t;
  77. struct video_frame;
  78. typedef struct videocap_param_s
  79. {
  80. /* mode VIDEOCAP_FRAME_xxx */
  81. int cap_mode; /* capture mode setting on capture device, mainly for picture grabbing */
  82. int res_mode; /* resize mode for user, for example, cap_mode 640*480, res_mode is 176*144 */
  83. /* video frame format */
  84. int frame_fmt; /* VIDEO_FORMAT_I420 or VIDEO_FORMAT_RGB24 */
  85. float fps; /* frame per second */
  86. int dev_id;/* device id, return by videocap_get_device_count and videocap_get_device_name */
  87. /** preview window */
  88. void* pre_hwnd; /* preview window handle , if null no preview */
  89. int pre_width; /* preview video width */
  90. int pre_height; /* preview video height */
  91. /** callbacks */
  92. /* called from inner thread, should not block, can be null */
  93. void (*on_frame)(void* user_data, video_frame* frame);
  94. void (*on_frame_raw)(void* user_data, video_frame* frame); // for rgb24
  95. int (*on_frame_i420)(void* user_data, video_frame* frame); // for i420
  96. /* triggered when video capture device is lost */
  97. void (*on_device_lost)(void* user_data);
  98. /* after grab */
  99. void (*on_grab)(void* user_data, video_frame* frame);
  100. void* user_data;
  101. int option; /* combination of VIDEOCAP_OPT_ xxx */
  102. int irotate;
  103. }videocap_param_t;
  104. typedef struct videocap_callback_s {
  105. void (*debug)(void* user_data, const char* fmt, va_list arg);
  106. void (*oncapturefailed)();
  107. void (*onvideocapexcption)();
  108. #ifdef _WIN32
  109. #else
  110. void (*logevent)(int itype, int idevid, const char* strmessage);
  111. #endif
  112. void* user_data;
  113. }videocap_callback_t;
  114. class IVideoCapture
  115. {
  116. public:
  117. virtual int VideoCaptureSetParam(videocap_param_t* param) = 0;
  118. virtual int StartVideoCapture() = 0;
  119. virtual int StopVideoCapture() = 0;
  120. virtual void VideoCaptureDestroy() = 0;
  121. virtual int GetCamBrightness(int* ibright, bool bRawRange) = 0;
  122. virtual int SetCamBrightness(int ibright, bool bRawRange) = 0;
  123. virtual int SetCamAutoBrightness() = 0;
  124. virtual bool GetCamRawBrightnessRange(int* imin, int* imax) = 0;
  125. };
  126. extern "C" LIBVIDEOCAPTURE_API IVideoCapture* CreateVideoCaptureObj(videocap_callback_t* pCallback);
  127. extern "C" LIBVIDEOCAPTURE_API void DestroyVideoCaptureObj(IVideoCapture* pIVideoCapture);