https://www.usbzh.com/article/detail-831.html
USB视频类(UVC)是一个标准类规范,用于标准化USB上的视频流功能。它使网络摄像头、数字摄像机、模拟视频转换器、模拟和数字电视调谐器等设备能够与主机无缝连接。UVC支持流式传输多种视频格式,包括YUV、MJPEG、MPEG-2 TS、H.264、DV等。它提供了向主机描述视频设备功能的结构,并定义了USB
根据请求控制设备的不同参数和视频流的特征。它还为视频设备提供了支持多种视频分辨率、格式和帧速率的灵活性,这对设备和主机之间的带宽协商有很大影响。大多数操作系统平台都支持UVC驱动程序,这大大减少了开发人员创建USB视频设备所需的时间。/*USB Video device product defines*/#define BCD_DEVICE 0x0100#define VENDOR_ID 0x20B1 #define PRODUCT_ID 0x1DE0/*USB Device Descriptor*/static unsigned char devDesc[] 0x12, /*0 bLength*/.USB_DESCTYPE_DEVICE, /*1 bdescriptorType - Device*/.0x00, /*2 bcdUSB version*/.0x02, /*3 bcdUSB version*/.0xEF, /*4 bDeviceClass - USB Miscellaneous Class*/.0x02, /*5 bDeviceSubClass - Common Class*/
.0x01, /*6 bDeviceProtocol - Interface Association Descriptor*/.0x40, /*7 bMaxPacketSize for EP0 - max = 64*/.(VENDOR_ID & 0xFF), /*8 idVendor*/.(VENDOR_ID >> 8), /*9 idVendor*/.(PRODUCT_ID & 0xFF), /*10 idProduct*/.(PRODUCT_ID >> 8), /*11 idProduct*/.(BCD_DEVICE & 0xFF), /*12 bcdDevice*/.(BCD_DEVICE >> 8), /*13 bcdDevice*/.0x01, /*14 iManufacturer - index of string*/.0x02, /*15 iProduct - index of string*/.0x00, /*16 iSerialNumber - index of string*/.0x01 /*17 bNumConfigurations*/
/*USB Configuration Descriptor*/
static unsigned char cfgDesc[] = {
.0x09, /*0 bLength*/
.USB_DESCTYPE_CONFIGURATION, /*1 bDescriptorType - Configuration*/
.0xAE,00, /*2 wTotalLength*/
.0x02, /*4 bNumInterfaces*/
.0x01, /*5 bConfigurationValue*/
.0x03, /*6 iConfiguration - index of string*/
.0x80, /*7 bmAttributes - Bus powered*/
.0xFA, /*8 bMaxPower (in 2mA units) - 500mA*/
./*Interface Association Descriptor*/
.0x08, /*0 bLength*/
.USB_DESCTYPE_INTERFACE_ASSOCIATION, /*1 bDescriptorType - Interface Association*/
.0x00, /*2 bFirstInterface - VideoControl i/f*/
.0x02, /*3 bInterfaceCount - 2 Interfaces*/
.USB_CLASS_VIDEO, /*4 bFunctionClass - Video Class*/
.USB_VIDEO_INTERFACE_COLLECTION, /*5 bFunctionSubClass - Video Interface Collection*/
.0x00, /*6 bFunctionProtocol - No protocol*/
.0x02, /*7 iFunction - index of string*/
./*Video Control (VC) Interface Descriptor*/
.0x09, /*0 bLength*/
.USB_DESCTYPE_INTERFACE, /*1 bDescriptorType - Interface*/
.0x00, /*2 bInterfaceNumber - Interface 0*/
.0x00, /*3 bAlternateSetting*/
.0x01, /*4 bNumEndpoints*/
.USB_CLASS_VIDEO, /*5 bInterfaceClass - Video Class*/
.USB_VIDEO_CONTROL, /*6 bInterfaceSubClass - VideoControl Interface*/
.0x00, /*7 bInterfaceProtocol - No protocol*/
.0x02, /*8 iInterface - Index of string (same as iFunction of IAD)*/
./*Class-specific VC Interface Header Descriptor*/
.0x0D, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VC_HEADER, /*2 bDescriptorSubType - HEADER*/
.0x10, 0x01, /*3 bcdUVC - Video class revision 1.1*/
.0x28, 0x00, /*5 wTotalLength - till output terminal*/
.WORD_CHARS(100000000), /*7 dwClockFrequency - 100MHz (Deprecated)*/
.0x01, /*11 bInCollection - One Streaming Interface*/
.0x01, /*12 baInterfaceNr - Number of the Streaming interface*/
./*Input Terminal (Camera) Descriptor - Represents the CCD sensor (Simulated here in this demo)*/
.0x12, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VC_INPUT_TERMINAL, /*2 bDescriptorSubType - INPUT TERMINAL*/
.0x01, /*3 bTerminalID*/
.0x01, 0x02, /*4 wTerminalType - ITT_CAMERA type (CCD Sensor)*/
.0x00, /*6 bAssocTerminal - No association*/
.0x00, /*7 iTerminal - Unused*/
.0x00, 0x00, /*8 wObjectiveFocalLengthMin - No optical zoom supported*/
.0x00, 0x00, /*10 wObjectiveFocalLengthMax - No optical zoom supported*/
.0x00, 0x00, /*12 wOcularFocalLength - No optical zoom supported*/
.0x03, /*14 bControlSize - 3 bytes*/
.0x00, 0x00, 0x00, /*15 bmControls - No controls are supported*/
./*Output Terminal Descriptor*/
.0x09, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VC_OUPUT_TERMINAL, /*2 bDescriptorSubType - OUTPUT TERMINAL*/
.0x02, /*3 bTerminalID*/
.0x01, 0x01, /*4 wTerminalType - TT_STREAMING type*/
.0x00, /*6 bAssocTerminal - No association*/
.0x01, /*7 bSourceID - Source is Input terminal 1*/
.0x00, /*8 iTerminal - Unused*/
./*Standard Interrupt Endpoint Descriptor*/
.0x07, /*0 bLength*/
.USB_DESCTYPE_ENDPOINT, /*1 bDescriptorType*/
.(VIDEO_STATUS_EP_NUM | 0x80), /*2 bEndpointAddress - IN endpoint*/
.0x03, /*3 bmAttributes - Interrupt transfer*/
.0x40, 0x00, /*4 wMaxPacketSize - 64 bytes*/
.0x09, /*6 bInterval - 2^(9-1) microframes = 32ms*/
./*Class-specific Interrupt Endpoint Descriptor*/
.0x05, /*0 bLength*/
.USB_DESCTYPE_CS_ENDPOINT, /*1 bDescriptorType - Class-specific Endpoint*/
.0x03, /*2 bDescriptorSubType - Interrupt Endpoint*/
.0x40, 0x00, /*3 wMaxTransferSize - 64 bytes*/
./*Video Streaming Interface Descriptor*/
./*Zero-bandwidth Alternate Setting 0*/
.0x09, /*0 bLength*/
.USB_DESCTYPE_INTERFACE, /*1 bDescriptorType - Interface*/
.0x01, /*2 bInterfaceNumber - Interface 1*/
.0x00, /*3 bAlternateSetting - 0*/
.0x00, /*4 bNumEndpoints - No bandwidth used*/
.USB_CLASS_VIDEO, /*5 bInterfaceClass - Video Class*/
.USB_VIDEO_STREAMING, /*6 bInterfaceSubClass - VideoStreaming Interface*/
.0x00, /*7 bInterfaceProtocol - No protocol*/
.0x00, /*8 iInterface - Unused*/
./*Class-specific VS Interface Input Header Descriptor*/
.0x0E, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VS_INPUT_HEADER, /*2 bDescriptorSubType - INPUT HEADER*/
.0x01, /*3 bNumFormats - One format supported*/
.0x47, 0x00, /*4 wTotalLength - Size of class-specific VS descriptors*/
.(VIDEO_DATA_EP_NUM | 0x80), /*6 bEndpointAddress - Iso EP for video streaming*/
.0x00, /*7 bmInfo - No dynamic format change*/
.0x02, /*8 bTerminalLink - Denotes the Output Terminal*/
.0x01, /*9 bStillCaptureMethod - Method 1 supported*/
.0x00, /*10 bTriggerSupport - No Hardware Trigger*/
.0x00, /*11 bTriggerUsage*/
.0x01, /*12 bControlSize - 1 byte*/
.0x00, /*13 bmaControls - No Controls supported*/
./*Class-specific VS Format Descriptor*/
.0x1B, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VS_FORMAT_UNCOMPRESSED, /*2 bDescriptorSubType - FORMAT UNCOMPRESSED*/
.0x01, /*3 bFormatIndex*/
.0x01, /*4 bNumFrameDescriptors - 1 Frame descriptor followed*/
.0x59,0x55,0x59,0x32,
.0x00,0x00,0x10,0x00,
.0x80,0x00,0x00,0xAA,
.0x00,0x38,0x9B,0x71, /*5 guidFormat - YUY2 Video format*/
.BITS_PER_PIXEL, /*21 bBitsPerPixel - 16 bits*/
.0x01, /*22 bDefaultFrameIndex*/
.0x00, /*23 bAspectRatioX*/
.0x00, /*24 bAspectRatioY*/
.0x00, /*25 bmInterlaceFlags - No interlaced mode*/
.0x00, /*26 bCopyProtect - No restrictions on duplication*/
./*Class-specific VS Frame Descriptor*/
.0x1E, /*0 bLength*/
.USB_DESCTYPE_CS_INTERFACE, /*1 bDescriptorType - Class-specific Interface*/
.USB_VS_FRAME_UNCOMPRESSED, /*2 bDescriptorSubType*/
.0x01, /*3 bFrameIndex*/
.0x01, /*4 bmCapabilities - Still image capture method 1*/
.SHORT_CHARS(WIDTH), /*5 wWidth - 480 pixels*/
.SHORT_CHARS(HEIGHT), /*7 wHeight - 320 pixels*/
.WORD_CHARS(MIN_BIT_RATE), /*9 dwMinBitRate*/
.WORD_CHARS(MAX_BIT_RATE), /*13 dwMaxBitRate*/
.WORD_CHARS(MAX_FRAME_SIZE), /*17 dwMaxVideoFrameBufSize*/
.WORD_CHARS(FRAME_INTERVAL), /*21 dwDefaultFrameInterval (in 100ns units)*/
.0x01, /*25 bFrameIntervalType*/
.WORD_CHARS(FRAME_INTERVAL), /*26 dwFrameInterval (in 100ns units)*/
./*Video Streaming Interface Descriptor*/
./*Alternate Setting 1*/
.0x09, /*0 bLength*/
.USB_DESCTYPE_INTERFACE, /*1 bDescriptorType - Interface*/
.0x01, /*2 bInterfaceNumber - Interface 1*/
.0x01, /*3 bAlternateSetting - 1*/
.0x01, /*4 bNumEndpoints*/
.USB_CLASS_VIDEO, /*5 bInterfaceClass - Video Class*/
.USB_VIDEO_STREAMING, /*6 bInterfaceSubClass - VideoStreaming Interface*/
.0x00, /*7 bInterfaceProtocol - No protocol*/
.0x00, /*8 iInterface - Unused*/
./*Standard VS Isochronous Video Data Endpoint Descriptor*/
.0x07, /*0 bLength*/
.USB_DESCTYPE_ENDPOINT, /*1 bDescriptorType*/
.(VIDEO_DATA_EP_NUM | 0x80), /*2 bEndpointAddress - IN Endpoint*/
.0x05, /*3 bmAttributes - Isochronous EP (Asynchronous)*/
.0x00, 0x04, /*4 wMaxPacketSize 1x 1024 bytes*/
.0x01, /*6 bInterval*/
配置描述符告诉主机设备的电源需求及其支持的接口数量。多个接口一起提供视频功能。这组接口称为视频接口集合。视频接口集合由接口关联描述符(IAD)描述。在示例应用程序中,IAD定义接口0和1分组以形成USB视频设备。这两个接口是:视频控制接口(VC接口)视频流接口(VS接口)注:视频功能必须有一个视频控制接口和零个或多个视频流接口。
沒有留言:
張貼留言