AVCaptureDeviceをお持ちの場合、関連するUSBインターフェイスを取得してIOKit経由でハードウェアにアクセスする方法を教えてください。AVCaptureDeviceのUSBインターフェイス
私はvid & pidで見つけようとしましたが、同じvidの2つのデバイス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);