在模拟uvc设备时遇到一些问题,希望大佬帮忙解解惑
目前在模拟一个摄像头,遇到了一些问题,在win10和win11自带的相机软件可以正常显示图像,但是第三方的软件在调用摄像头时黑屏无显示,通过分析仪抓包可以看到数据在正常上传,并且在部分电脑上自带的相机软件也显示黑屏。
上传图片为一张静态图片,图片转为二进制存在单片机内,一个sof传1024KB数据,修改传包间隔没有效果,不知道从什么地方下手,希望大佬帮忙解解惑
设备描述符如下:
/*---------------------------------------------------------------------------*/
0x12, /* bLength */
0x01, /* bDescriptorType */
0x00, /* bcdUSB */
0x02,
0xEF, /* bDeviceClass */
0x02, /* bDeviceSubClass */
0x01, /* bDeviceProtocol */
0x40, /* bMaxPacketSize*/
LOBYTE(DEF_USB_VID), /* idVendor */
HIBYTE(DEF_USB_VID), /* idVendor */
LOBYTE(DEF_USB_PID), /* idVendor */
HIBYTE(DEF_USB_PID), /* idVendor */
0x00, /* bcdDevice rel. 2.00 */
0x02,
0x00, /* Index of manufacturer string */
0x00, /* Index of product string */
0x00, /* Index of serial number string */
0x01 /* bNumConfigurations */
/*---------------------------------------------------------------------------*/
配置描述符如下:
/*---------------------------------------------------------------------------*/
/*Configuration Descriptor*/
0x09, /* bLength: Configuation Descriptor size */
0x02, /* bDescriptorType: Configuration */
LOBYTE(USB_UVC_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
HIBYTE(USB_UVC_CONFIG_DESC_SIZ),
0x02, /*bNumInterfaces: 2 interface*/
0x01, /*bConfigurationValue: Configuration value*/
0x04, /*iConfiguration: Index of string descriptor describing the configuration*/
0x80, /*bmAttributes: bus powered device */
0xFA, /*MaxPower 500 mA: this current is used for detecting Vbus*/
/* 09 */
/*---------------------------------------------------------------------------*/
/*Interface Association Descriptor*/
0x08, /* bLength: Interface Association Descriptor size */
0x0B, /* bDescritorType: Interface Association */
0x00, /* bFirstInterface: VideoControl Interface ID */
0x02, /* bInterfaceCount: 2 Video Interface */
0x0E, /* bFunctionClass: CC_VIDEO */
0x03, /* bFunctionSubClass: SC_VIDEO_INTERFACE_COLLECTION */
0x00, /* bFunctionProtocol: PC_PROTOCOL_UNDEFINED */
USBD_IDX_INTERFACE_STR, /* iFunction: Index of string descriptor descripting the function */
/*Standard VC Interface Descriptor*/
0x09, /* bLenght: Standard VC Interface Descriptor size */
0x04, /*bDescriptorType: interface */
0x00, /* bInterfaceNumber: interface ID */
0x00, /* bAlternateSetting: Alternate setting */
0x00, /* bNumEndpoints: no endpoint */
0x0E, /* bInterfaceClass: CC_VIDEO */
0x01, /* bInterfaceSubClass: SC_VIDEOCONTROL */
0x00, /* bInterfacePortocol: PC_PROTOCOL_15 */
USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
/*Class-specific VC Interface Header Descriptor*/
0x0D, /* bLength: Class-specific VC Interface Header Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubType: VC_HEADER */
0x10, /* bcdUVC: UVC1.5 revision */
0x01,
0x27, /* wTotalLength: total size of class-specific descriptors */
0x00,
0x80, /* dwClockFrequency: deprecated */
0x8D,
0x5B,
0x00,
0x01, /* bInCollection: number of streaming interfaces */
0x01, /* baInterfaceNr(1): VideoStreaming interface 1 belongs to VC interface */
/*Input Terminal Descriptor Composite*/
0x11, /* bLength: Input Terminal Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubType: VC_INPUT_TERMINAL */
0x01, /* bTerminalID: Terminal ID */
0x01, /* wTerminalType: ITT_CAMERA */
0x02,
0x00, /* bAssocTerminal: no association */
0x00, /*iTerminal: index of string descriptor descripting the terminal */
0x00, /* wObjectiveFocalLengthMin: No optical zoom supported */
0x00,
0x00, /* wObjectiveFocalLengthMax: No optical zoom supported */
0x00,
0x00, /* wOcularFocalLength: No optical zoom supported */
0x00,
0x02, /* bControlSize: this terminal doesn't implement any controls */
0x00, /* bmControls: No controls are supported */
0x00,
/*Output Terminal Descriptor*/
0x09, /* bLength: Output Terminal Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x03, /* bDescriptorSubType: VC_OUTPUT_TERMINAL */
0x02, /* bTerminalID: Terminal ID */
0x01, /* wTerminalType: TT_STREAMING */
0x01,
0x00, /* bAssocTerminal: no association */
0x01, /* bSourceID: connect to the input terminal output pin */
0x00, /*iTerminal: index of string descriptor descripting the terminal */
/*---------------------------------------------------------------------------*/
/*Standard VS Interface Alternate 0 setting Descriptor*/
0x09, /* bLength: Standard VS Interface Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: INTERFACE */
0x01, /* bInterfaceNumber: Interface ID */
0x00, /* bAlternateSetting: index of this alternate setting */
0x00, /* bNumEndpoints: 0 endpoint */
0x0E, /* bInterfaceClass: CC_VIDEO */
0x02, /* bInterfaceSubClass: SC_VIDEOSTREAMING */
0x00, /* bInterfaceProtocol: PC_PROTOCOL_15 */
USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
/*Class-specific VS Header Descriptor*/
0x0E, /* bLength: Class-specific VS Header Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubType: VS_INPUT_HEADER */
0x01, /* bNumFormats: one format descriptor follows */
0x3F,//0x45, /* wTotalLength: Total size of class-specific VS interface descriptors */
0x00,
UVC_ISO_DATA_EP, /* bEndpointAddress: address of isochronour video data endpoint */
0x00, /* bmInfo: no dynamic format change supported */
0x02, /* bTerminalLink: the terminal ID of output Terminal */
0x00, /* bStillCaptureMethod: no supports still image capture method */
0x00, /* bTriggerSupport: no supports hardware trigger */
0x00, /* bTriggerUsage: initiate still image capture */
0x01, /* bControlSize: the size of bmaControls field */
0x00, /* bmaControls: no VS specific controls are supported */
/*Payload Format Descriptor*/
0x0B, /* blength: Payload Format Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubType: VS_FORMAT_MJPEG */
0x01, /* bFormatIndex: index of the format descriptor */
0x01, /* bNumFrameDescriptor: number of frame descriptors */
0x01, /* bmFlags: FixedSizeSamples */
0x01, /* bDefaultFrameIndex: */
0x00, /* bAspectRatioX: not required */
0x00, /* bAspectRatioY: not required */
0x00, /* bInterlaceFlags: non-interlaced stream */
0x00, /* bCopyProtect: no restrictions */
/*Class-specific VS Frame Descriptor*/
0x26, /* bLength: Class-specific VS Frame Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x07, /* bDescriptorSubType: VS_FRAME_MJPEG */
0x01, /* bFrameIndex: index of frame descriptor */
0x03, /* bmCapabilities:still image capture method 0 supported,fixed frame-rate */
LOBYTE(width), /* wWidth: frame width */
HIBYTE(width),
LOBYTE(hight), /* wHeight: frame height */
HIBYTE(hight),
0x00, /* dwMinBitRate: */
0xB0,
0x04,
0x00,
0x00, /* dwMaxBitRate: */
0x00,
0x4B,
0x00,
0x00, /* dwMaxVideoFrameBufSize: in bytes */
0xA0,
0x00,
0x00,
0x2A, /* dwDefaultFrameInterval: */
0x2C,
0x0A,
0x00,
0x00, /* bFrameIntervalType: Continuous frame interval */
0x2A, /* dwMinFrameInterval: */
0x2C,
0x0A,
0x00,
0x2A, /* dwMaxFrameInterval: */
0x2C,
0x0A,
0x00,
0x00, /* dwFrameIntervalSetp: no frame interval step supported */
0x00,
0x00,
0x00,
/*---------------------------------------------------------------------------*/
/*Standard VS Interface Alternate setting 1 Descriptor*/
0x09, /* bLength: Standard VS Interface Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: INTERFACE */
0x01, /* bInterfaceNumber: Interface ID */
0x01, /* bAlternateSetting: index of this alternate setting */
0x01, /* bNumEndpoints: 1 endpoint */
0x0E, /* bInterfaceClass: CC_VIDEO */
0x02, /* bInterfaceSubClass: SC_VIDEOSTREAMING */
0x00, /* bInterfaceProtocol: PC_PROTOCOL_15 */
USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
/*Endpoint Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
0x05, /* bDescriptorType: ENDPOINT */
UVC_ISO_DATA_EP, /* bEndpointAddress: address of isochronour video data endpoint */
0x05, /* bmAttributes: Isochronous transfer Asynchronous data type */
LOBYTE(UVC_ISO_DATA_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(UVC_ISO_DATA_PACKET_SIZE),
0x01, /* bInterval: */
/********** Descriptor of UVC interface 0 Alternate setting 0 **************/
- 用BUSHOUND抓包看一下数据传输的过程 - 主要看负载数据头
- 打开摄像头的VS_COMMIT_CONTROL的数据- 分析数据传输的格式是否正确
应该还是数据的问题,只是不同的应用软件兼容性好一些
主要是查看负载数据头是否正确。如果负载数据头正确,你可以把负载数据头剔除掉,将剩下的数据存存起来,会是一张完整的图片。按指定格式打开。QQ群里有指定格式打开工具。像YUV2,NV12等,JPG的直接换成JPG扩展名主可以用图形工具打开。
负载数据头请参考:https://www.usbzh.com/article/detail-7.html