forked from pupil-labs/pyuvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuvc.pxd
476 lines (395 loc) · 15.7 KB
/
cuvc.pxd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
'''
(*)~----------------------------------------------------------------------------------
Pupil - eye tracking platform
Copyright (C) 2012-2015 Pupil Labs
Distributed under the terms of the CC BY-NC-SA License.
License details are in the file license.txt, distributed as part of this software.
----------------------------------------------------------------------------------~(*)
'''
from libc.string cimport const_char
IF UNAME_SYSNAME == "Windows":
from posix.types cimport suseconds_t, time_t
cdef extern from "<winsock.h>":
cdef struct timeval:
long tv_sec
long tv_usec
cdef extern from "<time.h>":
cdef struct timespec:
time_t tv_sec
long tv_nsec
cdef extern from "libusb/libusb.h":
pass
ELSE:
from posix.time cimport timeval,timespec
cdef extern from "libusb-1.0/libusb.h":
pass
cdef extern from "Python.h":
void PyEval_InitThreads()
cdef enum ctrl_bit_mask_processing_unit:
UVC_PU_BRIGHTNESS_CONTROL = 1 << 0
UVC_PU_CONTRAST_CONTROL = 1 << 1
UVC_PU_HUE_CONTROL = 1 << 2
UVC_PU_SATURATION_CONTROL = 1 << 3
UVC_PU_SHARPNESS_CONTROL = 1 << 4
UVC_PU_GAMMA_CONTROL = 1 << 5
UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL = 1 << 6
UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL = 1 << 7
UVC_PU_BACKLIGHT_COMPENSATION_CONTROL = 1 << 8
UVC_PU_GAIN_CONTROL = 1 << 9
UVC_PU_POWER_LINE_FREQUENCY_CONTROL = 1 << 10
UVC_PU_HUE_AUTO_CONTROL = 1 << 11
UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL = 1 << 12
UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL = 1 << 13
UVC_PU_DIGITAL_MULTIPLIER_CONTROL = 1 << 14
UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL = 1 << 15
UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL = 1 << 16
UVC_PU_ANALOG_LOCK_STATUS_CONTROL = 1 << 17
cdef enum ctrl_bit_mask_input_terminal:
UVC_CT_SCANNING_MODE_CONTROL = 1 << 0
UVC_CT_AE_MODE_CONTROL = 1 << 1
UVC_CT_AE_PRIORITY_CONTROL = 1 << 2
UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL = 1 << 3
UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL = 1 << 4
UVC_CT_FOCUS_ABSOLUTE_CONTROL = 1 << 5
UVC_CT_FOCUS_RELATIVE_CONTROL = 1 << 6
UVC_CT_IRIS_ABSOLUTE_CONTROL = 1 << 7
UVC_CT_IRIS_RELATIVE_CONTROL = 1 << 8
UVC_CT_ZOOM_ABSOLUTE_CONTROL = 1 << 9
UVC_CT_ZOOM_RELATIVE_CONTROL = 1 << 10
UVC_CT_PANTILT_ABSOLUTE_CONTROL = 1 << 11
UVC_CT_PANTILT_RELATIVE_CONTROL = 1 << 12
UVC_CT_ROLL_ABSOLUTE_CONTROL = 1 << 13
UVC_CT_ROLL_RELATIVE_CONTROL = 1 << 14
UVC_CT_FOCUS_AUTO_CONTROL = 1 << 17
UVC_CT_PRIVACY_CONTROL = 1 << 18
cdef extern from "libuvc/libuvc.h":
ctypedef int uint8_t
ctypedef int uint16_t
ctypedef int int16_t
ctypedef int uint16_t
ctypedef int uint32_t
ctypedef int int32_t
ctypedef int uint64_t
cdef enum uvc_error:
UVC_SUCCESS
UVC_ERROR_IO
UVC_ERROR_INVALID_PARAM
UVC_ERROR_ACCESS
UVC_ERROR_NO_DEVICE
UVC_ERROR_NOT_FOUND
UVC_ERROR_BUSY
UVC_ERROR_TIMEOUT
UVC_ERROR_OVERFLOW
UVC_ERROR_PIPE
UVC_ERROR_INTERRUPTED
UVC_ERROR_NO_MEM
UVC_ERROR_NOT_SUPPORTED
UVC_ERROR_INVALID_DEVICE
UVC_ERROR_INVALID_MODE
UVC_ERROR_CALLBACK_EXISTS
UVC_ERROR_OTHER
ctypedef uvc_error uvc_error_t
cdef enum uvc_frame_format:
UVC_FRAME_FORMAT_UNKNOWN
UVC_FRAME_FORMAT_ANY
UVC_FRAME_FORMAT_UNCOMPRESSED
UVC_FRAME_FORMAT_COMPRESSED
UVC_FRAME_FORMAT_YUYV
UVC_FRAME_FORMAT_UYVY
UVC_FRAME_FORMAT_RGB
UVC_FRAME_FORMAT_BGR
UVC_FRAME_FORMAT_MJPEG
UVC_FRAME_FORMAT_GRAY8
UVC_FRAME_FORMAT_GRAY16,
UVC_FRAME_FORMAT_BY8,
UVC_FRAME_FORMAT_BA81,
UVC_FRAME_FORMAT_SGRBG8,
UVC_FRAME_FORMAT_SGBRG8,
UVC_FRAME_FORMAT_SRGGB8,
UVC_FRAME_FORMAT_SBGGR8,
UVC_FRAME_FORMAT_H264,
UVC_FRAME_FORMAT_COUNT
ctypedef uvc_frame_format uvc_frame_format_t
enum:
UVC_COLOR_FORMAT_UNKNOWN
UVC_COLOR_FORMAT_UNCOMPRESSED
UVC_COLOR_FORMAT_COMPRESSED
UVC_COLOR_FORMAT_YUYV
UVC_COLOR_FORMAT_UYVY
UVC_COLOR_FORMAT_RGB
UVC_COLOR_FORMAT_BGR
UVC_COLOR_FORMAT_MJPEG
UVC_COLOR_FORMAT_GRAY8
enum uvc_vs_desc_subtype:
UVC_VS_UNDEFINED = 0x00
UVC_VS_INPUT_HEADER = 0x01
UVC_VS_OUTPUT_HEADER = 0x02
UVC_VS_STILL_IMAGE_FRAME = 0x03
UVC_VS_FORMAT_UNCOMPRESSED = 0x04
UVC_VS_FRAME_UNCOMPRESSED = 0x05
UVC_VS_FORMAT_MJPEG = 0x06
UVC_VS_FRAME_MJPEG = 0x07
UVC_VS_FORMAT_MPEG2TS = 0x0a
UVC_VS_FORMAT_DV = 0x0c
UVC_VS_COLORFORMAT = 0x0d
UVC_VS_FORMAT_FRAME_BASED = 0x10
UVC_VS_FRAME_FRAME_BASED = 0x11
UVC_VS_FORMAT_STREAM_BASED = 0x12
UVC_VS_FORMAT_H264 = 0x13
UVC_VS_FRAME_H264 = 0x14
cdef struct uvc_frame_desc:
uvc_format_desc *parent
uvc_frame_desc *prev
uvc_frame_desc *next
uvc_vs_desc_subtype bDescriptorSubtype
uint8_t bFrameIndex
uint8_t bmCapabilities
uint16_t wWidth
uint16_t wHeight
uint32_t dwMinBitRate
uint32_t dwMaxBitRate
uint32_t dwMaxVideoFrameBufferSize
uint32_t dwDefaultFrameInterval
uint32_t dwMinFrameInterval
uint32_t dwMaxFrameInterval
uint32_t dwFrameIntervalStep
uint8_t bFrameIntervalType
uint32_t dwBytesPerLine
uint32_t *intervals
ctypedef uvc_frame_desc uvc_frame_desc_t
cdef struct uvc_format_desc:
#uvc_streaming_interface *parent
uvc_format_desc *prev
uvc_format_desc *next
uvc_vs_desc_subtype bDescriptorSubtype
uint8_t bFormatIndex
uint8_t bNumFrameDescriptors
#union {
#uint8_t guidFormat[16]
#uint8_t fourccFormat[4]
#}
#/** Format-specific data */
#union {
#/** BPP for uncompressed stream */
#uint8_t bBitsPerPixel
#/** Flags for JPEG stream */
#uint8_t bmFlags
#}
#/** Default {uvc_frame_desc} to choose given this format */
uint8_t bDefaultFrameIndex
uint8_t bAspectRatioX
uint8_t bAspectRatioY
uint8_t bmInterlaceFlags
uint8_t bCopyProtect
uint8_t bVariableSize
uvc_frame_desc *frame_descs
ctypedef uvc_format_desc uvc_format_desc_t
# typedef struct uvc_streaming_interface {
# struct uvc_device_info *parent;
# struct uvc_streaming_interface *prev, *next;
# /** Interface number */
# uint8_t bInterfaceNumber;
# /** Video formats that this interface provides */
# struct uvc_format_desc *format_descs;
# /** USB endpoint to use when communicating with this interface */
# uint8_t bEndpointAddress;
# uint8_t bTerminalLink;
#} uvc_streaming_interface_t;
cdef struct uvc_streaming_interface:
#parent
uvc_streaming_interface *prev
uvc_streaming_interface *next
uint8_t bInterfaceNumber
uvc_format_desc *format_descs
uint8_t bEndpointAddress
uint8_t bTerminalLink
ctypedef uvc_streaming_interface uvc_streaming_interface_t
cdef enum uvc_req_code:
UVC_RC_UNDEFINED = 0x00
UVC_SET_CUR = 0x01
UVC_GET_CUR = 0x81
UVC_GET_MIN = 0x82
UVC_GET_MAX = 0x83
UVC_GET_RES = 0x84
UVC_GET_LEN = 0x85
UVC_GET_INFO = 0x86
UVC_GET_DEF = 0x87
cdef enum uvc_device_power_mode:
pass
cdef enum uvc_ct_ctrl_selector:
UVC_CT_CONTROL_UNDEFINED
UVC_CT_SCANNING_MODE_CONTROL
UVC_CT_AE_MODE_CONTROL
UVC_CT_AE_PRIORITY_CONTROL
UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL
UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL
UVC_CT_FOCUS_ABSOLUTE_CONTROL
UVC_CT_FOCUS_RELATIVE_CONTROL
UVC_CT_FOCUS_AUTO_CONTROL
UVC_CT_IRIS_ABSOLUTE_CONTROL
UVC_CT_IRIS_RELATIVE_CONTROL
UVC_CT_ZOOM_ABSOLUTE_CONTROL
UVC_CT_ZOOM_RELATIVE_CONTROL
UVC_CT_PANTILT_ABSOLUTE_CONTROL
UVC_CT_PANTILT_RELATIVE_CONTROL
UVC_CT_ROLL_ABSOLUTE_CONTROL
UVC_CT_ROLL_RELATIVE_CONTROL
UVC_CT_PRIVACY_CONTROL
UVC_CT_FOCUS_SIMPLE_CONTROL
UVC_CT_DIGITAL_WINDOW_CONTROL
UVC_CT_REGION_OF_INTEREST_CONTROL
enum uvc_pu_ctrl_selector:
UVC_PU_CONTROL_UNDEFINED
UVC_PU_BACKLIGHT_COMPENSATION_CONTROL
UVC_PU_BRIGHTNESS_CONTROL
UVC_PU_CONTRAST_CONTROL
UVC_PU_GAIN_CONTROL
UVC_PU_POWER_LINE_FREQUENCY_CONTROL
UVC_PU_HUE_CONTROL
UVC_PU_SATURATION_CONTROL
UVC_PU_SHARPNESS_CONTROL
UVC_PU_GAMMA_CONTROL
UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL
UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL
UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL
UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL
UVC_PU_DIGITAL_MULTIPLIER_CONTROL
UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL
UVC_PU_HUE_AUTO_CONTROL
UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL
UVC_PU_ANALOG_LOCK_STATUS_CONTROL
UVC_PU_CONTRAST_AUTO_CONTROL
cdef struct libusb_context:
pass
cdef struct uvc_context:
pass
ctypedef uvc_context uvc_context_t
cdef struct uvc_device:
pass
ctypedef uvc_device uvc_device_t
cdef struct uvc_device_handle:
pass
ctypedef uvc_device_handle uvc_device_handle_t
cdef struct uvc_stream_handle:
pass
ctypedef uvc_stream_handle uvc_stream_handle_t
cdef struct uvc_input_terminal:
uvc_input_terminal *prev
uvc_input_terminal *next
uint8_t bTerminalID
uint64_t bmControls
ctypedef uvc_input_terminal uvc_input_terminal_t
cdef struct uvc_output_terminal:
pass
ctypedef uvc_output_terminal uvc_output_terminal_t
cdef struct uvc_processing_unit:
uvc_processing_unit *prev
uvc_processing_unit *next
uint8_t bUnitID
uint8_t bSourceID
uint64_t bmControls
ctypedef uvc_processing_unit uvc_processing_unit_t
cdef struct uvc_extension_unit:
uvc_extension_unit *prev
uvc_extension_unit *next
uint8_t bUnitID
uint8_t guidExtensionCode[16]
uint64_t bmControls
ctypedef uvc_extension_unit uvc_extension_unit_t
cdef enum uvc_status_class:
UVC_STATUS_CLASS_CONTROL = 0x10
UVC_STATUS_CLASS_CONTROL_CAMERA = 0x11
UVC_STATUS_CLASS_CONTROL_PROCESSING = 0x12
cdef enum uvc_status_attribute:
UVC_STATUS_ATTRIBUTE_VALUE_CHANGE = 0x00,
UVC_STATUS_ATTRIBUTE_INFO_CHANGE = 0x01,
UVC_STATUS_ATTRIBUTE_FAILURE_CHANGE = 0x02,
UVC_STATUS_ATTRIBUTE_UNKNOWN = 0xff
ctypedef void(*uvc_status_callback_t)(uvc_status_class status_class,
int event,
int selector,
uvc_status_attribute status_attribute,
void *data,
size_t data_len,
void *user_ptr)
cdef struct uvc_device_descriptor:
int idVendor
int idProduct
int bcdUVC
const_char *serialNumber
const_char *manufacturer
const_char *product
ctypedef uvc_device_descriptor uvc_device_descriptor_t
cdef struct uvc_frame:
void *data
int data_bytes
int width
int height
uvc_frame_format frame_format
int step
#/** Frame number (may skip, but is strictly monotonically increasing) */
int sequence
#/** Estimate of system time when the device started capturing the image */
timeval capture_time
uvc_device_handle_t * source
int library_owns_data
ctypedef uvc_frame uvc_frame_t
cdef struct uvc_stream_ctrl:
pass
ctypedef uvc_stream_ctrl uvc_stream_ctrl_t
#fns
uvc_error_t uvc_init(uvc_context_t **ctx, libusb_context *usb_ctx)
void uvc_exit(uvc_context_t *ctx)
uvc_error_t uvc_get_device_list(uvc_context_t *ctx, uvc_device_t ***list)
void uvc_free_device_list(uvc_device_t **list, uint8_t unref_devices)
uvc_error_t uvc_get_device_descriptor(uvc_device_t *dev,uvc_device_descriptor_t **desc)
void uvc_free_device_descriptor(uvc_device_descriptor_t *desc)
int uvc_get_bus_number(uvc_device_t *dev)
int uvc_get_device_address(uvc_device_t *dev)
uvc_error_t uvc_find_device( uvc_context_t *ctx, uvc_device_t **dev, int vid, int pid, const char *sn)
void uvc_ref_device(uvc_device_t *dev)
void uvc_unref_device(uvc_device_t *dev)
uvc_error_t uvc_open(uvc_device_t *dev,uvc_device_handle_t **devh)
void uvc_close(uvc_device_handle_t *devh)
uvc_device_t *uvc_get_device(uvc_device_handle_t *devh)
ctypedef void(*uvc_frame_callback_t)( uvc_frame *frame, void *user_ptr) # this is supposed to work wihtout a pointer?
void uvc_set_status_callback(uvc_device_handle_t *devh, uvc_status_callback_t cb,void *user_ptr)
const uvc_input_terminal_t *uvc_get_input_terminals(uvc_device_handle_t *devh)
const uvc_output_terminal_t *uvc_get_output_terminals(uvc_device_handle_t *devh)
const uvc_processing_unit_t *uvc_get_processing_units(uvc_device_handle_t *devh)
const uvc_extension_unit_t *uvc_get_extension_units(uvc_device_handle_t *devh)
uvc_error_t uvc_get_stream_ctrl_format_size( uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uvc_frame_format format, int width, int height, int fps)
uvc_format_desc_t *uvc_get_format_descs(uvc_device_handle_t* )
uvc_streaming_interface_t *uvc_get_streaming_ifs(uvc_device_handle_t *)
uvc_error_t uvc_probe_stream_ctrl( uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl)
uvc_error_t uvc_start_streaming( uvc_device_handle_t *devh, uvc_stream_ctrl_t *ctrl, uvc_frame_callback_t *cb, void *user_ptr, uint8_t flags)
void uvc_stop_streaming(uvc_device_handle_t *devh)
uvc_error_t uvc_stream_open_ctrl(uvc_device_handle_t *devh, uvc_stream_handle_t **strmh, uvc_stream_ctrl_t *ctrl)
uvc_error_t set_uvc_stream_ctrl"uvc_stream_ctrl"(uvc_stream_handle_t *strmh, uvc_stream_ctrl_t *ctrl)
uvc_error_t uvc_stream_start(uvc_stream_handle_t *strmh,uvc_frame_callback_t *cb,void *user_ptr,float bandwidth_factor, uint8_t flags)
#uvc_error_t uvc_stream_start_iso(uvc_stream_handle_t *strmh, uvc_frame_callback_t *cb, void *user_ptr)
uvc_error_t uvc_stream_get_frame( uvc_stream_handle_t *strmh, uvc_frame_t **frame, int timeout_us) nogil
uvc_error_t uvc_stream_stop(uvc_stream_handle_t *strmh)
void uvc_stream_close(uvc_stream_handle_t *strmh)
uvc_frame_t *uvc_allocate_frame(size_t data_bytes)
void uvc_free_frame(uvc_frame_t *frame)
uvc_error_t uvc_duplicate_frame(uvc_frame_t *in_frame, uvc_frame_t *out_frame)
int uvc_get_ctrl_len(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl)
int uvc_get_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len, uvc_req_code req_code)
int uvc_set_ctrl(uvc_device_handle_t *devh, uint8_t unit, uint8_t ctrl, void *data, int len)
#/** Converts an unaligned four-byte little-endian integer into an int32 */
cdef inline int32_t DW_TO_INT(uint8_t *p):
return (p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24)
#/** Converts an unaligned two-byte little-endian integer into an int16 */
cdef inline int16_t SW_TO_SHORT(uint8_t *p):
return (p)[0] | ((p)[1] << 8)
#/** Converts an int16 into an unaligned two-byte little-endian integer */
cdef inline void SHORT_TO_SW(int16_t s, uint8_t *p):
p[0] = s
p[1] = s >> 8
#/** Converts an int32 into an unaligned four-byte little-endian integer */
cdef inline void INT_TO_DW(int32_t i, uint8_t *p):
p[0] = i
p[1] = i >> 8
p[2] = i >> 16
p[3] = i >> 24