AVCaptureDevice的USB接口

nhhxz33t  于 2023-10-16  发布在  其他
关注(0)|答案(2)|浏览(131)

如果我有AVCaptureDevice,我如何获得相关的USB接口,以便通过IOKit访问底层硬件?
我试过通过vid & pid查找它,但如果我插入两个具有相同vid,pid的设备,这将不起作用。下面是我用来从AVCaptureDevice中提取vid和pid的代码:

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithDeviceType:AVMediaTypeVideo];
NSString *modelID = [device modelID];

NSRange vidRange = [modelID rangeOfString:@"VendorID_"];
int vid = [[modelID substringWithRange:NSMakeRange(vidRange.location + 9, 5)] intValue];

NSRange pidRange = [modelID rangeOfString:@"ProductID_"];
int vid = [[modelID substringWithRange:NSMakeRange(pidRange.location + 10, 5)] intValue];

然后我搜索匹配的IOService:

CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
CFNumberRef numberRef;

numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vid);
CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorID), numberRef);
CFRelease(numberRef);

numberRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pid);
CFDictionarySetValue(matchingDict, CFSTR(kUSBProductID), numberRef);
CFRelease(numberRef);

io_service_t camera = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
aurhwmvo

aurhwmvo1#

也许AVCaptureDevicemodelIDuniqueID的组合可以帮助您找到匹配的IOService。这两个ID的格式看起来既没有文档记录,又依赖于传输和媒体类型,但是您应该能够弄清楚一些事情。以下是USB音频的初步Map(因为我没有任何USB摄像头),基于两个设备:

modelID: USB Headphone Set:0C76:1607
uniqueID: AppleUSBAudioEngine:Unknown Manufacturer:USB Headphone Set:14200000:2,1,
    USB Headphone Set:

    Product ID: 0x1607
    Vendor ID:  0x0c76  (Solid State System Co., Ltd.)
Version:    1.00
Speed:  Up to 12 Mb/sec
    Location ID:    0x14200000 / 9
    Current Available (mA): 1000
    Current Required (mA):  100
    Extra Operating Current (mA):   0

uniqueID: AppleUSBAudioEngine:Burr-Brown from TI              :USB Audio CODEC :14200000:2,
modelID: USB Audio CODEC :08BB:2902
    USB Audio CODEC :

    Product ID: 0x2902
    Vendor ID:  0x08bb  (Texas Instruments Japan)
Version:    1.00
Speed:  Up to 12 Mb/sec
Manufacturer:   Burr-Brown from TI
    Location ID:    0x14200000 / 10
    Current Available (mA): 1000
    Current Required (mA):  100
    Extra Operating Current (mA):   0

(USB音频)格式类似于

modelID: name:vendorID:productID
uniqueID: AppleUSBAudioEngine:Manufacturer or Unknown Manufacturer:location ID:???

如果USB video的uniqueID类似,那么productIDvendorIDlocationID(哪个USB端口)的组合应该足以唯一地识别底层设备的硬件,尽管是以一种脆弱且未记录的方式。

wr98u20j

wr98u20j2#

在视频设备的情况下,AVCaptureDevice uniqueID * 似乎 * 为“0xLLLLLLLLVVVVVPPPP”形式的字符串,其中:

  • LLLLLLLL是表示USB设备位置ID的十六进制字符串
  • VVVV是表示USB设备的制造商ID的十六进制字符串
  • PPPP是表示USB设备的产品ID的十六进制字符串。

例如0x 144000002 E1 A4 C 01
(This苹果没有任何记录;我上面所说的完全是推论,这就是为什么我说“似乎是”。
这三个值应该与查询io_service_t时返回的值相对应

CFNumberRef vendorIdObj = IORegistryEntrySearchCFProperty(ioService, kIOUSBPlane, CFSTR(kUSBVendorID), kCFAllocatorDefault, 0);
CFNumberRef productIdObj = IORegistryEntrySearchCFProperty(ioService, kIOUSBPlane, CFSTR(kUSBProductID), kCFAllocatorDefault, 0);
CFNumberRef locationIdObj = IORegistryEntrySearchCFProperty(ioService, kIOUSBPlane, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault, 0);

通过将uniqueID字符串解码为三个组件,您应该能够将它们与上面的IORegistryEntrySearchCFProperty函数返回的值进行比较,从而获得AVCaptureDevice的USB接口。

相关问题