5 #ifndef LIBUVC_INTERNAL_H 6 #define LIBUVC_INTERNAL_H 17 #define DW_TO_INT(p) ((p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24)) 19 #define SW_TO_SHORT(p) ((p)[0] | ((p)[1] << 8)) 21 #define SHORT_TO_SW(s, p) \ 25 #define INT_TO_DW(i, p) \ 32 #define DL_NTH(head, out, n) \ 35 LDECLTYPE(head) dl_nth_p = (head); \ 37 while (dl_nth_p && dl_nth_i > (n)) { \ 38 dl_nth_p = dl_nth_p->prev; \ 42 while (dl_nth_p && dl_nth_i < (n)) { \ 43 dl_nth_p = dl_nth_p->next; \ 52 #define UVC_DEBUG(format, ...) fprintf(stderr, "[%s:%d/%s] " format "\n", basename(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) 53 #define UVC_ENTER() fprintf(stderr, "[%s:%d] begin %s\n", basename(__FILE__), __LINE__, __FUNCTION__) 54 #define UVC_EXIT(code) fprintf(stderr, "[%s:%d] end %s (%d)\n", basename(__FILE__), __LINE__, __FUNCTION__, code) 55 #define UVC_EXIT_VOID() fprintf(stderr, "[%s:%d] end %s\n", basename(__FILE__), __LINE__, __FUNCTION__) 57 #define UVC_DEBUG(format, ...) 59 #define UVC_EXIT_VOID() 60 #define UVC_EXIT(code) 64 #define IS_INDEXABLE(arg) (sizeof(arg[0])) 65 #define IS_ARRAY(arg) (IS_INDEXABLE(arg) && (((void *) &arg) == ((void *) arg))) 66 #define ARRAYSIZE(arr) (sizeof(arr) / (IS_ARRAY(arr) ? sizeof(arr[0]) : 0)) 69 enum uvc_int_subclass_code {
70 UVC_SC_UNDEFINED = 0x00,
71 UVC_SC_VIDEOCONTROL = 0x01,
72 UVC_SC_VIDEOSTREAMING = 0x02,
73 UVC_SC_VIDEO_INTERFACE_COLLECTION = 0x03
77 enum uvc_int_proto_code {
78 UVC_PC_PROTOCOL_UNDEFINED = 0x00
82 enum uvc_vc_desc_subtype {
83 UVC_VC_DESCRIPTOR_UNDEFINED = 0x00,
85 UVC_VC_INPUT_TERMINAL = 0x02,
86 UVC_VC_OUTPUT_TERMINAL = 0x03,
87 UVC_VC_SELECTOR_UNIT = 0x04,
88 UVC_VC_PROCESSING_UNIT = 0x05,
89 UVC_VC_EXTENSION_UNIT = 0x06
93 enum uvc_ep_desc_subtype {
94 UVC_EP_UNDEFINED = 0x00,
95 UVC_EP_GENERAL = 0x01,
96 UVC_EP_ENDPOINT = 0x02,
97 UVC_EP_INTERRUPT = 0x03
101 enum uvc_vc_ctrl_selector {
102 UVC_VC_CONTROL_UNDEFINED = 0x00,
103 UVC_VC_VIDEO_POWER_MODE_CONTROL = 0x01,
104 UVC_VC_REQUEST_ERROR_CODE_CONTROL = 0x02
108 enum uvc_term_ctrl_selector {
109 UVC_TE_CONTROL_UNDEFINED = 0x00
113 enum uvc_su_ctrl_selector {
114 UVC_SU_CONTROL_UNDEFINED = 0x00,
115 UVC_SU_INPUT_SELECT_CONTROL = 0x01
119 enum uvc_xu_ctrl_selector {
120 UVC_XU_CONTROL_UNDEFINED = 0x00
124 enum uvc_vs_ctrl_selector {
125 UVC_VS_CONTROL_UNDEFINED = 0x00,
126 UVC_VS_PROBE_CONTROL = 0x01,
127 UVC_VS_COMMIT_CONTROL = 0x02,
128 UVC_VS_STILL_PROBE_CONTROL = 0x03,
129 UVC_VS_STILL_COMMIT_CONTROL = 0x04,
130 UVC_VS_STILL_IMAGE_TRIGGER_CONTROL = 0x05,
131 UVC_VS_STREAM_ERROR_CODE_CONTROL = 0x06,
132 UVC_VS_GENERATE_KEY_FRAME_CONTROL = 0x07,
133 UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL = 0x08,
134 UVC_VS_SYNC_DELAY_CONTROL = 0x09
138 enum uvc_status_type {
139 UVC_STATUS_TYPE_CONTROL = 1,
140 UVC_STATUS_TYPE_STREAMING = 2
144 #define UVC_STREAM_EOH (1 << 7) 145 #define UVC_STREAM_ERR (1 << 6) 146 #define UVC_STREAM_STI (1 << 5) 147 #define UVC_STREAM_RES (1 << 4) 148 #define UVC_STREAM_SCR (1 << 3) 149 #define UVC_STREAM_PTS (1 << 2) 150 #define UVC_STREAM_EOF (1 << 1) 151 #define UVC_STREAM_FID (1 << 0) 154 #define UVC_CONTROL_CAP_GET (1 << 0) 155 #define UVC_CONTROL_CAP_SET (1 << 1) 156 #define UVC_CONTROL_CAP_DISABLED (1 << 2) 157 #define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3) 158 #define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4) 160 struct uvc_streaming_interface;
161 struct uvc_device_info;
164 typedef struct uvc_streaming_interface {
165 struct uvc_device_info *parent;
166 struct uvc_streaming_interface *prev, *next;
168 uint8_t bInterfaceNumber;
172 uint8_t bEndpointAddress;
173 uint8_t bTerminalLink;
174 } uvc_streaming_interface_t;
177 typedef struct uvc_control_interface {
178 struct uvc_device_info *parent;
184 uint8_t bEndpointAddress;
186 uint8_t bInterfaceNumber;
187 } uvc_control_interface_t;
192 struct uvc_context *
ctx;
194 libusb_device *usb_dev;
197 typedef struct uvc_device_info {
199 struct libusb_config_descriptor *
config;
201 uvc_control_interface_t ctrl_if;
203 uvc_streaming_interface_t *stream_ifs;
217 #define LIBUVC_XFER_BUF_SIZE (64 * 1024 * 1024) 219 struct uvc_stream_handle {
220 struct uvc_device_handle *devh;
221 struct uvc_stream_handle *prev, *next;
222 struct uvc_streaming_interface *stream_if;
232 uint32_t
seq, hold_seq;
233 uint32_t pts, hold_pts;
234 uint32_t last_scr, hold_last_scr;
235 size_t got_bytes, hold_bytes;
236 uint8_t *outbuf, *holdbuf;
237 pthread_mutex_t cb_mutex;
238 pthread_cond_t cb_cond;
240 uint32_t last_polled_seq;
243 struct libusb_transfer **transfers;
244 uint8_t **transfer_bufs;
247 int num_transfer_bufs;
254 struct uvc_device_handle {
255 struct uvc_device *
dev;
256 struct uvc_device_handle *prev, *next;
258 libusb_device_handle *usb_devh;
259 struct uvc_device_info *
info;
260 struct libusb_transfer *status_xfer;
261 uint8_t status_buf[32];
264 void *status_user_ptr;
274 struct libusb_context *usb_ctx;
279 pthread_t handler_thread;
280 uint8_t kill_handler_thread;
293 #endif // !def(LIBUVC_INTERNAL_H)
uvc_error_t uvc_query_stream_ctrl(uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uint8_t probe, enum uvc_req_code req)
enum uvc_error uvc_error_t
void config(uvc::device &device, uint8_t gyro_bw, uint8_t gyro_range, uint8_t accel_bw, uint8_t accel_range, uint32_t time_seed)
void( uvc_status_callback_t)(enum uvc_status_class status_class, int event, int selector, enum uvc_status_attribute status_attribute, void *data, size_t data_len, void *user_ptr)
uvc_error_t uvc_claim_if(uvc_device_handle_t *devh, int idx)
struct uvc_stream_handle uvc_stream_handle_t
void uvc_start_handler_thread(uvc_context_t *ctx)
struct uvc_context uvc_context_t
struct uvc_device_handle uvc_device_handle_t
void( uvc_frame_callback_t)(struct uvc_frame *frame, void *user_ptr)
uvc_error_t uvc_release_if(uvc_device_handle_t *devh, int idx)