videocap.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef VIDEOCAP_H
  2. #define VIDEOCAP_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "videoutil.h"
  7. /**
  8. * video capture header file
  9. *
  10. * caution:
  11. * (1) the thread use these functions must call CoInitialize at first
  12. * (2) only tackle RGB24
  13. */
  14. /** function return values */
  15. #define VIDEOCAP_OK 0
  16. #define VIDEOCAP_ERROR -1
  17. /** frame size mode, we only support eight currently */
  18. #define VIDEOCAP_FRAME_SQCIF 0x00
  19. #define VIDEOCAP_FRAME_QQVGA 0x01
  20. #define VIDEOCAP_FRAME_QCIF 0x02
  21. #define VIDEOCAP_FRAME_QVGA 0x03
  22. #define VIDEOCAP_FRAME_CIF 0x04
  23. #define VIDEOCAP_FRAME_VGA 0x05
  24. #define VIDEOCAP_FRAME_4CIF 0x06
  25. #define VIDEOCAP_FRAME_SVGA 0x07
  26. #define VIDEOCAP_FRAME_NHD 0x08
  27. #define VIDEOCAP_FRAME_SXGA 0x09
  28. #define VIDEOCAP_FRAME_720P 0x0A
  29. #define VIDEOCAP_FRAME_1080P 0x0B
  30. //#define VIDEOCAP_CS_YUV420 0x01
  31. //#define VIDEOCAP_CS_RGB24 0x02
  32. /* width and height */
  33. #define VIDEOCAP_SQCIF_WIDTH 128
  34. #define VIDEOCAP_SQCIF_HEIGHT 96
  35. #define VIDEOCAP_QQVGA_WIDTH 160
  36. #define VIDEOCAP_QQVGA_HEIGHT 120
  37. #define VIDEOCAP_QCIF_WIDTH 176
  38. #define VIDEOCAP_QCIF_HEIGHT 144
  39. #define VIDEOCAP_QVGA_WIDTH 320
  40. #define VIDEOCAP_QVGA_HEIGHT 240
  41. #define VIDEOCAP_CIF_WIDTH 352
  42. #define VIDEOCAP_CIF_HEIGHT 288
  43. #define VIDEOCAP_VGA_WIDTH 640
  44. #define VIDEOCAP_VGA_HEIGHT 480
  45. #define VIDEOCAP_4CIF_WIDTH 704
  46. #define VIDEOCAP_4CIF_HEIGHT 576
  47. #define VIDEOCAP_SVGA_WIDTH 800
  48. #define VIDEOCAP_SVGA_HEIGHT 600
  49. #define VIDEOCAP_NHD_WIDTH 640
  50. #define VIDEOCAP_NHD_HEIGHT 360
  51. #define VIDEOCAP_SXGA_WIDTH 1280
  52. #define VIDEOCAP_SXGA_HEIGHT 960
  53. #define VIDEOCAP_720P_WIDTH 1280
  54. #define VIDEOCAP_720P_HEIGHT 720
  55. #define VIDEOCAP_1080P_WIDTH 1920
  56. #define VIDEOCAP_1080P_HEIGHT 1080
  57. #define VIDEOCAP_OPT_ENABLE_GRAB 0x01
  58. #define VIDEOCAP_OPT_EANBLE_RESIZE 0x02
  59. #define VIDEOCAP_OPT_ENABLE_FLIP 0x04
  60. #define VIDEOCAP_OPT_ENABLE_ASYNC_GRAB 0x08
  61. #define VIDEOCAP_OPT_HOZFLIP 0x10
  62. #define VIDEOCAP_MAX_MODE 12
  63. /* video device capability */
  64. typedef struct videocap_device_cap {
  65. int mode[VIDEOCAP_MAX_MODE]; /* VIDEOCAP_FRAME_XXX */
  66. int mode_cnt;
  67. int max_frame_interval[VIDEOCAP_MAX_MODE]; /* max frame interval for each mode */
  68. int min_frame_interval[VIDEOCAP_MAX_MODE]; /* min frame interval for each mode */
  69. }videocap_device_cap;
  70. typedef struct videocap_param
  71. {
  72. /* mode VIDEOCAP_FRAME_xxx */
  73. int cap_mode; /* capture mode setting on capture device, mainly for picture grabbing */
  74. int res_mode; /* resize mode for user, for example, cap_mode 640*480, res_mode is 176*144 */
  75. /* video frame format */
  76. int frame_fmt; /* VIDEO_FORMAT_I420 or VIDEO_FORMAT_RGB24 */
  77. float fps; /* frame per second */
  78. int dev_id;/* device id, return by videocap_get_device_count and videocap_get_device_name */
  79. /** preview window */
  80. HWND pre_hwnd; /* preview window handle , if null no preview */
  81. int pre_width; /* preview video width */
  82. int pre_height; /* preview video height */
  83. /** callbacks */
  84. /* called from inner thread, should not block, can be null */
  85. void (*on_frame)(void *user_data, video_frame *frame);
  86. void (*on_frame_raw)(void *user_data, video_frame *frame); // for rgb24
  87. /* triggered when video capture device is lost */
  88. void (*on_device_lost)(void *user_data);
  89. /* after grab */
  90. void (*on_grab)(void *user_data, video_frame *frame);
  91. void *user_data;
  92. int option; /* combination of VIDEOCAP_OPT_ xxx */
  93. }videocap_param;
  94. /**
  95. * videocap instance handler
  96. */
  97. typedef struct videocap* videocap_t;
  98. /**
  99. * get video camera devices count, return device count numbers
  100. */
  101. int videocap_get_device_count();
  102. /**
  103. * get video camera name, buf length should not be larger than 255,
  104. * return -1 if error
  105. * if buf == null, len is ignored, return value is the required buffer size
  106. * else return value is copy to buf, including null-terminated char
  107. */
  108. int videocap_get_device_name(int device_id, WCHAR *buf, int len);
  109. /**
  110. * get video device path string, buf length should not be larger than 255,
  111. * return -1 on error, if buf == null, len is ignored, return value is the required buffer size
  112. */
  113. int videocap_get_device_path(int device_id, WCHAR *buf, int len);
  114. /**
  115. * return 0 success, other value failed
  116. */
  117. int videocap_get_device_cap(int device_id, videocap_device_cap *cap);
  118. /**
  119. * create videocap instance handler
  120. *
  121. * param h: return instance handler
  122. *
  123. * return value: VIDEOCAP_OK if success, othersize VIDEOCAP_ERROR
  124. */
  125. int videocap_create(videocap_t *h ,videocap_param *param);
  126. /**
  127. * destroy videocap instance
  128. */
  129. void videocap_destroy(videocap_t h);
  130. /**
  131. * start capture, return 0 on success
  132. */
  133. int videocap_start(videocap_t h);
  134. /**
  135. * stop capture
  136. * return 0 on success
  137. */
  138. int videocap_stop(videocap_t h);
  139. /**
  140. * for grab picture, picture size is related with cap_mode,
  141. * note:
  142. * (1) user provide the frame buffer
  143. */
  144. int videocap_grab(videocap_t h, video_frame *frame);
  145. /**
  146. * for async grab
  147. */
  148. int videocap_async_grab(videocap_t h, video_frame *frame);
  149. /**
  150. * for adjust brightness
  151. */
  152. int videocap_adj_brightness(videocap_t h, int nValue);
  153. /**
  154. * for set auto brightness
  155. */
  156. int videocap_set_autobrightness(videocap_t h);
  157. /**
  158. * for get brightness
  159. */
  160. int videocap_get_brightness(videocap_t h,int*nValue);
  161. /**
  162. * add grab cb count
  163. */
  164. int videocap_incrment_grab_cb(videocap_t h);
  165. /**
  166. * if you not use on_frame callback(video capture is a push source), then you should use this function
  167. * to manually get video frame periodically
  168. * note:
  169. * (1) frame size is related with res_mode
  170. * (2) user provide the frame buffer
  171. */
  172. int videocap_get_frame(videocap_t h, video_frame *frame);
  173. /**
  174. * detect whether videocap_t indicated by h is in running state
  175. * return 0 on success
  176. */
  177. int videocap_is_running(videocap_t h, BOOL *state);
  178. /**
  179. * preview manipulate functions
  180. */
  181. int videocap_set_preview_wnd_visible(videocap_t h, BOOL visible);
  182. int videocap_get_preview_wnd_visible(videocap_t h, BOOL *visible);
  183. int videocap_set_preview_wnd_width(videocap_t h, int width);
  184. int videocap_set_preview_wnd_height(videocap_t h, int height);
  185. int videocap_get_mode_width(int mode);
  186. int videocap_get_mode_height(int mode);
  187. #ifdef __cplusplus
  188. }// extern "C" {
  189. #endif
  190. #endif // VIDEOCAP_H