5 #ifndef LIBUVC_INTERNAL_H 6 #define LIBUVC_INTERNAL_H 15 #include <condition_variable> 17 #include "../third-party/libusb/libusb/libusb.h" 21 #define DW_TO_INT(p) ((p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24)) 23 #define SW_TO_SHORT(p) ((p)[0] | ((p)[1] << 8)) 25 #define QW_TO_QUAD(p) ((p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24) | \ 26 ((p)[4] << 32) |((p)[5] << 40) |((p)[6] << 48) |((p)[7] << 56)) 29 #define SHORT_TO_SW(s, p) \ 33 #define INT_TO_DW(i, p) \ 40 #define QUAD_TO_QW(i, p) \ 51 #define DL_NTH(head, out, n) \ 54 LDECLTYPE(head) dl_nth_p = (head); \ 56 while (dl_nth_p && dl_nth_i > (n)) { \ 57 dl_nth_p = dl_nth_p->prev; \ 61 while (dl_nth_p && dl_nth_i < (n)) { \ 62 dl_nth_p = dl_nth_p->next; \ 71 #define UVC_DEBUG(format, ...) fprintf(stderr, "[%s:%d/%s] " format "\n", basename(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__) 72 #define UVC_ENTER() fprintf(stderr, "[%s:%d] begin %s\n", basename(__FILE__), __LINE__, __FUNCTION__) 73 #define UVC_EXIT(code) fprintf(stderr, "[%s:%d] end %s (%d)\n", basename(__FILE__), __LINE__, __FUNCTION__, code) 74 #define UVC_EXIT_VOID() fprintf(stderr, "[%s:%d] end %s\n", basename(__FILE__), __LINE__, __FUNCTION__) 76 #define UVC_DEBUG(format, ...) 78 #define UVC_EXIT_VOID() 79 #define UVC_EXIT(code) 83 #define IS_INDEXABLE(arg) (sizeof(arg[0])) 84 #define IS_ARRAY(arg) (IS_INDEXABLE(arg) && (((void *) &arg) == ((void *) arg))) 85 #define ARRAYSIZE(arr) (sizeof(arr) / (IS_ARRAY(arr) ? sizeof(arr[0]) : 0)) 88 enum uvc_int_subclass_code {
89 UVC_SC_UNDEFINED = 0x00,
90 UVC_SC_VIDEOCONTROL = 0x01,
91 UVC_SC_VIDEOSTREAMING = 0x02,
92 UVC_SC_VIDEO_INTERFACE_COLLECTION = 0x03
96 enum uvc_int_proto_code {
97 UVC_PC_PROTOCOL_UNDEFINED = 0x00
101 enum uvc_vc_desc_subtype {
102 UVC_VC_DESCRIPTOR_UNDEFINED = 0x00,
103 UVC_VC_HEADER = 0x01,
104 UVC_VC_INPUT_TERMINAL = 0x02,
105 UVC_VC_OUTPUT_TERMINAL = 0x03,
106 UVC_VC_SELECTOR_UNIT = 0x04,
107 UVC_VC_PROCESSING_UNIT = 0x05,
108 UVC_VC_EXTENSION_UNIT = 0x06
112 enum uvc_ep_desc_subtype {
113 UVC_EP_UNDEFINED = 0x00,
114 UVC_EP_GENERAL = 0x01,
115 UVC_EP_ENDPOINT = 0x02,
116 UVC_EP_INTERRUPT = 0x03
120 enum uvc_vc_ctrl_selector {
121 UVC_VC_CONTROL_UNDEFINED = 0x00,
122 UVC_VC_VIDEO_POWER_MODE_CONTROL = 0x01,
123 UVC_VC_REQUEST_ERROR_CODE_CONTROL = 0x02
127 enum uvc_term_ctrl_selector {
128 UVC_TE_CONTROL_UNDEFINED = 0x00
132 enum uvc_su_ctrl_selector {
133 UVC_SU_CONTROL_UNDEFINED = 0x00,
134 UVC_SU_INPUT_SELECT_CONTROL = 0x01
138 enum uvc_xu_ctrl_selector {
139 UVC_XU_CONTROL_UNDEFINED = 0x00
143 enum uvc_vs_ctrl_selector {
144 UVC_VS_CONTROL_UNDEFINED = 0x00,
145 UVC_VS_PROBE_CONTROL = 0x01,
146 UVC_VS_COMMIT_CONTROL = 0x02,
147 UVC_VS_STILL_PROBE_CONTROL = 0x03,
148 UVC_VS_STILL_COMMIT_CONTROL = 0x04,
149 UVC_VS_STILL_IMAGE_TRIGGER_CONTROL = 0x05,
150 UVC_VS_STREAM_ERROR_CODE_CONTROL = 0x06,
151 UVC_VS_GENERATE_KEY_FRAME_CONTROL = 0x07,
152 UVC_VS_UPDATE_FRAME_SEGMENT_CONTROL = 0x08,
153 UVC_VS_SYNC_DELAY_CONTROL = 0x09
157 enum uvc_status_type {
158 UVC_STATUS_TYPE_CONTROL = 1,
159 UVC_STATUS_TYPE_STREAMING = 2
163 #define UVC_STREAM_EOH (1 << 7) 164 #define UVC_STREAM_ERR (1 << 6) 165 #define UVC_STREAM_STI (1 << 5) 166 #define UVC_STREAM_RES (1 << 4) 167 #define UVC_STREAM_SCR (1 << 3) 168 #define UVC_STREAM_PTS (1 << 2) 169 #define UVC_STREAM_EOF (1 << 1) 170 #define UVC_STREAM_FID (1 << 0) 173 #define UVC_CONTROL_CAP_GET (1 << 0) 174 #define UVC_CONTROL_CAP_SET (1 << 1) 175 #define UVC_CONTROL_CAP_DISABLED (1 << 2) 176 #define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3) 177 #define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4) 179 struct uvc_streaming_interface;
180 struct uvc_device_info;
183 typedef struct uvc_streaming_interface {
184 struct uvc_device_info *parent;
185 struct uvc_streaming_interface *prev, *next;
187 uint8_t bInterfaceNumber;
191 uint8_t bEndpointAddress;
192 uint8_t bTerminalLink;
193 } uvc_streaming_interface_t;
196 typedef struct uvc_control_interface {
197 struct uvc_device_info *parent;
204 uint32_t dwClockFrequency;
205 uint8_t bEndpointAddress;
207 uint8_t bInterfaceNumber;
208 } uvc_control_interface_t;
213 struct uvc_context *ctx;
215 libusb_device *usb_dev;
219 typedef struct uvc_device_info {
221 struct libusb_config_descriptor *config;
223 uvc_control_interface_t ctrl_if;
225 uvc_streaming_interface_t *stream_ifs;
238 #define LIBUVC_NUM_TRANSFER_BUFS 1 240 #define LIBUVC_XFER_BUF_SIZE ( 16 * 1024 * 1024 ) 242 struct uvc_stream_handle {
243 struct uvc_device_handle *devh;
244 struct uvc_stream_handle *prev, *next;
245 struct uvc_streaming_interface *stream_if;
255 uint32_t seq, hold_seq;
256 uint32_t pts, hold_pts;
257 uint32_t last_scr, hold_last_scr;
258 uint8_t *metadata_buf;
259 size_t metadata_bytes,metadata_size;
260 size_t got_bytes, hold_bytes;
261 uint8_t *outbuf, *holdbuf;
263 std::condition_variable cb_cond;
264 std::thread cb_thread;
265 uint32_t last_polled_seq;
268 struct libusb_transfer *transfers[LIBUVC_NUM_TRANSFER_BUFS];
269 uint8_t *transfer_bufs[LIBUVC_NUM_TRANSFER_BUFS];
278 struct uvc_device_handle {
279 struct uvc_device *dev;
280 struct uvc_device_handle *prev, *next;
282 libusb_device_handle *usb_devh;
283 struct uvc_device_info *info;
284 struct libusb_transfer *status_xfer;
285 uint8_t status_buf[32];
288 void *status_user_ptr;
291 void *button_user_ptr;
301 struct libusb_context *usb_ctx;
306 std::thread handler_thread;
307 int kill_handler_thread;
320 #endif // !def(LIBUVC_INTERNAL_H) 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)
Definition: libuvc.h:389
uvc_req_code
Definition: libuvc.h:197
void() uvc_button_callback_t(int button, int state, void *user_ptr)
Definition: libuvc.h:399
enum uvc_error uvc_error_t
void() uvc_frame_callback_t(struct uvc_frame *frame, void *user_ptr)
Definition: libuvc.h:461
struct uvc_stream_handle uvc_stream_handle_t
Definition: libuvc.h:323
enum uvc_frame_format frame_format
Definition: libuvc.h:439
struct uvc_context uvc_context_t
Definition: libuvc.h:300
struct uvc_device_handle uvc_device_handle_t
Definition: libuvc.h:315
uvc_frame_format
Definition: libuvc.h:65