123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- #ifndef VIDEOCAP_H
- #define VIDEOCAP_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "videoutil.h"
- /**
- * video capture header file
- *
- * caution:
- * (1) the thread use these functions must call CoInitialize at first
- * (2) only tackle RGB24
- */
- /** function return values */
- #define VIDEOCAP_OK 0
- #define VIDEOCAP_ERROR -1
- /** frame size mode, we only support eight currently */
- #define VIDEOCAP_FRAME_SQCIF 0x00
- #define VIDEOCAP_FRAME_QQVGA 0x01
- #define VIDEOCAP_FRAME_QCIF 0x02
- #define VIDEOCAP_FRAME_QVGA 0x03
- #define VIDEOCAP_FRAME_CIF 0x04
- #define VIDEOCAP_FRAME_VGA 0x05
- #define VIDEOCAP_FRAME_4CIF 0x06
- #define VIDEOCAP_FRAME_SVGA 0x07
- #define VIDEOCAP_FRAME_NHD 0x08
- #define VIDEOCAP_FRAME_SXGA 0x09
- #define VIDEOCAP_FRAME_720P 0x0A
- #define VIDEOCAP_FRAME_1080P 0x0B
- //#define VIDEOCAP_CS_YUV420 0x01
- //#define VIDEOCAP_CS_RGB24 0x02
- /* width and height */
- #define VIDEOCAP_SQCIF_WIDTH 128
- #define VIDEOCAP_SQCIF_HEIGHT 96
- #define VIDEOCAP_QQVGA_WIDTH 160
- #define VIDEOCAP_QQVGA_HEIGHT 120
- #define VIDEOCAP_QCIF_WIDTH 176
- #define VIDEOCAP_QCIF_HEIGHT 144
- #define VIDEOCAP_QVGA_WIDTH 320
- #define VIDEOCAP_QVGA_HEIGHT 240
- #define VIDEOCAP_CIF_WIDTH 352
- #define VIDEOCAP_CIF_HEIGHT 288
- #define VIDEOCAP_VGA_WIDTH 640
- #define VIDEOCAP_VGA_HEIGHT 480
- #define VIDEOCAP_4CIF_WIDTH 704
- #define VIDEOCAP_4CIF_HEIGHT 576
- #define VIDEOCAP_SVGA_WIDTH 800
- #define VIDEOCAP_SVGA_HEIGHT 600
- #define VIDEOCAP_NHD_WIDTH 640
- #define VIDEOCAP_NHD_HEIGHT 360
- #define VIDEOCAP_SXGA_WIDTH 1280
- #define VIDEOCAP_SXGA_HEIGHT 960
- #define VIDEOCAP_720P_WIDTH 1280
- #define VIDEOCAP_720P_HEIGHT 720
- #define VIDEOCAP_1080P_WIDTH 1920
- #define VIDEOCAP_1080P_HEIGHT 1080
- #define VIDEOCAP_OPT_ENABLE_GRAB 0x01
- #define VIDEOCAP_OPT_EANBLE_RESIZE 0x02
- #define VIDEOCAP_OPT_ENABLE_FLIP 0x04
- #define VIDEOCAP_OPT_ENABLE_ASYNC_GRAB 0x08
- #define VIDEOCAP_OPT_HOZFLIP 0x10
- #define VIDEOCAP_MAX_MODE 12
- /* video device capability */
- typedef struct videocap_device_cap {
- int mode[VIDEOCAP_MAX_MODE]; /* VIDEOCAP_FRAME_XXX */
- int mode_cnt;
- int max_frame_interval[VIDEOCAP_MAX_MODE]; /* max frame interval for each mode */
- int min_frame_interval[VIDEOCAP_MAX_MODE]; /* min frame interval for each mode */
- }videocap_device_cap;
- typedef struct videocap_param
- {
- /* mode VIDEOCAP_FRAME_xxx */
- int cap_mode; /* capture mode setting on capture device, mainly for picture grabbing */
- int res_mode; /* resize mode for user, for example, cap_mode 640*480, res_mode is 176*144 */
- /* video frame format */
- int frame_fmt; /* VIDEO_FORMAT_I420 or VIDEO_FORMAT_RGB24 */
- float fps; /* frame per second */
- int dev_id;/* device id, return by videocap_get_device_count and videocap_get_device_name */
- /** preview window */
- HWND pre_hwnd; /* preview window handle , if null no preview */
- int pre_width; /* preview video width */
- int pre_height; /* preview video height */
- /** callbacks */
- /* called from inner thread, should not block, can be null */
- void (*on_frame)(void *user_data, video_frame *frame);
- void (*on_frame_raw)(void *user_data, video_frame *frame); // for rgb24
- /* triggered when video capture device is lost */
- void (*on_device_lost)(void *user_data);
- /* after grab */
- void (*on_grab)(void *user_data, video_frame *frame);
- void *user_data;
- int option; /* combination of VIDEOCAP_OPT_ xxx */
- }videocap_param;
- /**
- * videocap instance handler
- */
- typedef struct videocap* videocap_t;
- /**
- * get video camera devices count, return device count numbers
- */
- int videocap_get_device_count();
- /**
- * get video camera name, buf length should not be larger than 255,
- * return -1 if error
- * if buf == null, len is ignored, return value is the required buffer size
- * else return value is copy to buf, including null-terminated char
- */
- int videocap_get_device_name(int device_id, WCHAR *buf, int len);
- /**
- * get video device path string, buf length should not be larger than 255,
- * return -1 on error, if buf == null, len is ignored, return value is the required buffer size
- */
- int videocap_get_device_path(int device_id, WCHAR *buf, int len);
- /**
- * return 0 success, other value failed
- */
- int videocap_get_device_cap(int device_id, videocap_device_cap *cap);
- /**
- * create videocap instance handler
- *
- * param h: return instance handler
- *
- * return value: VIDEOCAP_OK if success, othersize VIDEOCAP_ERROR
- */
- int videocap_create(videocap_t *h ,videocap_param *param);
- /**
- * destroy videocap instance
- */
- void videocap_destroy(videocap_t h);
- /**
- * start capture, return 0 on success
- */
- int videocap_start(videocap_t h);
- /**
- * stop capture
- * return 0 on success
- */
- int videocap_stop(videocap_t h);
- /**
- * for grab picture, picture size is related with cap_mode,
- * note:
- * (1) user provide the frame buffer
- */
- int videocap_grab(videocap_t h, video_frame *frame);
- /**
- * for async grab
- */
- int videocap_async_grab(videocap_t h, video_frame *frame);
- /**
- * for adjust brightness
- */
- int videocap_adj_brightness(videocap_t h, int nValue);
- /**
- * for set auto brightness
- */
- int videocap_set_autobrightness(videocap_t h);
- /**
- * for get brightness
- */
- int videocap_get_brightness(videocap_t h,int*nValue);
- /**
- * add grab cb count
- */
- int videocap_incrment_grab_cb(videocap_t h);
- /**
- * if you not use on_frame callback(video capture is a push source), then you should use this function
- * to manually get video frame periodically
- * note:
- * (1) frame size is related with res_mode
- * (2) user provide the frame buffer
- */
- int videocap_get_frame(videocap_t h, video_frame *frame);
- /**
- * detect whether videocap_t indicated by h is in running state
- * return 0 on success
- */
- int videocap_is_running(videocap_t h, BOOL *state);
- /**
- * preview manipulate functions
- */
- int videocap_set_preview_wnd_visible(videocap_t h, BOOL visible);
- int videocap_get_preview_wnd_visible(videocap_t h, BOOL *visible);
- int videocap_set_preview_wnd_width(videocap_t h, int width);
- int videocap_set_preview_wnd_height(videocap_t h, int height);
- int videocap_get_mode_width(int mode);
- int videocap_get_mode_height(int mode);
- #ifdef __cplusplus
- }// extern "C" {
- #endif
- #endif // VIDEOCAP_H
|