xref: /openbsd/sys/dev/usb/uvideo.h (revision 9c7bd2b0)
1 /*	$OpenBSD: uvideo.h,v 1.63 2025/01/16 22:58:19 kirill Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Robert Nagy <robert@openbsd.org>
5  * Copyright (c) 2008 Marcus Glocker <mglocker@openbsd.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include <sys/queue.h>
21 #include <sys/videoio.h>
22 
23 /*
24  * USB Video Class
25  */
26 /* Table A-7: Video Class-Specific Endpoint Descriptor Subtypes */
27 #define	EP_UNDEFINED					0x00
28 #define EP_GENERAL					0x01
29 #define EP_ENDPOINT					0x02
30 #define EP_INTERRUPT					0x03
31 
32 /* Table A-5: Video Class-Specific VC Interface Descriptor Subtypes */
33 #define	UDESCSUB_VC_DESCRIPTOR_UNDEFINED		0x00
34 #define UDESCSUB_VC_HEADER				0x01
35 #define UDESCSUB_VC_INPUT_TERMINAL			0x02
36 #define UDESCSUB_VC_OUTPUT_TERMINAL			0x03
37 #define UDESCSUB_VC_SELECTOR_UNIT			0x04
38 #define UDESCSUB_VC_PROCESSING_UNIT			0x05
39 #define UDESCSUB_VC_EXTENSION_UNIT			0x06
40 
41 /* Table A-6: Video Class-Specific VS Interface Descriptor Subtypes */
42 #define	UDESCSUB_VS_UNDEFINED				0x00
43 #define UDESCSUB_VS_INPUT_HEADER			0x01
44 #define UDESCSUB_VS_OUTPUT_HEADER			0x02
45 #define UDESCSUB_VS_STILL_IMAGE_FRAME			0x03
46 #define UDESCSUB_VS_FORMAT_UNCOMPRESSED			0x04
47 #define UDESCSUB_VS_FRAME_UNCOMPRESSED			0x05
48 #define UDESCSUB_VS_FORMAT_MJPEG			0x06
49 #define UDESCSUB_VS_FRAME_MJPEG				0x07
50 #define UDESCSUB_VS_FORMAT_MPEG2TS			0x0a
51 #define UDESCSUB_VS_FORMAT_DV				0x0c
52 #define UDESCSUB_VS_COLORFORMAT				0x0d
53 #define UDESCSUB_VS_FORMAT_FRAME_BASED			0x10
54 #define UDESCSUB_VS_FRAME_FRAME_BASED			0x11
55 #define UDESCSUB_VS_FORMAT_STREAM_BASED			0x12
56 
57 /* Table A-8: Video Class-Specific Request Codes */
58 #define RC_UNDEFINED					0x00
59 #define SET_CUR						0x01
60 #define GET_CUR						0x81
61 #define GET_MIN						0x82
62 #define GET_MAX						0x83
63 #define GET_RES						0x84
64 #define GET_LEN						0x85
65 #define GET_INFO					0x86
66 #define GET_DEF						0x87
67 
68 /* Table A-9: Video Control Interface Control Selectors */
69 #define VC_CONTROL_UNDEFINED				0x00
70 #define VC_VIDEO_POWER_MODE_CONTROL			0x01
71 #define VC_REQUEST_ERROR_CODE_CONTROL			0x02
72 
73 /* Table A-11: Selector Unit Control Selectors */
74 #define	SU_CONTROL_UNDEFINED				0x00
75 #define	SU_INPUT_SELECT_CONTROL				0x01
76 
77 /* Table A-12: Camera Terminal Control Selectors */
78 #define	CT_CONTROL_UNDEFINED				0x00
79 #define	CT_SCANNING_MODE_CONTROL			0x01
80 #define	CT_AE_MODE_CONTROL				0x02
81 #define	CT_AE_PRIORITY_CONTROL				0x03
82 #define	CT_EXPOSURE_TIME_ABSOLUTE_CONTROL		0x04
83 #define	CT_EXPOSURE_TIME_RELATIVE_CONTROL		0x05
84 #define	CT_FOCUS_ABSOLUTE_CONTROL			0x06
85 #define	CT_FOCUS_RELATIVE_CONTROL			0x07
86 #define	CT_FOCUS_AUTO_CONTROL				0x08
87 #define	CT_IRIS_ABSOLUTE_CONTROL			0x09
88 #define	CT_IRIS_RELATIVE_CONTROL			0x0a
89 #define	CT_ZOOM_ABSOLUTE_CONTROL			0x0b
90 #define	CT_ZOOM_RELATIVE_CONTROL			0x0c
91 #define	CT_PANTILT_ABSOLUTE_CONTROL			0x0d
92 #define	CT_PANTILT_RELATIVE_CONTROL			0x0e
93 #define	CT_ROLL_ABSOLUTE_CONTROL			0x0f
94 #define	CT_ROLL_RELATIVE_CONTROL			0x10
95 #define	CT_PRIVACY_CONTROL				0x11
96 
97 /* Table A-13: Processing Unit Control Selectors */
98 #define	PU_CONTROL_UNDEFINED				0x00
99 #define	PU_BACKLIGHT_COMPENSATION_CONTROL		0x01
100 #define	PU_BRIGHTNESS_CONTROL				0x02
101 #define	PU_CONTRAST_CONTROL				0x03
102 #define	PU_GAIN_CONTROL					0x04
103 #define	PU_POWER_LINE_FREQUENCY_CONTROL			0x05
104 #define	PU_HUE_CONTROL					0x06
105 #define	PU_SATURATION_CONTROL				0x07
106 #define	PU_SHARPNESS_CONTROL				0x08
107 #define	PU_GAMMA_CONTROL				0x09
108 #define	PU_WHITE_BALANCE_TEMPERATURE_CONTROL		0x0a
109 #define	PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL	0x0b
110 #define	PU_WHITE_BALANCE_COMPONENT_CONTROL		0x0c
111 #define	PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL		0x0d
112 #define	PU_DIGITAL_MULTIPLIER_CONTROL			0x0e
113 #define	PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL		0x0f
114 #define	PU_HUE_AUTO_CONTROL				0x10
115 #define	PU_ANALOG_VIDEO_STANDARD_CONTROL		0x11
116 #define	PU_ANALOG_LOCK_STATUS_CONTROL			0x12
117 
118 /* Table A-15: VideoStreaming Interface Control Selectors */
119 #define	VS_CONTROL_UNDEFINED				0x00
120 #define	VS_PROBE_CONTROL				0x01
121 #define	VS_COMMIT_CONTROL				0x02
122 #define	VS_STILL_PROBE_CONTROL				0x03
123 #define	VS_STILL_COMMIT_CONTROL				0x04
124 #define	VS_STILL_IMAGE_TRIGGER_CONTROL			0x05
125 #define	VS_STREAM_ERROR_CODE_CONTROL			0x06
126 #define	VS_GENERATE_KEY_FRAME_CONTROL			0x07
127 #define	VS_UPDATE_FRAME_SEGMENT_CONTROL			0x08
128 #define	VS_SYNC_DELAY_CONTROL				0x09
129 
130 /* probe commit bmRequests */
131 #define	UVIDEO_SET_IF					0x21
132 #define	UVIDEO_GET_IF					0xa1
133 #define	UVIDEO_SET_EP					0x22
134 #define	UVIDEO_GET_EP					0xa2
135 
136 /* Table B-1: USB Terminal Types */
137 #define	TT_VENDOR_SPECIFIC				0x0100
138 #define	TT_STREAMING					0x0101
139 
140 /* Table B-2: Input Terminal Types */
141 #define	ITT_VENDOR_SPECIFIC				0x0200
142 #define	ITT_CAMERA					0x0201
143 #define	ITT_MEDIA_TRANSPORT_INPUT			0x0202
144 
145 /* Table B-3: Output Terminal Types */
146 #define	OTT_VENDOR_SPECIFIC				0x0300
147 #define	OTT_DISPLAY					0x0301
148 #define	OTT_MEDIA_TRANSPORT_OUTPUT			0x0302
149 
150 /* Table B-4: External Terminal Types */
151 #define	EXTERNAL_VENDOR_SPECIFIC			0x0400
152 #define	COMPOSITE_CONNECTOR				0x0401
153 #define	SVIDEO_CONNECTOR				0x0402
154 #define	COMPONENT_CONNECTOR				0x0403
155 
156 /* Table 3-3: VC Interface Header Descriptor */
157 struct usb_video_header_desc {
158 	uByte	bLength;
159 	uByte	bDescriptorType;
160 	uByte	bDescriptorSubtype;
161 	uWord	bcdUVC;
162 	uWord	wTotalLength;
163 	uDWord	dwClockFrequency;
164 	uByte	bInCollection;
165 } __packed;
166 
167 struct usb_video_header_desc_all {
168 	struct usb_video_header_desc	*fix;
169 	uByte				*baInterfaceNr;
170 };
171 
172 /* Table 3-4: Input Terminal Descriptor */
173 struct usb_video_input_terminal_desc {
174 	uByte	bLength;
175 	uByte	bDescriptorType;
176 	uByte	bDescriptorSubtype;
177 	uByte	bTerminalID;
178 	uWord	wTerminalType;
179 	uByte	bAssocTerminal;
180 	uByte	iTerminal;
181 } __packed;
182 
183 /* Table 3-5: Output Terminal Descriptor */
184 struct usb_video_output_terminal_desc {
185 	uByte	bLength;
186 	uByte	bDescriptorType;
187 	uByte	bDescriptorSubtype;
188 	uByte	bTerminalID;
189 	uWord	wTerminalType;
190 	uByte	bAssocTerminal;
191 	uByte	bSourceID;
192 	uByte	iTerminal;
193 } __packed;
194 
195 /* Table 3-6: Camera Terminal Descriptor */
196 struct usb_video_camera_terminal_desc {
197 	uByte	bLength;
198 	uByte	bDescriptorType;
199 	uByte	bDescriptorSubtype;
200 	uByte	bTerminalID;
201 	uWord	wTerminalType;
202 	uByte	bAssocTerminal;
203 	uByte	iTerminal;
204 	uWord	wObjectiveFocalLengthMin;
205 	uWord	wObjectiveFocalLengthMax;
206 	uWord	wOcularFocalLength;
207 	uByte	bControlSize;
208 	uByte	*bmControls;
209 } __packed;
210 
211 /* Table 3-8: VC Processing Unit Descriptor */
212 struct usb_video_vc_processing_desc {
213 	uByte	bLength;
214 	uByte	bDescriptorType;
215 	uByte	bDescriptorSubtype;
216 	uByte	bUnitID;
217 	uByte	bSourceID;
218 	uWord	wMaxMultiplier;
219 	uByte	bControlSize;
220 	uByte	bmControls[255]; /* [bControlSize] */
221 	/* uByte iProcessing; */
222 	/* uByte bmVideoStandards; */
223 } __packed;
224 
225 /* Table 3-9: VC Extension Unit Descriptor */
226 struct usb_video_vc_extension_desc {
227 	uByte	bLength;
228 	uByte	bDescriptorType;
229 	uByte	bDescriptorSubtype;
230 	uByte	bUnitID;
231 	uByte	guidExtensionCode[16];
232 	uByte	bNumControls;
233 	uByte	bNrInPins;
234 } __packed;
235 
236 /* Table 3-11: VC Endpoint Descriptor */
237 struct usb_video_vc_endpoint_desc {
238 	uByte	bLength;
239 	uByte	bDescriptorType;
240 	uByte	bDescriptorSubtype;
241 	uWord	wMaxTransferSize;
242 } __packed;
243 
244 /* Table 3-13: Interface Input Header Descriptor */
245 struct usb_video_input_header_desc {
246 	uByte	bLength;
247 	uByte	bDescriptorType;
248 	uByte	bDescriptorSubtype;
249 	uByte	bNumFormats;
250 	uWord	wTotalLength;
251 	uByte	bEndpointAddress;
252 	uByte	bmInfo;
253 	uByte	bTerminalLink;
254 	uByte	bStillCaptureMethod;
255 	uByte	bTriggerSupport;
256 	uByte	bTriggerUsage;
257 	uByte	bControlSize;
258 } __packed;
259 
260 struct usb_video_input_header_desc_all {
261 	struct usb_video_input_header_desc	*fix;
262 	uByte					*bmaControls;
263 };
264 
265 /* Table 3-18: Color Matching Descriptor */
266 struct usb_video_color_matching_descr {
267 	uByte	bLength;
268 	uByte	bDescriptorType;
269 	uByte	bDescriptorSubtype;
270 	uByte	bColorPrimaries;
271 	uByte	bTransferCharacteristics;
272 	uByte	bMatrixCoefficients;
273 } __packed;
274 
275 /* Table 4-47: Video Probe and Commit Controls */
276 struct usb_video_probe_commit {
277 	uWord	bmHint;
278 	uByte	bFormatIndex;
279 	uByte	bFrameIndex;
280 	uDWord	dwFrameInterval;
281 	uWord	wKeyFrameRate;
282 	uWord	wPFrameRate;
283 	uWord	wCompQuality;
284 	uWord	wCompWindowSize;
285 	uWord	wDelay;
286 	uDWord	dwMaxVideoFrameSize;
287 	uDWord	dwMaxPayloadTransferSize;
288 	uDWord	dwClockFrequency;
289 	uByte	bmFramingInfo;
290 	uByte	bPreferedVersion;
291 	uByte	bMinVersion;
292 	uByte	bMaxVersion;
293 } __packed;
294 
295 /*
296  * USB Video Payload Uncompressed
297  */
298 /* Table 2-1: Compression Formats */
299 #define	UVIDEO_FORMAT_GUID_YUY2	{			\
300     'Y',  'U',  'Y',  '2',  0x00, 0x00, 0x10, 0x00,	\
301     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
302 
303 #define	UVIDEO_FORMAT_GUID_YV12	{			\
304     'Y',  'V',  '1',  '2',  0x00, 0x00, 0x10, 0x00,	\
305     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
306 
307 #define	UVIDEO_FORMAT_GUID_I420	{			\
308     'I',  '4',  '2',  '0',  0x00, 0x00, 0x10, 0x00,	\
309     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
310 
311 #define	UVIDEO_FORMAT_GUID_Y800	{			\
312     'Y',  '8',  '0',  '0',  0x00, 0x00, 0x10, 0x00,	\
313     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
314 
315 #define	UVIDEO_FORMAT_GUID_Y8	{			\
316     'Y',  '8',  ' ',  ' ',  0x00, 0x00, 0x10, 0x00,	\
317     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
318 
319 #define	UVIDEO_FORMAT_GUID_D3DFMT_L8	{		\
320     0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,	\
321     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
322 
323 #define	UVIDEO_FORMAT_GUID_KSMEDIA_L8_IR	{	\
324     0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00,	\
325     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
326 
327 #define	UVIDEO_FORMAT_GUID_BY8	{			\
328     'B',  'Y',  '8',  ' ',  0x00, 0x00, 0x10, 0x00,	\
329     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
330 
331 #define	UVIDEO_FORMAT_GUID_BA81	{			\
332     'B',  'A',  '8',  '1',  0x00, 0x00, 0x10, 0x00,	\
333     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
334 
335 #define	UVIDEO_FORMAT_GUID_GBRG	{			\
336     'G',  'B',  'R',  'G',  0x00, 0x00, 0x10, 0x00,	\
337     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
338 
339 #define	UVIDEO_FORMAT_GUID_GRBG	{			\
340     'G',  'R',  'B',  'G',  0x00, 0x00, 0x10, 0x00,	\
341     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
342 
343 #define	UVIDEO_FORMAT_GUID_RGGB	{			\
344     'R',  'G',  'G',  'B',  0x00, 0x00, 0x10, 0x00,	\
345     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
346 
347 #define	UVIDEO_FORMAT_GUID_RGBP	{			\
348     'R',  'G',  'B',  'P',  0x00, 0x00, 0x10, 0x00,	\
349     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
350 
351 #define	UVIDEO_FORMAT_GUID_D3DFMT_R5G6B5	{	\
352     0x7b, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11,	\
353     0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 }
354 
355 #define	UVIDEO_FORMAT_GUID_BGR3	{			\
356     0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11,	\
357     0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 }
358 
359 #define	UVIDEO_FORMAT_GUID_BGR4	{			\
360     0x7e, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11,	\
361     0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 }
362 
363 #define	UVIDEO_FORMAT_GUID_H265	{			\
364     'H',  '2',  '6',  '5',  0x00, 0x00, 0x10, 0x00,	\
365     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
366 
367 #define	UVIDEO_FORMAT_GUID_RW10	{			\
368     'R',  'W',  '1',  '0',  0x00, 0x00, 0x10, 0x00,	\
369     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
370 
371 #define	UVIDEO_FORMAT_GUID_BG16	{			\
372     'B',  'G',  '1',  '6',  0x00, 0x00, 0x10, 0x00,	\
373     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
374 
375 #define	UVIDEO_FORMAT_GUID_GB16	{			\
376     'G',  'B',  '1',  '6',  0x00, 0x00, 0x10, 0x00,	\
377     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
378 
379 #define	UVIDEO_FORMAT_GUID_RG16	{			\
380     'R',  'G',  '1',  '6',  0x00, 0x00, 0x10, 0x00,	\
381     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
382 
383 #define	UVIDEO_FORMAT_GUID_GR16	{			\
384     'G',  'R',  '1',  '6',  0x00, 0x00, 0x10, 0x00,	\
385     0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
386 
387 #define	UVIDEO_FORMAT_GUID_INVZ	{			\
388     'I',  'N',  'V',  'Z',  0x90, 0x2d, 0x58, 0x4a,	\
389     0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b }
390 
391 #define	UVIDEO_FORMAT_GUID_INVI	{			\
392     'I',  'N',  'V',  'I',  0xdb, 0x57, 0x49, 0x5e,	\
393     0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f }
394 
395 /*
396  * USB Video Payload MJPEG
397  */
398 /* Table 2-1: Stream Header Format for the Motion-JPEG */
399 #define UVIDEO_SH_MAX_LEN	12
400 #define UVIDEO_SH_MIN_LEN	2
401 struct usb_video_stream_header {
402 	uByte	bLength;
403 	uByte	bFlags;
404 #define	UVIDEO_SH_FLAG_FID	(1 << 0)
405 #define	UVIDEO_SH_FLAG_EOF	(1 << 1)
406 #define	UVIDEO_SH_FLAG_PTS	(1 << 2)
407 #define	UVIDEO_SH_FLAG_SCR	(1 << 3)
408 #define	UVIDEO_SH_FLAG_RES	(1 << 4)
409 #define	UVIDEO_SH_FLAG_STI	(1 << 5)
410 #define	UVIDEO_SH_FLAG_ERR	(1 << 6)
411 #define	UVIDEO_SH_FLAG_EOH	(1 << 7)
412 	/* TODO complete struct */
413 } __packed;
414 
415 /* Table 3-1: Motion-JPEG Video Format Descriptor */
416 struct usb_video_format_mjpeg_desc {
417 	uByte	bLength;
418 	uByte	bDescriptorType;
419 	uByte	bDescriptorSubtype;
420 	uByte	bFormatIndex;
421 	uByte	bNumFrameDescriptors;
422 	uByte	bmFlags;
423 	uByte	bDefaultFrameIndex;
424 	uByte	bAspectRatioX;
425 	uByte	bAspectRatioY;
426 	uByte	bmInterlaceFlags;
427 	uByte	bCopyProtect;
428 } __packed;
429 
430 /* Table 3-2: Video Frame Descriptor (same for mjpeg and uncompressed)*/
431 struct usb_video_frame_desc {
432 	uByte	bLength;
433 	uByte	bDescriptorType;
434 	uByte	bDescriptorSubtype;
435 	uByte	bFrameIndex;
436 	uByte	bmCapabilities;
437 	uWord	wWidth;
438 	uWord	wHeight;
439 	uDWord	dwMinBitRate;
440 	uDWord	dwMaxBitRate;
441 	uDWord	dwMaxVideoFrameBufferSize;
442 	uDWord	dwDefaultFrameInterval;
443 	uByte	bFrameIntervalType;
444 	/* uDWord ivals[]; frame intervals, length varies */
445 } __packed;
446 
447 /*
448  * USB Video Payload Uncompressed
449  */
450 /* Table 3-1: Uncompressed Video Format Descriptor */
451 struct usb_video_format_uncompressed_desc {
452 	uByte	bLength;
453 	uByte	bDescriptorType;
454 	uByte	bDescriptorSubtype;
455 	uByte	bFormatIndex;
456 	uByte	bNumFrameDescriptors;
457 	uByte	guidFormat[16];
458 	uByte	bBitsPerPixel;
459 	uByte	bDefaultFrameIndex;
460 	uByte	bAspectRatioX;
461 	uByte	bAspectRatioY;
462 	uByte	bmInterlaceFlags;
463 	uByte	bCopyProtect;
464 } __packed;
465 
466 /*
467  * Driver specific private definitions.
468  */
469 struct uvideo_format_desc {
470 	uByte	bLength;
471 	uByte	bDescriptorType;
472 	uByte	bDescriptorSubtype;
473 	uByte	bFormatIndex;
474 	uByte	bNumFrameDescriptors;
475 	union {
476 		/* mjpeg */
477 		struct {
478 			uByte	bmFlags;
479 			uByte	bDefaultFrameIndex;
480 			uByte	bAspectRatioX;
481 			uByte	bAspectRatioY;
482 			uByte	bmInterlaceFlags;
483 			uByte	bCopyProtect;
484 		} mjpeg;
485 
486 		/* uncompressed */
487 		struct {
488 			uByte	guidFormat[16];
489 			uByte	bBitsPerPixel;
490 			uByte	bDefaultFrameIndex;
491 			uByte	bAspectRatioX;
492 			uByte	bAspectRatioY;
493 			uByte	bmInterlaceFlags;
494 			uByte	bCopyProtect;
495 		} uc;
496 	} u;
497 } __packed;
498 
499 #define UVIDEO_NFRAMES_MAX	40
500 struct uvideo_isoc_xfer {
501 	struct uvideo_softc	*sc;
502 	struct usbd_xfer	*xfer;
503 	void			*buf;
504 	uint16_t		 size[UVIDEO_NFRAMES_MAX];
505 };
506 
507 struct uvideo_bulk_xfer {
508 	struct uvideo_softc	*sc;
509 	struct usbd_xfer	*xfer;
510 	void			*buf;
511 	uint16_t		 size;
512 };
513 
514 #define UVIDEO_IXFERS		3
515 struct uvideo_vs_iface {
516 	struct usbd_interface	*ifaceh;
517 	struct usbd_pipe	*pipeh;
518 	int			 iface;
519 	int			 numalts;
520 	int			 curalt;
521 	int			 endpoint;
522 	uint32_t		 psize;
523 	int			 bulk_endpoint;
524 	int			 bulk_running;
525 	struct uvideo_isoc_xfer	 ixfer[UVIDEO_IXFERS];
526 	struct uvideo_bulk_xfer	 bxfer;
527 };
528 
529 struct uvideo_frame_buffer {
530 	int		 sample;
531 	uint8_t		 fid;
532 	uint8_t		 error;
533 	int		 offset;
534 	int		 buf_size;
535 	uint8_t		*buf;
536 	uint32_t	 fmt_flags;
537 };
538 
539 /*
540  * 1920x1080 uncompressed (e.g. YUYV422) requires ~4MB image data per frame.
541  * 4MB * 8 frame buffers = 32MB kernel memory required.
542  * With 8 frame buffers we are pretty safe not to run out of kernel memory.
543  */
544 #define UVIDEO_MAX_BUFFERS	8
545 struct uvideo_mmap {
546 	SIMPLEQ_ENTRY(uvideo_mmap)	q_frames;
547 	uint8_t				*buf;
548 	struct v4l2_buffer		 v4l2_buf;
549 };
550 typedef SIMPLEQ_HEAD(, uvideo_mmap) q_mmap;
551 
552 struct uvideo_format_group {
553 	uint32_t				 pixelformat;
554 	uint8_t					 format_dfidx;
555 	struct uvideo_format_desc		*format;
556 	/* frame descriptors for mjpeg and uncompressed are identical */
557 #define UVIDEO_MAX_FRAME			 32
558 	struct usb_video_frame_desc		*frame_cur;
559 	struct usb_video_frame_desc		*frame[UVIDEO_MAX_FRAME];
560 	int					 frame_num;
561 };
562 
563 struct uvideo_res {
564 	int width;
565 	int height;
566 	int fidx;
567 };
568 
569 struct uvideo_controls {
570 	int		cid;
571 	int		type;
572 	char		name[32];
573 	uint8_t         ctrl_bit;
574 	uint16_t	ctrl_selector;
575 	uint16_t	ctrl_len;
576 	int		sig;
577 } uvideo_ctrls[] = {
578         /*
579          * Processing Unit Controls
580          */
581 	{
582 	    V4L2_CID_BRIGHTNESS,
583 	    V4L2_CTRL_TYPE_INTEGER,
584 	    "Brightness",
585 	    0,
586 	    PU_BRIGHTNESS_CONTROL,
587 	    2,
588 	    1
589 	},
590 	{
591 	    V4L2_CID_CONTRAST,
592 	    V4L2_CTRL_TYPE_INTEGER,
593 	    "Contrast",
594 	    1,
595 	    PU_CONTRAST_CONTROL,
596 	    2,
597 	    0
598 	},
599 	{
600 	    V4L2_CID_HUE,
601 	    V4L2_CTRL_TYPE_INTEGER,
602 	    "Hue",
603 	    2,
604 	    PU_HUE_CONTROL,
605 	    2,
606 	    1
607 	},
608 	{
609 	    V4L2_CID_SATURATION,
610 	    V4L2_CTRL_TYPE_INTEGER,
611 	    "Saturation",
612 	    3,
613 	    PU_SATURATION_CONTROL,
614 	    2,
615 	    0
616 	},
617 	{
618 	    V4L2_CID_SHARPNESS,
619 	    V4L2_CTRL_TYPE_INTEGER,
620 	    "Sharpness",
621 	    4,
622 	    PU_SHARPNESS_CONTROL,
623 	    2,
624 	    0
625 	},
626 	{
627 	    V4L2_CID_GAMMA,
628 	    V4L2_CTRL_TYPE_INTEGER,
629 	    "Gamma",
630 	    5,
631 	    PU_GAMMA_CONTROL,
632 	    2,
633 	    0
634 	},
635 	{
636 	    V4L2_CID_WHITE_BALANCE_TEMPERATURE,
637 	    V4L2_CTRL_TYPE_INTEGER,
638 	    "White Balance Temperature",
639 	    6,
640 	    PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
641 	    2,
642 	    0
643 	},
644 #if 0
645         /* XXX Two V4L2 ids mapping one UVC control */
646 	{
647 	    V4L2_CID_RED_BALANCE, /* V4L2_CID_BLUE_BALANCE */
648 	    V4L2_CTRL_TYPE_INTEGER,
649 	    "White Balance Red Component", /* Blue Component */
650 	    7,
651 	    PU_WHITE_BALANCE_COMPONENT_CONTROL,
652 	    4,
653 	    0
654 	},
655 #endif
656         {
657             V4L2_CID_BACKLIGHT_COMPENSATION,
658             V4L2_CTRL_TYPE_INTEGER,
659             "Backlight Compensation",
660             8,
661             PU_BACKLIGHT_COMPENSATION_CONTROL,
662             2,
663 	    0
664         },
665 	{
666 	    V4L2_CID_GAIN,
667 	    V4L2_CTRL_TYPE_INTEGER,
668 	    "Gain",
669 	    9,
670 	    PU_GAIN_CONTROL,
671 	    2,
672 	    0
673 	},
674         {
675             V4L2_CID_POWER_LINE_FREQUENCY,
676             V4L2_CTRL_TYPE_MENU,
677             "Power Line Frequency",
678             10,
679             PU_POWER_LINE_FREQUENCY_CONTROL,
680             2,
681 	    0
682         },
683         {
684             V4L2_CID_HUE_AUTO,
685             V4L2_CTRL_TYPE_BOOLEAN,
686             "Hue Auto",
687             11,
688             PU_HUE_AUTO_CONTROL,
689             1,
690 	    0
691         },
692         {
693             V4L2_CID_AUTO_WHITE_BALANCE,
694             V4L2_CTRL_TYPE_BOOLEAN,
695             "White Balance Temperature Auto",
696             12,
697             PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
698             1,
699 	    0
700         },
701         {
702             V4L2_CID_AUTO_WHITE_BALANCE,
703             V4L2_CTRL_TYPE_BOOLEAN,
704             "White Balance Component Auto",
705             13,
706             PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
707             1,
708 	    0
709         },
710 #if 0
711         /* XXX No V4L2 CID for these controls? */
712         {
713             V4L2_CID_XXX,
714             V4L2_CTRL_TYPE_INTEGER,
715             "Digital Multiplier",
716             14,
717             PU_DIGITAL_MULTIPLIER_CONTROL,
718             2,
719 	    0
720         },
721         {
722             V4L2_CID_XXX,
723             V4L2_CTRL_TYPE_INTEGER,
724             "Digital Multiplier Limit",
725             15,
726             PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
727             2,
728 	    0
729         },
730         {
731             V4L2_CID_XXX,
732             V4L2_CTRL_TYPE_INTEGER,
733             "Analog Video Standard",
734             16,
735             PU_ANALOG_VIDEO_STANDARD_CONTROL,
736             1,
737 	    0
738         },
739         {
740             V4L2_CID_XXX,
741             V4L2_CTRL_TYPE_INTEGER,
742             "Analog Lock Status",
743             17,
744             PU_ANALOG_LOCK_STATUS_CONTROL,
745             1,
746 	    0
747         },
748 #endif
749 	{ 0, 0, "", 0, 0, 0, 0 }
750 };
751