1 /* $OpenBSD: uvideo.h,v 1.71 2025/09/06 13:45:41 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 #ifndef _UVIDEO_H_ 21 #define _UVIDEO_H_ 22 23 #include <sys/queue.h> 24 #include "uvideo_v4l2.h" 25 26 /* 27 * USB Video Class 28 */ 29 /* Table A-7: Video Class-Specific Endpoint Descriptor Subtypes */ 30 #define EP_UNDEFINED 0x00 31 #define EP_GENERAL 0x01 32 #define EP_ENDPOINT 0x02 33 #define EP_INTERRUPT 0x03 34 35 /* Table A-5: Video Class-Specific VC Interface Descriptor Subtypes */ 36 #define UDESCSUB_VC_DESCRIPTOR_UNDEFINED 0x00 37 #define UDESCSUB_VC_HEADER 0x01 38 #define UDESCSUB_VC_INPUT_TERMINAL 0x02 39 #define UDESCSUB_VC_OUTPUT_TERMINAL 0x03 40 #define UDESCSUB_VC_SELECTOR_UNIT 0x04 41 #define UDESCSUB_VC_PROCESSING_UNIT 0x05 42 #define UDESCSUB_VC_EXTENSION_UNIT 0x06 43 44 /* Table A-6: Video Class-Specific VS Interface Descriptor Subtypes */ 45 #define UDESCSUB_VS_UNDEFINED 0x00 46 #define UDESCSUB_VS_INPUT_HEADER 0x01 47 #define UDESCSUB_VS_OUTPUT_HEADER 0x02 48 #define UDESCSUB_VS_STILL_IMAGE_FRAME 0x03 49 #define UDESCSUB_VS_FORMAT_UNCOMPRESSED 0x04 50 #define UDESCSUB_VS_FRAME_UNCOMPRESSED 0x05 51 #define UDESCSUB_VS_FORMAT_MJPEG 0x06 52 #define UDESCSUB_VS_FRAME_MJPEG 0x07 53 #define UDESCSUB_VS_FORMAT_MPEG2TS 0x0a 54 #define UDESCSUB_VS_FORMAT_DV 0x0c 55 #define UDESCSUB_VS_COLORFORMAT 0x0d 56 #define UDESCSUB_VS_FORMAT_FRAME_BASED 0x10 57 #define UDESCSUB_VS_FRAME_FRAME_BASED 0x11 58 #define UDESCSUB_VS_FORMAT_STREAM_BASED 0x12 59 #define UDESCSUB_VS_FORMAT_H264 0x13 60 #define UDESCSUB_VS_FRAME_H264 0x14 61 #define UDESCSUB_VS_FORMAT_H264_SIMULCAST 0x15 62 63 /* Table A-8: Video Class-Specific Request Codes */ 64 #define RC_UNDEFINED 0x00 65 #define SET_CUR 0x01 66 #define GET_CUR 0x81 67 #define GET_MIN 0x82 68 #define GET_MAX 0x83 69 #define GET_RES 0x84 70 #define GET_LEN 0x85 71 #define GET_INFO 0x86 72 #define GET_DEF 0x87 73 74 /* Table A-9: Video Control Interface Control Selectors */ 75 #define VC_CONTROL_UNDEFINED 0x00 76 #define VC_VIDEO_POWER_MODE_CONTROL 0x01 77 #define VC_REQUEST_ERROR_CODE_CONTROL 0x02 78 79 /* Table A-11: Selector Unit Control Selectors */ 80 #define SU_CONTROL_UNDEFINED 0x00 81 #define SU_INPUT_SELECT_CONTROL 0x01 82 83 /* Table A-12: Camera Terminal Control Selectors */ 84 #define CT_CONTROL_UNDEFINED 0x00 85 #define CT_SCANNING_MODE_CONTROL 0x01 86 #define CT_AE_MODE_CONTROL 0x02 87 #define CT_AE_PRIORITY_CONTROL 0x03 88 #define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04 89 #define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05 90 #define CT_FOCUS_ABSOLUTE_CONTROL 0x06 91 #define CT_FOCUS_RELATIVE_CONTROL 0x07 92 #define CT_FOCUS_AUTO_CONTROL 0x08 93 #define CT_IRIS_ABSOLUTE_CONTROL 0x09 94 #define CT_IRIS_RELATIVE_CONTROL 0x0a 95 #define CT_ZOOM_ABSOLUTE_CONTROL 0x0b 96 #define CT_ZOOM_RELATIVE_CONTROL 0x0c 97 #define CT_PANTILT_ABSOLUTE_CONTROL 0x0d 98 #define CT_PANTILT_RELATIVE_CONTROL 0x0e 99 #define CT_ROLL_ABSOLUTE_CONTROL 0x0f 100 #define CT_ROLL_RELATIVE_CONTROL 0x10 101 #define CT_PRIVACY_CONTROL 0x11 102 103 /* Table A-13: Processing Unit Control Selectors */ 104 #define PU_CONTROL_UNDEFINED 0x00 105 #define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01 106 #define PU_BRIGHTNESS_CONTROL 0x02 107 #define PU_CONTRAST_CONTROL 0x03 108 #define PU_GAIN_CONTROL 0x04 109 #define PU_POWER_LINE_FREQUENCY_CONTROL 0x05 110 #define PU_HUE_CONTROL 0x06 111 #define PU_SATURATION_CONTROL 0x07 112 #define PU_SHARPNESS_CONTROL 0x08 113 #define PU_GAMMA_CONTROL 0x09 114 #define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0a 115 #define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0b 116 #define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0c 117 #define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0d 118 #define PU_DIGITAL_MULTIPLIER_CONTROL 0x0e 119 #define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0f 120 #define PU_HUE_AUTO_CONTROL 0x10 121 #define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11 122 #define PU_ANALOG_LOCK_STATUS_CONTROL 0x12 123 124 /* Table A-15: VideoStreaming Interface Control Selectors */ 125 #define VS_CONTROL_UNDEFINED 0x00 126 #define VS_PROBE_CONTROL 0x01 127 #define VS_COMMIT_CONTROL 0x02 128 #define VS_STILL_PROBE_CONTROL 0x03 129 #define VS_STILL_COMMIT_CONTROL 0x04 130 #define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05 131 #define VS_STREAM_ERROR_CODE_CONTROL 0x06 132 #define VS_GENERATE_KEY_FRAME_CONTROL 0x07 133 #define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08 134 #define VS_SYNC_DELAY_CONTROL 0x09 135 136 /* probe commit bmRequests */ 137 #define UVIDEO_SET_IF 0x21 138 #define UVIDEO_GET_IF 0xa1 139 #define UVIDEO_SET_EP 0x22 140 #define UVIDEO_GET_EP 0xa2 141 142 /* Table B-1: USB Terminal Types */ 143 #define TT_VENDOR_SPECIFIC 0x0100 144 #define TT_STREAMING 0x0101 145 146 /* Table B-2: Input Terminal Types */ 147 #define ITT_VENDOR_SPECIFIC 0x0200 148 #define ITT_CAMERA 0x0201 149 #define ITT_MEDIA_TRANSPORT_INPUT 0x0202 150 151 /* Table B-3: Output Terminal Types */ 152 #define OTT_VENDOR_SPECIFIC 0x0300 153 #define OTT_DISPLAY 0x0301 154 #define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302 155 156 /* Table B-4: External Terminal Types */ 157 #define EXTERNAL_VENDOR_SPECIFIC 0x0400 158 #define COMPOSITE_CONNECTOR 0x0401 159 #define SVIDEO_CONNECTOR 0x0402 160 #define COMPONENT_CONNECTOR 0x0403 161 162 /* Table 3-3: VC Interface Header Descriptor */ 163 struct usb_video_header_desc { 164 uByte bLength; 165 uByte bDescriptorType; 166 uByte bDescriptorSubtype; 167 uWord bcdUVC; 168 uWord wTotalLength; 169 uDWord dwClockFrequency; 170 uByte bInCollection; 171 } __packed; 172 173 struct usb_video_header_desc_all { 174 struct usb_video_header_desc *fix; 175 uByte *baInterfaceNr; 176 }; 177 178 /* Table 3-4: Input Terminal Descriptor */ 179 struct usb_video_input_terminal_desc { 180 uByte bLength; 181 uByte bDescriptorType; 182 uByte bDescriptorSubtype; 183 uByte bTerminalID; 184 uWord wTerminalType; 185 uByte bAssocTerminal; 186 uByte iTerminal; 187 } __packed; 188 189 /* Table 3-5: Output Terminal Descriptor */ 190 struct usb_video_output_terminal_desc { 191 uByte bLength; 192 uByte bDescriptorType; 193 uByte bDescriptorSubtype; 194 uByte bTerminalID; 195 uWord wTerminalType; 196 uByte bAssocTerminal; 197 uByte bSourceID; 198 uByte iTerminal; 199 } __packed; 200 201 /* Table 3-6: Camera Terminal Descriptor */ 202 struct usb_video_camera_terminal_desc { 203 uByte bLength; 204 uByte bDescriptorType; 205 uByte bDescriptorSubtype; 206 uByte bTerminalID; 207 uWord wTerminalType; 208 uByte bAssocTerminal; 209 uByte iTerminal; 210 uWord wObjectiveFocalLengthMin; 211 uWord wObjectiveFocalLengthMax; 212 uWord wOcularFocalLength; 213 uByte bControlSize; 214 uByte bmControls[255]; /* [bControlSize] */ 215 } __packed; 216 217 /* Table 3-8: VC Processing Unit Descriptor */ 218 struct usb_video_vc_processing_desc { 219 uByte bLength; 220 uByte bDescriptorType; 221 uByte bDescriptorSubtype; 222 uByte bUnitID; 223 uByte bSourceID; 224 uWord wMaxMultiplier; 225 uByte bControlSize; 226 uByte bmControls[255]; /* [bControlSize] */ 227 /* uByte iProcessing; */ 228 /* uByte bmVideoStandards; */ 229 } __packed; 230 231 /* Table 3-9: VC Extension Unit Descriptor */ 232 struct usb_video_vc_extension_desc { 233 uByte bLength; 234 uByte bDescriptorType; 235 uByte bDescriptorSubtype; 236 uByte bUnitID; 237 uByte guidExtensionCode[16]; 238 uByte bNumControls; 239 uByte bNrInPins; 240 } __packed; 241 242 /* Table 3-11: VC Endpoint Descriptor */ 243 struct usb_video_vc_endpoint_desc { 244 uByte bLength; 245 uByte bDescriptorType; 246 uByte bDescriptorSubtype; 247 uWord wMaxTransferSize; 248 } __packed; 249 250 /* Table 3-13: Interface Input Header Descriptor */ 251 struct usb_video_input_header_desc { 252 uByte bLength; 253 uByte bDescriptorType; 254 uByte bDescriptorSubtype; 255 uByte bNumFormats; 256 uWord wTotalLength; 257 uByte bEndpointAddress; 258 uByte bmInfo; 259 uByte bTerminalLink; 260 uByte bStillCaptureMethod; 261 uByte bTriggerSupport; 262 uByte bTriggerUsage; 263 uByte bControlSize; 264 } __packed; 265 266 struct usb_video_input_header_desc_all { 267 struct usb_video_input_header_desc *fix; 268 uByte *bmaControls; 269 }; 270 271 /* Table 3-18: Color Matching Descriptor */ 272 struct usb_video_color_matching_descr { 273 uByte bLength; 274 uByte bDescriptorType; 275 uByte bDescriptorSubtype; 276 uByte bColorPrimaries; 277 uByte bTransferCharacteristics; 278 uByte bMatrixCoefficients; 279 } __packed; 280 281 /* Table 4-75: Video Probe and Commit Controls */ 282 struct usb_video_probe_commit { 283 uWord bmHint; 284 uByte bFormatIndex; 285 uByte bFrameIndex; 286 uDWord dwFrameInterval; 287 uWord wKeyFrameRate; 288 uWord wPFrameRate; 289 uWord wCompQuality; 290 uWord wCompWindowSize; 291 uWord wDelay; 292 uDWord dwMaxVideoFrameSize; 293 uDWord dwMaxPayloadTransferSize; 294 uDWord dwClockFrequency; 295 uByte bmFramingInfo; 296 uByte bPreferedVersion; 297 uByte bMinVersion; 298 uByte bMaxVersion; 299 uByte bUsage; 300 uByte bBitDepthLuma; 301 uByte bmSettings; 302 uByte bMaxNumberOfRefFramesPlus1; 303 uWord bmRateControlModes; 304 uByte bmLayoutPerStream[8]; 305 } __packed; 306 307 /* 308 * USB Video Payload Uncompressed 309 */ 310 /* Table 2-1: Compression Formats */ 311 #define UVIDEO_FORMAT_GUID_YUY2 { \ 312 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 313 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 314 315 #define UVIDEO_FORMAT_GUID_NV12 { \ 316 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 317 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 318 319 #define UVIDEO_FORMAT_GUID_NV21 { \ 320 'N', 'V', '2', '1', 0x00, 0x00, 0x10, 0x00, \ 321 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 322 323 #define UVIDEO_FORMAT_GUID_YV12 { \ 324 'Y', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 325 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 326 327 #define UVIDEO_FORMAT_GUID_I420 { \ 328 'I', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 329 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 330 331 #define UVIDEO_FORMAT_GUID_M420 { \ 332 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 333 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 334 335 #define UVIDEO_FORMAT_GUID_UYVY { \ 336 'U', 'Y', 'V', 'Y', 0x00, 0x00, 0x10, 0x00, \ 337 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 338 339 #define UVIDEO_FORMAT_GUID_Y800 { \ 340 'Y', '8', '0', '0', 0x00, 0x00, 0x10, 0x00, \ 341 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 342 343 #define UVIDEO_FORMAT_GUID_Y8 { \ 344 'Y', '8', ' ', ' ', 0x00, 0x00, 0x10, 0x00, \ 345 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 346 347 #define UVIDEO_FORMAT_GUID_D3DFMT_L8 { \ 348 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, \ 349 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 350 351 #define UVIDEO_FORMAT_GUID_KSMEDIA_L8_IR { \ 352 0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, \ 353 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 354 355 #define UVIDEO_FORMAT_GUID_Y12 { \ 356 'Y', '1', '2', ' ', 0x00, 0x00, 0x10, 0x00, \ 357 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 358 359 #define UVIDEO_FORMAT_GUID_Y16 { \ 360 'Y', '1', '6', ' ', 0x00, 0x00, 0x10, 0x00, \ 361 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 362 363 #define UVIDEO_FORMAT_GUID_BY8 { \ 364 'B', 'Y', '8', ' ', 0x00, 0x00, 0x10, 0x00, \ 365 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 366 367 #define UVIDEO_FORMAT_GUID_BA81 { \ 368 'B', 'A', '8', '1', 0x00, 0x00, 0x10, 0x00, \ 369 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 370 371 #define UVIDEO_FORMAT_GUID_GBRG { \ 372 'G', 'B', 'R', 'G', 0x00, 0x00, 0x10, 0x00, \ 373 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 374 375 #define UVIDEO_FORMAT_GUID_GRBG { \ 376 'G', 'R', 'B', 'G', 0x00, 0x00, 0x10, 0x00, \ 377 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 378 379 #define UVIDEO_FORMAT_GUID_RGGB { \ 380 'R', 'G', 'G', 'B', 0x00, 0x00, 0x10, 0x00, \ 381 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 382 383 #define UVIDEO_FORMAT_GUID_RGBP { \ 384 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ 385 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 386 387 #define UVIDEO_FORMAT_GUID_D3DFMT_R5G6B5 { \ 388 0x7b, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \ 389 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 } 390 391 #define UVIDEO_FORMAT_GUID_BGR3 { \ 392 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \ 393 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 } 394 395 #define UVIDEO_FORMAT_GUID_BGR4 { \ 396 0x7e, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \ 397 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70 } 398 399 #define UVIDEO_FORMAT_GUID_H265 { \ 400 'H', '2', '6', '5', 0x00, 0x00, 0x10, 0x00, \ 401 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 402 403 #define UVIDEO_FORMAT_GUID_RW10 { \ 404 'R', 'W', '1', '0', 0x00, 0x00, 0x10, 0x00, \ 405 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 406 407 #define UVIDEO_FORMAT_GUID_BG16 { \ 408 'B', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 409 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 410 411 #define UVIDEO_FORMAT_GUID_GB16 { \ 412 'G', 'B', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 413 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 414 415 #define UVIDEO_FORMAT_GUID_RG16 { \ 416 'R', 'G', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 417 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 418 419 #define UVIDEO_FORMAT_GUID_GR16 { \ 420 'G', 'R', '1', '6', 0x00, 0x00, 0x10, 0x00, \ 421 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } 422 423 #define UVIDEO_FORMAT_GUID_INVZ { \ 424 'I', 'N', 'V', 'Z', 0x90, 0x2d, 0x58, 0x4a, \ 425 0x92, 0x0b, 0x77, 0x3f, 0x1f, 0x2c, 0x55, 0x6b } 426 427 #define UVIDEO_FORMAT_GUID_INVI { \ 428 'I', 'N', 'V', 'I', 0xdb, 0x57, 0x49, 0x5e, \ 429 0x8e, 0x3f, 0xf4, 0x79, 0x53, 0x2b, 0x94, 0x6f } 430 431 /* 432 * USB Video Payload MJPEG 433 */ 434 /* Table 2-1: Stream Header Format for the Motion-JPEG */ 435 #define UVIDEO_SH_MAX_LEN 12 436 #define UVIDEO_SH_MIN_LEN 2 437 struct usb_video_stream_header { 438 uByte bLength; 439 uByte bFlags; 440 #define UVIDEO_SH_FLAG_FID (1 << 0) 441 #define UVIDEO_SH_FLAG_EOF (1 << 1) 442 #define UVIDEO_SH_FLAG_PTS (1 << 2) 443 #define UVIDEO_SH_FLAG_SCR (1 << 3) 444 #define UVIDEO_SH_FLAG_RES (1 << 4) 445 #define UVIDEO_SH_FLAG_STI (1 << 5) 446 #define UVIDEO_SH_FLAG_ERR (1 << 6) 447 #define UVIDEO_SH_FLAG_EOH (1 << 7) 448 /* TODO complete struct */ 449 } __packed; 450 451 /* Table 3-19: Color Matching Descriptor */ 452 struct usb_video_colorformat_desc { 453 uByte bLength; 454 uByte bDescriptorType; 455 uByte bDescriptorSubtype; 456 uByte bColorPrimaries; 457 uByte bTransferCharacteristics; 458 uByte bMatrixCoefficients; 459 } __packed; 460 461 struct usb_video_frame_desc { 462 uByte bLength; 463 uByte bDescriptorType; 464 uByte bDescriptorSubtype; 465 uByte bFrameIndex; 466 union { 467 /* 468 * Table 3-2: Video Frame Descriptor 469 * (same for mjpeg and uncompressed) 470 */ 471 struct { 472 uByte bmCapabilities; 473 uWord wWidth; 474 uWord wHeight; 475 uDWord dwMinBitRate; 476 uDWord dwMaxBitRate; 477 uDWord dwMaxVideoFrameBufferSize; 478 uDWord dwDefaultFrameInterval; 479 uByte bFrameIntervalType; 480 } uc; 481 482 /* 483 * Table 3-2 Frame Based Payload Video Frame Descriptors */ 484 struct { 485 uByte bmCapabilities; 486 uWord wWidth; 487 uWord wHeight; 488 uDWord dwMinBitRate; 489 uDWord dwMaxBitRate; 490 uDWord dwDefaultFrameInterval; 491 uByte bFrameIntervalType; 492 uDWord dwBytesPerLine; 493 } fb; 494 495 /* Table 3-2: H.264 Payload Video Frame Descriptor */ 496 struct { 497 uWord wWidth; 498 uWord wHeight; 499 uWord wSARwidth; 500 uWord wSARheight; 501 uWord wProfile; 502 uByte bLevelIDC; 503 uWord wConstrainedToolset; 504 uDWord bmSupportedUsages; 505 uWord bmCapabilities; 506 uDWord bmSVCCapabilities; 507 uDWord bmMVCCapabilities; 508 uDWord dwMinBitRate; 509 uDWord dwMaxBitRate; 510 uDWord dwDefaultFrameInterval; 511 uByte bNumFrameIntervals; 512 } h264; 513 514 } u; 515 516 #define UVIDEO_FRAME_MIN_LEN(frm) \ 517 (offsetof(struct usb_video_frame_desc, u) + \ 518 ( \ 519 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_H264) ? \ 520 sizeof(((struct usb_video_frame_desc *)0)->u.h264) : \ 521 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_FRAME_BASED) ? \ 522 sizeof(((struct usb_video_frame_desc *)0)->u.fb) : \ 523 sizeof(((struct usb_video_frame_desc *)0)->u.uc) \ 524 ) \ 525 ) 526 527 #define UVIDEO_FRAME_FIELD(frm, field) \ 528 ( \ 529 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_H264) ? \ 530 (frm)->u.h264.field : \ 531 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_FRAME_BASED) ? \ 532 (frm)->u.fb.field : \ 533 (frm)->u.uc.field \ 534 ) 535 536 #define UVIDEO_FRAME_NUM_INTERVALS(frm) \ 537 ( \ 538 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_H264) ? \ 539 (frm)->u.h264.bNumFrameIntervals : \ 540 ((frm)->bDescriptorSubtype == UDESCSUB_VS_FRAME_FRAME_BASED) ? \ 541 (frm)->u.fb.bFrameIntervalType : \ 542 (frm)->u.uc.bFrameIntervalType \ 543 ) 544 545 /* uDWord ivals[]; frame intervals, length varies */ 546 } __packed; 547 548 struct usb_video_format_desc { 549 uByte bLength; 550 uByte bDescriptorType; 551 uByte bDescriptorSubtype; 552 uByte bFormatIndex; 553 uByte bNumFrameDescriptors; 554 union { 555 /* Table 3-1: Motion-JPEG Video Format Descriptor */ 556 struct { 557 uByte bmFlags; 558 uByte bDefaultFrameIndex; 559 uByte bAspectRatioX; 560 uByte bAspectRatioY; 561 uByte bmInterlaceFlags; 562 uByte bCopyProtect; 563 } mjpeg; 564 565 /* Table 3-1: Uncompressed Video Format Descriptor */ 566 struct { 567 uByte guidFormat[16]; 568 uByte bBitsPerPixel; 569 uByte bDefaultFrameIndex; 570 uByte bAspectRatioX; 571 uByte bAspectRatioY; 572 uByte bmInterlaceFlags; 573 uByte bCopyProtect; 574 } uc; 575 576 /* Table 3-1: Frame Based Payload Video Format Descriptor */ 577 struct { 578 uByte guidFormat[16]; 579 uByte bBitsPerPixel; 580 uByte bDefaultFrameIndex; 581 uByte bAspectRatioX; 582 uByte bAspectRatioY; 583 uByte bmInterlaceFlags; 584 uByte bCopyProtect; 585 uByte bVariableSize; 586 } fb; 587 588 /* Table 3-1: H.264 Payload Video Format Descriptor */ 589 struct { 590 uByte bDefaultFrameIndex; 591 uByte bMaxCodecConfigDelay; 592 uByte bmSupportedSliceModes; 593 uByte bmSupportedSyncFrameTypes; 594 uByte bResolutionScaling; 595 uByte _reserved1; 596 uByte bmSupportedRateControlModes; 597 uWord wMaxMBperSecOneResolutionNoScalability; 598 uWord wMaxMBperSecTwoResolutionsNoScalability; 599 uWord wMaxMBperSecThreeResolutionsNoScalability; 600 uWord wMaxMBperSecFourResolutionsNoScalability; 601 uWord wMaxMBperSecOneResolutionTemporalScalability; 602 uWord wMaxMBperSecTwoResolutionsTemporalScalablility; 603 uWord wMaxMBperSecThreeResolutionsTemporalScalability; 604 uWord wMaxMBperSecFourResolutionsTemporalScalability; 605 uWord wMaxMBperSecOneResolutionTemporalQualityScalability; 606 uWord wMaxMBperSecTwoResolutionsTemporalQualityScalability; 607 uWord wMaxMBperSecThreeResolutionsTemporalQualityScalablity; 608 uWord wMaxMBperSecFourResolutionsTemporalQualityScalability; 609 uWord wMaxMBperSecOneResolutionTemporalSpatialScalability; 610 uWord wMaxMBperSecTwoResolutionsTemporalSpatialScalability; 611 uWord wMaxMBperSecThreeResolutionsTemporalSpatialScalablity; 612 uWord wMaxMBperSecFourResolutionsTemporalSpatialScalability; 613 uWord wMaxMBperSecOneResolutionFullScalability; 614 uWord wMaxMBperSecTwoResolutionsFullScalability; 615 uWord wMaxMBperSecThreeResolutionsFullScalability; 616 uWord wMaxMBperSecFourResolutionsFullScalability; 617 } h264; 618 } u; 619 620 #define UVIDEO_FORMAT_LEN(fmt) \ 621 ( \ 622 (((fmt)->bDescriptorSubtype == UDESCSUB_VS_FORMAT_H264) || \ 623 ((fmt)->bDescriptorSubtype == UDESCSUB_VS_FORMAT_H264_SIMULCAST)) ? \ 624 (offsetof(struct usb_video_format_desc, u) + \ 625 sizeof(((struct usb_video_format_desc *)0)->u.h264)) : \ 626 ((fmt)->bDescriptorSubtype == UDESCSUB_VS_FORMAT_FRAME_BASED) ? \ 627 (offsetof(struct usb_video_format_desc, u) + \ 628 sizeof(((struct usb_video_format_desc *)0)->u.fb)) : \ 629 ((fmt)->bDescriptorSubtype == UDESCSUB_VS_FORMAT_UNCOMPRESSED) ? \ 630 (offsetof(struct usb_video_format_desc, u) + \ 631 sizeof(((struct usb_video_format_desc *)0)->u.uc)) : \ 632 ((fmt)->bDescriptorSubtype == UDESCSUB_VS_FORMAT_MJPEG) ? \ 633 (offsetof(struct usb_video_format_desc, u) + \ 634 sizeof(((struct usb_video_format_desc *)0)->u.mjpeg)) : \ 635 sizeof(struct usb_video_colorformat_desc) \ 636 ) 637 638 } __packed; 639 640 /* 641 * Driver specific private definitions. 642 */ 643 #define UVIDEO_NFRAMES_MAX 128 644 645 #define UVIDEO_IXFERS 5 646 struct uvideo_vs_iface { 647 uint8_t iface_index; 648 int numalts; 649 int curalt; 650 int endpoint; 651 uint32_t psize; 652 int bulk_endpoint; 653 int bulk_running; 654 }; 655 656 struct uvideo_frame_buffer { 657 int sample; 658 uint8_t fid; 659 uint8_t error; 660 uint8_t mmap_q_full; 661 int offset; 662 int buf_size; 663 uint8_t *buf; 664 uint32_t fmt_flags; 665 }; 666 667 /* 668 * 1920x1080 uncompressed (e.g. YUYV422) requires ~4MB image data per frame. 669 * 4MB * 8 frame buffers = 32MB kernel memory required. 670 * With 8 frame buffers we are pretty safe not to run out of kernel memory. 671 */ 672 #define UVIDEO_MAX_BUFFERS 8 673 struct uvideo_mmap { 674 STAILQ_ENTRY(uvideo_mmap) q_frames; 675 uint8_t *buf; 676 struct v4l2_buffer v4l2_buf; 677 }; 678 typedef STAILQ_HEAD(, uvideo_mmap) q_mmap; 679 680 struct uvideo_format_group { 681 uint32_t pixelformat; 682 int has_colorformat; 683 uint32_t colorspace; 684 uint32_t xfer_func; 685 uint32_t ycbcr_enc; 686 uint8_t format_dfidx; 687 struct usb_video_format_desc *format; 688 /* frame descriptors for mjpeg and uncompressed are identical */ 689 #define UVIDEO_MAX_FRAME 32 690 struct usb_video_frame_desc *frame_cur; 691 struct usb_video_frame_desc *frame[UVIDEO_MAX_FRAME]; 692 int frame_num; 693 }; 694 695 struct uvideo_res { 696 int width; 697 int height; 698 int fidx; 699 }; 700 701 struct uvideo_controls { 702 int cid; 703 int type; 704 char name[32]; 705 uint8_t ctrl_bit; 706 uint16_t ctrl_selector; 707 uint16_t ctrl_len; 708 int sig; 709 }; 710 711 #endif /* _UVIDEO_H_ */ 712