Android/linux从usb声卡获取音频(使用libusb库)---环境,lsusb命令的介绍(一)
Android/linux从usb声卡获取音频(使用libusb库)---设备环境的确认(二)
Android/linux从usb声卡获取音频(使用libusb库)---libusb库获取“纯麦”音频数据(三)
Android/linux从usb声卡获取音频(使用libusb库)---libusb库获取“纯麦”音频数据,附(四)
Android/linux从usb声卡获取音频(使用libusb库)---监听“纯麦”(五)
上一篇demo源码中有好些个参数,是和设备相关的,怎么获取这些参数信息,就要通过lsusb 了,lsusb列出的具体信息的含义,参照一篇:https://www.cnblogs.com/Daniel-G/p/3993904.html 感谢,找了好久。(毕竟不熟悉USB协议)
这里对应解释一下 JMTek设备的信息:
root@can-virtual-machine:/work/test/libusb/libusb-1.0.22# lsusb -D /dev/bus/usb/002/006
Device: ID 0c76:1915 JMTek, LLC.
Device Descriptor: 设备描述符
bLength 18 //描述符的长度,指的是usb设备返回过来的数据 18个字节
bDescriptorType 1 //描述符类型,有很多描述符类型,描述不同属性,1 是设备描述符
bcdUSB 1.10 //usb协议版本号, 1.10
bDeviceClass 0 (Defined at Interface level) //usb设备类代码 https://www.cnblogs.com/Daniel-G/p/3993904.html 如果该字段为0x00,表示由接口描述符来指定(有可能该USB设备是一个复合设备,USB设备的各个接口相互独立,分别属于不同的设备类)。如果是0x01~0xfe,表示为USB-IF定义的设备类,例如0x03为HID设备,0x09为HUB设备。如果是0xff,表示由厂商自定义设备类型。
bDeviceSubClass 0 USB子类代码,由USB-IF分配,如果bDeviceClass为0x00,那么该字段也必须为 0x00,其它情况可以参考USB关于对于USB Device Class的定义。
bDeviceProtocol 0 协议代码,由USB-IF分配,如果bDeviceClass和bDeviceSubClass定义为0x00,那么该字段也必须为0x00。
bMaxPacketSize0 64 端点0最大数据包长度,必须为8、16、32和64。
idVendor 0x0c76 JMTek, LLC.
idProduct 0x1915
bcdDevice 1.00 设备序列号,由厂商自行设置。
iManufacturer 1 www.loostone.com 用于描述厂商的字符串描述符索引
iProduct 2 Loostone PureMic U7-K 用于描述产品的字符串描述符索引。
iSerial 3 6C7756745D75 用于描述产品序列号的字符串描述符索引,注意,所有的字符串描述符是可选的,如果没有字符串描述符,指定这些索引为0x00。
bNumConfigurations 1 配置描述符数量
Configuration Descriptor: 一个USB设备只有一个USB设备描述符,可以有多个配置描述符
bLength 9 配置描述符长度,配置描述符长度为9字节大小。
bDescriptorType 2 描述符类型,配置描述符类型为0x02。
wTotalLength 145 配置描述符信息总的大小,包括接口描述符、端点描述符等等。
bNumInterfaces 3 USB接口数量。
bConfigurationValue 1 当使用SetConfiguration和GetConfiguration请求时所指定的配置索引值。
iConfiguration 0 描述配置的字符串描述符索引。
bmAttributes 0x80 供电配置,位详细定义如下:
D7 保留,必须置1
D6 自供电模式
D5 远程唤醒
D4~D0 保留
(Bus Powered)
MaxPower 100mA 最大功耗
Interface Descriptor:一个配置中可以有一个或多个接口,一个接口中有0个或多个端点,接口描述符和端点描述符不能直接通过GetDescriptor请求返回,必须连同配置描述符一起返回
bLength 9 描述符长度,接口描述符长度为9个字节。
bDescriptorType 4 描述符类型,接口描述符的类型为0x04。
bInterfaceNumber 0 该接口编号,接口编号从0开始分配,当一个配置有多个接口时,就用该字段来区分不同的接口。
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 47
bInCollection 1
baInterfaceNr( 0) 1
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0205 Microphone Array
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 0
iTerminal 0
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 18
wTerminalType 0x0101 USB Streaming
bAssocTerminal 2
bSourceID 33
iTerminal 0
AudioControl Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 5 (SELECTOR_UNIT)
bUnitID 33
bNrInPins 1
baSource( 0) 50
iSelector 0
AudioControl Interface Descriptor:
bLength 10
bDescriptorType 36
bDescriptorSubtype 6 (FEATURE_UNIT)
bUnitID 50
bSourceID 2
bControlSize 1
bmaControls( 0) 0x03
Mute Control
Volume Control
bmaControls( 1) 0x00
bmaControls( 2) 0x00
iFeature 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 0
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 18
bDelay 1 frames
wFormatTag 1 PCM
AudioStreaming Interface Descriptor:
bLength 14
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 2 Discrete
tSamFreq[ 0] 48000
tSamFreq[ 1] 44100
Endpoint Descriptor://audio 设备端点
bLength 9 描述符长度,这里有两个值如果是audio设备的端点,那么端点描述符长度就为9个字节,对于其它设备端点,端点描述符长度就为7个字
bDescriptorType 5 描述符类型,端点描述符类型为0x05
bEndpointAddress 0x82 EP 2 IN 端点地址
bmAttributes 5 端点类型
Transfer Type Isochronous 同步传输
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x00c8 1x 200 bytes 端点所支持最大数据包的长度
bInterval 1 端点数据传输的访问时间间隔。对于全速/低速的中断端点,取值范围为 1~255,对于高速中断端点,取值范围为1~16 1ms
bRefresh 0
bSynchAddress 0
AudioControl Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 0 Undefined
wLockDelay 0 Undefined
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.00
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 234
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0004 1x 4 bytes
bInterval 32
Device Status: 0x0000
(Bus Powered)
所以上面几个重要的信息:
#define VID 0x0c76
#define PID 0x1915
#define EP_ISO_IN 0x82 //端点地址
#define IFACE_NUM 1 //usb “接口”编号 Configuration Descriptor: 中的bNumInterfaces 值表示该配置中接口数量,每一个配置中的接口有自己的接口编号 bInterfaceNumber
#define PACKET_SIZE 192 //lsusb 列出来的这个传输最大支持 200
附上一个usb协议传输的博客链接:usb中的endpoint(端点)和传输模式