UVC摄像头USB批量传输BULK数据传输方式的打开与关闭StreamOn StreamOff
2023-02-14
977
0
USB的批量传输和中断传输是一样的简单,但经常发现有人在问批量传输的UVC摄像头的打开与半闭问题的边界问题,特别是摄像头关闭的判断。
BULK摄像头的打开
我们通过BUSHOUND抓包的内容如下:
Device Length Phase Data Description
------ -------- ----- ------------------------------------------------------------------------------------------------------ --------------
42.0 CTL a1 81 00 01 01 00 22 00 GET CUR
42.0 34 IN 01 00 01 01 15 16 05 00 00 00 00 00 00 00 00 00 00 00 00 a4 1f 00 0c 48 3f 00 00 00 00 00 03 01 ..............
42.0 CTL 21 01 00 01 01 00 22 00 SET CUR
42.0 34 OUT 01 00 02 02 15 16 05 00 00 00 00 00 00 00 00 00 00 00 00 a4 1f 00 00 00 00 00 00 00 00 00 03 01 ..............
42.0 CTL a1 81 00 01 01 00 22 00 GET CUR
42.0 34 IN 01 00 02 02 15 16 05 00 00 00 00 00 00 00 00 00 00 00 00 90 7e 00 0c c8 00 00 00 00 00 00 03 01 ..............
42.0 CTL a1 83 00 01 01 00 22 00 GET MAX
42.0 34 IN 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..............
42.0 CTL a1 82 00 01 01 00 22 00 GET MIN
42.0 34 IN 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..............
42.0 CTL 21 01 00 02 01 00 22 00 SET CUR
42.0 34 OUT 01 00 02 02 15 16 05 00 00 00 00 00 00 00 00 00 00 00 00 90 7e 00 0c c8 00 00 00 00 00 00 03 01 ..............
42.0 CTL 01 0b 00 00 01 00 00 00 SET INTERFACE
42.1 51200 IN 0c 80 00 00 00 00 00 00 00 00 00 00 00 00 00 01 40 01 0c 01 ff ff 01 60 00 00 03 00 00 03 00 00 ..............
可以看到,通过复杂的UVC特定类请求GET_CUR,SET_CUR等,最终VS_PROBE_CONTROLL/VS_COMMIT_CONTROL之后,然后SET_INTERFACE之后,通过BULK端点0x81获取到了数据。
关于其具体的类似分析可参见:https://www.usbzh.com/article/detail-105.html
而通过南京沁恒的USB总线分析仪USB2.0 Monior抓到的数据类示:
BULK摄像头的关闭
通过BUSHOUND抓到的BULK数据传输的关闭摄像头的内容如下:
42.1 45388 IN 0c 83 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 01 d0 00 2d c4 0e e0 8b 42 8e f3 ef d8 f2 2f
42.0 CTL 01 0b 00 00 01 00 00 00 SET INTERFACE
可以看到就是简单的SET_INTERFACE,但是通过USB总线分析仪就是再是这么简单了:
可以看到,这里的关键点其实是:
02 01 00 00 81 00 00 00
0x02, // bmRequestType: Dir: H2D, Type: Standard, Recipient: Endpoint
0x01, // bRequest (Clear Feature)
0x00, 0x00, // wValue Feature Selector: 0
0x81, 0x00, // wIndex Endpoint: 0x81 (IN/D2H)
0x00, 0x00, // wLength = 0
// 8 bytes
可以看到,其对应的是CLEAR_FEATURE,对比USB 清除特性请求ClearFeature https://www.usbzh.com/article/detail-89.html 一文可知:
这是对于端点的停止特性ENDPOINT_HALT.
所以这也证明了,BUSHOUND抓到的包并不一定是USB总线上的数据包,但大部分是。只是因为其所在的层次不同,故数据不同。
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936