libuvcc  0.41a
simple uvc implementation for os x
 All Data Structures Functions Variables Typedefs Enumerations Groups Pages
libuvcc-defs.h
1 /* warning: mixed naming conventions! */
2 #ifndef __LIBUVCC_DEFS_H__
3 #define __LIBUVCC_DEFS_H__
4 
5 #include <IOKit/usb/USB.h>
6 
15 #define USB_BASE_CLASS_DEV 0x00
16 #define USB_BASE_CLASS_COM 0x02
17 #define USB_BASE_CLASS_HID 0x03
18 #define USB_BASE_CLASS_PHYS 0x05
19 #define USB_BASE_CLASS_IMG 0x06
20 #define USB_BASE_CLASS_CDC 0x0a
21 #define USB_BASE_CLASS_VID 0x0e
22 #define USB_BASE_CLASS_MISC 0xef
23 #define USB_BASE_CLASS_APP 0xfe
24 #define USB_BASE_CLASS_VEND 0xff
25 
29 #define USB_SUB_CLASS_VID_CTRL 0x01
30 
33 #define USB_RT_TD_SET 0x00
34 #define USB_RT_TD_GET 0x80
35 #define USB_RT_TY_STD (0x00 << 5)
36 #define USB_RT_TY_CLASS (0x01 << 5)
37 #define USB_RT_TY_VENDOR (0x02 << 5)
38 #define USB_RT_TY_RESERVED (0x03 << 5)
39 #define USB_RT_RE_DEVICE 0x00
40 #define USB_RT_RE_IFACE 0x01
41 #define USB_RT_RE_ENDPOINT 0x02
42 #define USB_RT_RE_OTHER 0x03
47 #define USB_REQ_GET_STATUS 0x00
48 #define USB_REQ_CLEAR_FEAT 0x01
49 /* 0x02 reserved for future use */
50 #define USB_REQ_SET_FEAT 0x03
51 /* 0x04 reserved for future use */
52 #define USB_REQ_SET_ADDR 0x05
53 #define USB_REQ_GET_DESC 0x06
54 #define USB_REQ_SET_DESC 0x07
55 #define USB_REQ_GET_CONF 0x08
56 #define USB_REQ_SET_CONF 0x09
57 #define USB_REQ_GET_IFACE 0x0a
58 #define USB_REQ_SET_IFACE 0x0b
59 #define USB_REQ_SYNCH_FRAME 0x0c
60 
64 #define USB_DESC_DEV 0x01
65 #define USB_DESC_CONFIG 0x02
66 #define USB_DESC_STRING 0x03
67 #define USB_DESC_IFACE 0x04
68 #define USB_DESC_EP 0x05
69 #define USB_DESC_DEV_QUALIFIER 0x06
70 #define USB_DESC_OTHER_SPEED_CONF 0x07
71 #define USB_DESC_IFACE_POWER 0x08
72 
76 #define UVC_DESC_UNDEFINED 0x20
77 #define UVC_DESC_DEV 0x21
78 #define UVC_DESC_CONF 0x22
79 #define UVC_DESC_STRING 0x23
80 #define UVC_DESC_IFACE 0x24
81 #define UVC_DESC_EP 0x25
82 #define UVC_DESC_IFACE_UNDEFINED 0x00
83 #define UVC_DESC_IFACE_HEADER 0x01
84 #define UVC_DESC_IFACE_INPUT_TERMINAL 0x02
85 #define UVC_DESC_IFACE_OUTPUT_TERMINAL 0x03
86 #define UVC_DESC_IFACE_SELECTOR_UNIT 0x04
87 #define UVC_DESC_IFACE_PROCESSING_UNIT 0x05
88 #define UVC_DESC_IFACE_EXTENSION_UNIT 0x06
89 
93 #define UVC_ITT_VENDOR_SPEC 0x0200
94 #define UVC_ITT_CAMERA 0x0201
95 #define UVC_ITT_MEDIA_TRANSPORT_INPUT 0x0202
96 
100 #define UVC_RC_UNDEFINED 0x00
101 #define UVC_SET_CUR 0x01
102 #define UVC_GET_CUR 0x81
103 #define UVC_GET_MIN 0x82
104 #define UVC_GET_MAX 0x83
105 #define UVC_GET_RES 0x84
106 #define UVC_GET_LEN 0x85
107 #define UVC_GET_INFO 0x86
108 #define UVC_GET_DEF 0x87
109 
112 /* this should be enumed! */
113 #define UVC_VC_CONTROL_UNDEFINED 0x00
114 #define UVC_VC_VIDEO_POWER_MODE_CONTROL 0x01
115 #define UVC_VC_REQUEST_ERROR_CODE_CONTROL 0x02
116 #define UVC_CT_CONTROL_UNDEFINED 0x00
117 #define UVC_CT_SCANNING_MODE_CONTROL (0x01 << 8)
118 #define UVC_CT_AE_MODE_CONTROL (0x02 << 8)
119 #define UVC_CT_AE_PRIORITY_CONTROL (0x03 << 8)
120 #define UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL (0x04 << 8)
121 #define UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL (0x05 << 8)
122 #define UVC_CT_FOCUS_ABSOLUTE_CONTROL (0x06 << 8)
123 #define UVC_CT_FOCUS_RELATIVE_CONTROL (0x07 << 8)
124 #define UVC_CT_FOCUS_AUTO_CONTROL (0x08 << 8)
125 #define UVC_CT_IRIS_ABSOLUTE_CONTROL (0x09 << 8)
126 #define UVC_CT_IRIS_RELATIVE_CONTROL (0x0a << 8)
127 #define UVC_CT_ZOOM_ABSOLUTE_CONTROL (0x0b << 8)
128 #define UVC_CT_ZOOM_RELATIVE_CONTROL (0x0c << 8)
129 #define UVC_CT_PANTILT_ABSOLUTE_CONTROL (0x0d << 8)
130 #define UVC_CT_PANTILT_RELATIVE_CONTROL (0x0e << 8)
131 #define UVC_CT_ROLL_ABSOLUTE_CONTROL (0x0f << 8)
132 #define UVC_CT_ROLL_RELATIVE_CONTROL (0x10 << 8)
133 #define UVC_CT_PRIVACY_CONTROL (0x11 << 8)
134 #define UVC_PU_CONTROL_UNDEFINED (0x00 << 8)
135 #define UVC_PU_BACKLIGHT_COMPENSATION_CONTROL (0x01 << 8)
136 #define UVC_PU_BRIGHTNESS_CONTROL (0x02 << 8)
137 #define UVC_PU_CONTRAST_CONTROL (0x03 << 8)
138 #define UVC_PU_GAIN_CONTROL (0x04 << 8)
139 #define UVC_PU_POWER_LINE_FREQUENCY_CONTROL (0x05 << 8)
140 #define UVC_PU_HUE_CONTROL (0x06 << 8)
141 #define UVC_PU_SATURATION_CONTROL (0x07 << 8)
142 #define UVC_PU_SHARPNESS_CONTROL (0x08 << 8)
143 #define UVC_PU_GAMMA_CONTROL (0x09 << 8)
144 #define UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL (0x0a << 8)
145 #define UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL (0x0b << 8)
146 #define UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL (0x0c << 8)
147 #define UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL (0x0d << 8)
148 #define UVC_PU_DIGITAL_MULTIPLIER_CONTROL (0x0e << 8)
149 #define UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL (0x0f << 8)
150 #define UVC_PU_HUE_AUTO_CONTROL (0x10 << 8)
151 #define UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL (0x11 << 8)
152 #define UVC_PU_ANALOG_LOCK_STATUS_CONTROL (0x12 << 8)
153 
159 #define UVCC_BMRT_SET USB_RT_TD_SET | USB_RT_TY_CLASS | USB_RT_RE_IFACE
160 #define UVCC_BMRT_GET USB_RT_TD_GET | USB_RT_TY_CLASS | USB_RT_RE_IFACE
161 
166 #define UVCC_INFO_GET_SUPPORT (int8_t)0x01
167 #define UVCC_INFO_SET_SUPPORT (int8_t)0x02
168 #define UVCC_INFO_DISABLED_BY_AUTOCTRL (int8_t)0x04
169 #define UVCC_INFO_ASYNC_CTRL (int8_t)0x08
170 
175 #define UVCC_AUTO_OFF (uint8_t)0x00
176 #define UVCC_AUTO_ON (uint8_t)0x01
177 
181 #define UVCC_SCANNING_MODE_INTERLACED (uint8_t)0x00
182 #define UVCC_SCANNING_MODE_PROGRESSIVE (uint8_t)0x01
183 
187 #define UVCC_EXPOSURE_MODE_MANUAL (int8_t)0x01
188 #define UVCC_EXPOSURE_MODE_AUTO (int8_t)0x02
189 #define UVCC_EXPOSURE_MODE_SHUTTER_PRIO (int8_t)0x04
190 #define UVCC_EXPOSURE_MODE_APERTURE_PRIO (int8_t)0x08
191 
195 #define UVCC_EXPOSURE_PRIO_CTRL_CONSTANT (int8_t)0x00
196 #define UVCC_EXPOSURE_PRIO_CTRL_DYNAMIC (int8_t)0x01
197 
201 #define UVCC_POWER_LINE_FREQUENCE_DISABLED (int8_t)0x00
202 #define UVCC_POWER_LINE_FREQUENCY_50HZ (int8_t)0x01
203 #define UVCC_POWER_LINE_FREQUENCY_60HZ (int8_t)0x02
204 
212 typedef IOUSBDeviceInterface320 usbDevIf;
213 typedef IOUSBInterfaceInterface197 usbIfIf;
214 
219  UVCC_DEV_SPEED_1_5_MBPS = kUSBDeviceSpeedLow,
220  UVCC_DEV_SPEED_12_MBPS = kUSBDeviceSpeedFull,
221  UVCC_DEV_SPEED_480_MBPS = kUSBDeviceSpeedHigh,
222  UVCC_DEV_SPEED_5000_MBPS = kUSBDeviceSpeedSuper,
223  UVCC_DEV_SPEED_USB_1A = UVCC_DEV_SPEED_1_5_MBPS,
224  UVCC_DEV_SPEED_USB_1B = UVCC_DEV_SPEED_12_MBPS,
225  UVCC_DEV_SPEED_USB_2 = UVCC_DEV_SPEED_480_MBPS,
226  UVCC_DEV_SPEED_USB_3 = UVCC_DEV_SPEED_5000_MBPS
227 };
228 
233 {
234  UVCC_ERR_EU_INDEX_OUT_OF_RANGE = -11,
235  UVCC_ERR_EU_REQ_INDEX_OUT_OF_RANGE,
236  UVCC_ERR_CREATE_MASTER_PORT_FAIL,
237  UVCC_ERR_CAM_IS_NULL,
238  UVCC_ERR_INTERFACE_IS_NULL,
239  UVCC_ERR_CTRL_REQUEST_IS_NULL,
240  UVCC_ERR_UNKNOWN_REQUEST,
241  UVCC_ERR_UNKNOWN_UVC_REQUEST,
242  UVCC_ERR_USB_OPEN_FAILED,
243  UVCC_ERR_CTRL_REQUEST_UNSUPPORTED_OR_MALFORMATTED,
244  UVCC_ERR_CTRL_REQUEST_FAILED,
245  UVCC_ERR_NO_ERROR = 0
246 };
247 
252 {
253  UVCC_WARN_NO_WARNING,
254  UVCC_WARN_LOGGING_TO_STDERR
255 };
256 
261 { /* note that these are just indicies in predef_reqs so don't change the order ! */
262  UVCC_REQ_SCANNING_MODE,
263  UVCC_REQ_EXPOSURE_AUTOMODE,
264  UVCC_REQ_EXPOSURE_AUTOPRIO,
265  UVCC_REQ_EXPOSURE_ABS,
266  UVCC_REQ_EXPOSURE_REL,
267  UVCC_REQ_FOCUS_AUTO,
268  UVCC_REQ_FOCUS_ABS,
269  UVCC_REQ_FOCUS_REL,
270  UVCC_REQ_IRIS_ABS,
271  UVCC_REQ_IRIS_REL,
272  UVCC_REQ_BACKLIGHT_COMPENSATION_ABS,
273  UVCC_REQ_BRIGHTNESS_ABS,
274  UVCC_REQ_CONTRAST_ABS,
275  UVCC_REQ_GAIN_ABS,
276  UVCC_REQ_POWER_LINE_FREQ,
277  UVCC_REQ_HUE_AUTO,
278  UVCC_REQ_HUE_ABS,
279  UVCC_REQ_SATURATION_ABS,
280  UVCC_REQ_SHARPNESS_ABS,
281  UVCC_REQ_GAMMA_ABS,
282  UVCC_REQ_WB_TEMPERATURE_AUTO,
283  UVCC_REQ_WB_TEMPERATURE_ABS,
284  UVCC_REQ_WB_COMPONENT_AUTO,
285  UVCC_REQ_WB_COMPONENT_ABS,
286  __UVCC_REQ_OUT_OF_RANGE
287 };
288 
293 {
294  UVCC_CTSM_UNDEFINED = 0x00000,
295  UVCC_CTSM_SCANNING_MODE = 0x00001,
296  UVCC_CTSM_ET_AUTOMODE = 0x00002,
297  UVCC_CTSM_ET_AUTOPRIO = 0x00004,
298  UVCC_CTSM_ET_ABSOLUTE = 0x00008,
299  UVCC_CTSM_ET_RELATIVE = 0x00010,
300  UVCC_CTSM_FOCUS_ABSOLUTE = 0x00020,
301  UVCC_CTSM_FOCUS_RELATIVE = 0x00040,
302  UVCC_CTSM_IRIS_ABSOLUTE = 0x00080,
303  UVCC_CTSM_IRIS_RELATIVE = 0x00100,
304  UVCC_CTSM_ZOOM_ABSOLUTE = 0x00200,
305  UVCC_CTSM_ZOOM_RELATIVE = 0x00400,
306  UVCC_CTSM_PANTILT_ABSOLUTE = 0x00800,
307  UVCC_CTSM_PANTILT_RELATIVE = 0x01000,
308  UVCC_CTSM_ROLL_ABSOLUTE = 0x02000,
309  UVCC_CTSM_ROLL_RELATIVE = 0x04000,
310  UVCC_CTSM_RESERVED_A = 0x08000,
311  UVCC_CTSM_RESERVED_B = 0x10000,
312  UVCC_CTSM_FOCUS_AUTO = 0x20000,
313  UVCC_CTSM_PRIVACY = 0x40000
314 };
315 
320 {
321  UVCC_PUSM_UNDEFINED = 0x00000,
322  UVCC_PUSM_BRIGHTNESS = 0x00001,
323  UVCC_PUSM_CONTRAST = 0x00002,
324  UVCC_PUSM_HUE = 0x00004,
325  UVCC_PUSM_SATURATION = 0x00008,
326  UVCC_PUSM_SHARPNESS = 0x00010,
327  UVCC_PUSM_GAMMA = 0x00020,
328  UVCC_PUSM_WB_TEMPERATURE = 0x00040,
329  UVCC_PUSM_WB_COMPONENT = 0x00080,
330  UVCC_PUSM_BACKLIGHT_COMPENSATION = 0x00100,
331  UVCC_PUSM_GAIN = 0x00200,
332  UVCC_PUSM_POWER_LINE_FREQUENCY = 0x00400,
333  UVCC_PUSM_HUE_AUTO = 0x00800,
334  UVCC_PUSM_WB_TEMPERATURE_AUTO = 0x01000,
335  UVCC_PUSM_WB_COMPONENT_AUTO = 0x02000,
336  UVCC_PUSM_DIGITAL_MULTIPLIER = 0x04000,
337  UVCC_PUSM_DIGITAL_MULTIPLIER_LIMIT = 0x08000,
338  UVCC_PUSM_ANALOG_VIDEO_STANDARD = 0x10000,
339  UVCC_PUSM_ANALOG_LOCK_STATUS = 0x20000
340 };
341 
342 /* uvc iface descriptors (the only ones i care about), first three fields are
343  always the same.. crazy sizes and casting means packing is needed */
345 #pragma pack(1)
347 {
348  uint8_t bLength;
349  uint8_t bDescriptorType;
350  uint8_t bDescriptorSubType;
351  uint16_t bcdUVC;
352  uint16_t wTotalLength;
353  uint32_t dwClockFrequency;
354  uint8_t bInCollection;
355  uint8_t baInterfaceNr[1];
356 };
357 #pragma options align = reset
358 
359 #pragma pack(1)
360 struct uvcITDesc
361 {
362  uint8_t bLength;
363  uint8_t bDescriptorType;
364  uint8_t bDescriptorSubType;
365  uint8_t bTerminalID;
366  uint16_t wTerminalType;
367  uint8_t bAssocTerminal;
368  uint8_t bSourceID;
369  uint8_t iTerminal;
370 };
371 #pragma options align = reset
372 
373 #pragma pack(1)
374 struct uvcCTDesc
375 {
376  uint8_t bLength;
377  uint8_t bDescriptorType;
378  uint8_t bDescriptorSubType;
379  uint8_t bTerminalID;
380  uint16_t wTerminalType;
381  uint8_t bAssocTerminal;
382  uint8_t iTerminal;
383  uint16_t wObjectiveFocalLengthMin;
384  uint16_t wObjectiveFocalLengthMax;
385  uint16_t wOcularFocalLength;
386  uint8_t bControlSize;
387  uint8_t bmControls[1];
388 };
389 #pragma options align = reset
390 
391 #pragma pack(1)
392 struct uvcPUDesc
393 {
394  uint8_t bLength;
395  uint8_t bDescriptorType;
396  uint8_t bDescriptorSubType;
397  uint8_t bUnitID;
398  uint8_t bSourceID;
399  uint16_t wMaxMultiplier;
400  uint8_t bControlSize;
401  uint8_t bmControls[1];
402 };
403 #pragma options align = reset
404 
405 #pragma pack(1)
407 {
408  uint8_t bLength;
409  uint8_t bDescriptorType;
410  uint8_t bDescriptorSubType;
411  uint8_t bUnitID;
412  uint8_t guidFormat[16];
413  uint8_t bNumControls;
414  uint8_t bNrInPins;
415  uint8_t baSourceID[1];
416 };
417 #pragma options align = reset
418 
419 #pragma pack(1)
421 {
422  uint8_t bControlSize;
423  uint8_t bmControls[1];
424 };
425 #pragma options align = reset
426 
427 #pragma pack(1)
429 {
430  uint8_t iExtension;
431 };
432 #pragma options align = reset
433 
437 {
438  uint16_t idVendor;
439  uint16_t idProduct;
440 };
441 
446 { /* "soft" info */
447  uint8_t bDevClass;
448  uint8_t bDevSubClass;
449  uint8_t bDevProtocol;
450  uint8_t bDevSpeed;
451  /* "hard" info */
452  uint16_t hwIdVendor;
453  uint16_t hwIdProduct;
454  uint16_t hwRelNo;
455  uint8_t bNumConfs;
456  /* string indicies */
457  uint8_t bIManufacturer;
458  uint8_t bIProduct;
459  uint8_t bISerialNumber;
460 };
461 
465 struct uvccCam
466 {
467  uint32_t idLocation;
468  /* mId is actually just a pointer into the devDesc */
469  struct uvccModelID *mID;
470 // IOUSBDeviceDescriptor devDesc;
471  usbDevIf **devIf;
472  struct uvccDevDesc devDesc;
473  usbIfIf **ctrlIf;
474  uint8_t ifNo, ctIndex, puIndex;
475  uint8_t nEUs;
476  uint8_t *euIndicies;
477  uint8_t **euGUIDs;
478  uint8_t *nEUReqs;
479  uint16_t **euWValues;
481  CFStringRef regName;
482  /* info when fetched.. should be updated by listener. */
483  uint32_t portInfo;
484  uint32_t ctSupportMap;
485  uint32_t puSupportMap;
486 };
490 typedef struct uvccCam uvccCam;
491 
492 
495 #endif