在模拟uvc设备时遇到一些问题,希望大佬帮忙解解惑

2022-09-28 16:38:40 编辑

目前在模拟一个摄像头,遇到了一些问题,在win10和win11自带的相机软件可以正常显示图像,但是第三方的软件在调用摄像头时黑屏无显示,通过分析仪抓包可以看到数据在正常上传,并且在部分电脑上自带的相机软件也显示黑屏。
上传图片为一张静态图片,图片转为二进制存在单片机内,一个sof传1024KB数据,修改传包间隔没有效果,不知道从什么地方下手,希望大佬帮忙解解惑

设备描述符如下:

  1. /*---------------------------------------------------------------------------*/
  2. 0x12, /* bLength */
  3. 0x01, /* bDescriptorType */
  4. 0x00, /* bcdUSB */
  5. 0x02,
  6. 0xEF, /* bDeviceClass */
  7. 0x02, /* bDeviceSubClass */
  8. 0x01, /* bDeviceProtocol */
  9. 0x40, /* bMaxPacketSize*/
  10. LOBYTE(DEF_USB_VID), /* idVendor */
  11. HIBYTE(DEF_USB_VID), /* idVendor */
  12. LOBYTE(DEF_USB_PID), /* idVendor */
  13. HIBYTE(DEF_USB_PID), /* idVendor */
  14. 0x00, /* bcdDevice rel. 2.00 */
  15. 0x02,
  16. 0x00, /* Index of manufacturer string */
  17. 0x00, /* Index of product string */
  18. 0x00, /* Index of serial number string */
  19. 0x01 /* bNumConfigurations */
  20. /*---------------------------------------------------------------------------*/
  21. 配置描述符如下:
  22. /*---------------------------------------------------------------------------*/
  23. /*Configuration Descriptor*/
  24. 0x09, /* bLength: Configuation Descriptor size */
  25. 0x02, /* bDescriptorType: Configuration */
  26. LOBYTE(USB_UVC_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
  27. HIBYTE(USB_UVC_CONFIG_DESC_SIZ),
  28. 0x02, /*bNumInterfaces: 2 interface*/
  29. 0x01, /*bConfigurationValue: Configuration value*/
  30. 0x04, /*iConfiguration: Index of string descriptor describing the configuration*/
  31. 0x80, /*bmAttributes: bus powered device */
  32. 0xFA, /*MaxPower 500 mA: this current is used for detecting Vbus*/
  33. /* 09 */
  34. /*---------------------------------------------------------------------------*/
  35. /*Interface Association Descriptor*/
  36. 0x08, /* bLength: Interface Association Descriptor size */
  37. 0x0B, /* bDescritorType: Interface Association */
  38. 0x00, /* bFirstInterface: VideoControl Interface ID */
  39. 0x02, /* bInterfaceCount: 2 Video Interface */
  40. 0x0E, /* bFunctionClass: CC_VIDEO */
  41. 0x03, /* bFunctionSubClass: SC_VIDEO_INTERFACE_COLLECTION */
  42. 0x00, /* bFunctionProtocol: PC_PROTOCOL_UNDEFINED */
  43. USBD_IDX_INTERFACE_STR, /* iFunction: Index of string descriptor descripting the function */
  44. /*Standard VC Interface Descriptor*/
  45. 0x09, /* bLenght: Standard VC Interface Descriptor size */
  46. 0x04, /*bDescriptorType: interface */
  47. 0x00, /* bInterfaceNumber: interface ID */
  48. 0x00, /* bAlternateSetting: Alternate setting */
  49. 0x00, /* bNumEndpoints: no endpoint */
  50. 0x0E, /* bInterfaceClass: CC_VIDEO */
  51. 0x01, /* bInterfaceSubClass: SC_VIDEOCONTROL */
  52. 0x00, /* bInterfacePortocol: PC_PROTOCOL_15 */
  53. USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
  54. /*Class-specific VC Interface Header Descriptor*/
  55. 0x0D, /* bLength: Class-specific VC Interface Header Descriptor size */
  56. 0x24, /* bDescriptorType: CS_INTERFACE */
  57. 0x01, /* bDescriptorSubType: VC_HEADER */
  58. 0x10, /* bcdUVC: UVC1.5 revision */
  59. 0x01,
  60. 0x27, /* wTotalLength: total size of class-specific descriptors */
  61. 0x00,
  62. 0x80, /* dwClockFrequency: deprecated */
  63. 0x8D,
  64. 0x5B,
  65. 0x00,
  66. 0x01, /* bInCollection: number of streaming interfaces */
  67. 0x01, /* baInterfaceNr(1): VideoStreaming interface 1 belongs to VC interface */
  68. /*Input Terminal Descriptor Composite*/
  69. 0x11, /* bLength: Input Terminal Descriptor size */
  70. 0x24, /* bDescriptorType: CS_INTERFACE */
  71. 0x02, /* bDescriptorSubType: VC_INPUT_TERMINAL */
  72. 0x01, /* bTerminalID: Terminal ID */
  73. 0x01, /* wTerminalType: ITT_CAMERA */
  74. 0x02,
  75. 0x00, /* bAssocTerminal: no association */
  76. 0x00, /*iTerminal: index of string descriptor descripting the terminal */
  77. 0x00, /* wObjectiveFocalLengthMin: No optical zoom supported */
  78. 0x00,
  79. 0x00, /* wObjectiveFocalLengthMax: No optical zoom supported */
  80. 0x00,
  81. 0x00, /* wOcularFocalLength: No optical zoom supported */
  82. 0x00,
  83. 0x02, /* bControlSize: this terminal doesn't implement any controls */
  84. 0x00, /* bmControls: No controls are supported */
  85. 0x00,
  86. /*Output Terminal Descriptor*/
  87. 0x09, /* bLength: Output Terminal Descriptor size */
  88. 0x24, /* bDescriptorType: CS_INTERFACE */
  89. 0x03, /* bDescriptorSubType: VC_OUTPUT_TERMINAL */
  90. 0x02, /* bTerminalID: Terminal ID */
  91. 0x01, /* wTerminalType: TT_STREAMING */
  92. 0x01,
  93. 0x00, /* bAssocTerminal: no association */
  94. 0x01, /* bSourceID: connect to the input terminal output pin */
  95. 0x00, /*iTerminal: index of string descriptor descripting the terminal */
  96. /*---------------------------------------------------------------------------*/
  97. /*Standard VS Interface Alternate 0 setting Descriptor*/
  98. 0x09, /* bLength: Standard VS Interface Descriptor size */
  99. USB_DESC_TYPE_INTERFACE, /* bDescriptorType: INTERFACE */
  100. 0x01, /* bInterfaceNumber: Interface ID */
  101. 0x00, /* bAlternateSetting: index of this alternate setting */
  102. 0x00, /* bNumEndpoints: 0 endpoint */
  103. 0x0E, /* bInterfaceClass: CC_VIDEO */
  104. 0x02, /* bInterfaceSubClass: SC_VIDEOSTREAMING */
  105. 0x00, /* bInterfaceProtocol: PC_PROTOCOL_15 */
  106. USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
  107. /*Class-specific VS Header Descriptor*/
  108. 0x0E, /* bLength: Class-specific VS Header Descriptor size */
  109. 0x24, /* bDescriptorType: CS_INTERFACE */
  110. 0x01, /* bDescriptorSubType: VS_INPUT_HEADER */
  111. 0x01, /* bNumFormats: one format descriptor follows */
  112. 0x3F,//0x45, /* wTotalLength: Total size of class-specific VS interface descriptors */
  113. 0x00,
  114. UVC_ISO_DATA_EP, /* bEndpointAddress: address of isochronour video data endpoint */
  115. 0x00, /* bmInfo: no dynamic format change supported */
  116. 0x02, /* bTerminalLink: the terminal ID of output Terminal */
  117. 0x00, /* bStillCaptureMethod: no supports still image capture method */
  118. 0x00, /* bTriggerSupport: no supports hardware trigger */
  119. 0x00, /* bTriggerUsage: initiate still image capture */
  120. 0x01, /* bControlSize: the size of bmaControls field */
  121. 0x00, /* bmaControls: no VS specific controls are supported */
  122. /*Payload Format Descriptor*/
  123. 0x0B, /* blength: Payload Format Descriptor size */
  124. 0x24, /* bDescriptorType: CS_INTERFACE */
  125. 0x06, /* bDescriptorSubType: VS_FORMAT_MJPEG */
  126. 0x01, /* bFormatIndex: index of the format descriptor */
  127. 0x01, /* bNumFrameDescriptor: number of frame descriptors */
  128. 0x01, /* bmFlags: FixedSizeSamples */
  129. 0x01, /* bDefaultFrameIndex: */
  130. 0x00, /* bAspectRatioX: not required */
  131. 0x00, /* bAspectRatioY: not required */
  132. 0x00, /* bInterlaceFlags: non-interlaced stream */
  133. 0x00, /* bCopyProtect: no restrictions */
  134. /*Class-specific VS Frame Descriptor*/
  135. 0x26, /* bLength: Class-specific VS Frame Descriptor size */
  136. 0x24, /* bDescriptorType: CS_INTERFACE */
  137. 0x07, /* bDescriptorSubType: VS_FRAME_MJPEG */
  138. 0x01, /* bFrameIndex: index of frame descriptor */
  139. 0x03, /* bmCapabilities:still image capture method 0 supported,fixed frame-rate */
  140. LOBYTE(width), /* wWidth: frame width */
  141. HIBYTE(width),
  142. LOBYTE(hight), /* wHeight: frame height */
  143. HIBYTE(hight),
  144. 0x00, /* dwMinBitRate: */
  145. 0xB0,
  146. 0x04,
  147. 0x00,
  148. 0x00, /* dwMaxBitRate: */
  149. 0x00,
  150. 0x4B,
  151. 0x00,
  152. 0x00, /* dwMaxVideoFrameBufSize: in bytes */
  153. 0xA0,
  154. 0x00,
  155. 0x00,
  156. 0x2A, /* dwDefaultFrameInterval: */
  157. 0x2C,
  158. 0x0A,
  159. 0x00,
  160. 0x00, /* bFrameIntervalType: Continuous frame interval */
  161. 0x2A, /* dwMinFrameInterval: */
  162. 0x2C,
  163. 0x0A,
  164. 0x00,
  165. 0x2A, /* dwMaxFrameInterval: */
  166. 0x2C,
  167. 0x0A,
  168. 0x00,
  169. 0x00, /* dwFrameIntervalSetp: no frame interval step supported */
  170. 0x00,
  171. 0x00,
  172. 0x00,
  173. /*---------------------------------------------------------------------------*/
  174. /*Standard VS Interface Alternate setting 1 Descriptor*/
  175. 0x09, /* bLength: Standard VS Interface Descriptor size */
  176. USB_DESC_TYPE_INTERFACE, /* bDescriptorType: INTERFACE */
  177. 0x01, /* bInterfaceNumber: Interface ID */
  178. 0x01, /* bAlternateSetting: index of this alternate setting */
  179. 0x01, /* bNumEndpoints: 1 endpoint */
  180. 0x0E, /* bInterfaceClass: CC_VIDEO */
  181. 0x02, /* bInterfaceSubClass: SC_VIDEOSTREAMING */
  182. 0x00, /* bInterfaceProtocol: PC_PROTOCOL_15 */
  183. USBD_IDX_INTERFACE_STR, /*iInterface: Index of string descriptor descripting the interface */
  184. /*Endpoint Descriptor*/
  185. 0x07, /* bLength: Endpoint Descriptor size */
  186. 0x05, /* bDescriptorType: ENDPOINT */
  187. UVC_ISO_DATA_EP, /* bEndpointAddress: address of isochronour video data endpoint */
  188. 0x05, /* bmAttributes: Isochronous transfer Asynchronous data type */
  189. LOBYTE(UVC_ISO_DATA_PACKET_SIZE), /* wMaxPacketSize: */
  190. HIBYTE(UVC_ISO_DATA_PACKET_SIZE),
  191. 0x01, /* bInterval: */
  192. /********** Descriptor of UVC interface 0 Alternate setting 0 **************/
USB中文网 2022-09-28 16:45:26 编辑
  • 用BUSHOUND抓包看一下数据传输的过程 - 主要看负载数据头
  • 打开摄像头的VS_COMMIT_CONTROL的数据- 分析数据传输的格式是否正确

应该还是数据的问题,只是不同的应用软件兼容性好一些

2022-09-28 16:51:23 编辑

因为传输静态图片不涉及时钟,所以负载头都是0c 0c传输完成变成0c 0e,下一包的负载头变成0c 0d和0c 0f,然后这样来回翻转

2022-09-29 11:19:43 编辑

我又尝试了一下,我发现确实应该是数据问题,关于UVC数据上报这部分,有什么协议规范或者具体要求的文档描述么

USB中文网 2022-09-29 19:23:13 编辑

主要是查看负载数据头是否正确。如果负载数据头正确,你可以把负载数据头剔除掉,将剩下的数据存存起来,会是一张完整的图片。按指定格式打开。QQ群里有指定格式打开工具。像YUV2,NV12等,JPG的直接换成JPG扩展名主可以用图形工具打开。
负载数据头请参考:https://www.usbzh.com/article/detail-7.html