MCPcopy Create free account
hub / github.com/RustCV/RustCV / list_devices

Method list_devices

rustcv-backend-avf/src/lib.rs:37–68  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

35
36impl Driver for AvfDriver {
37 fn list_devices(&self) -> Result<Vec<DeviceInfo>, CameraError> {
38 let mut result = Vec::new();
39 unsafe {
40 // AVCaptureDeviceTypeExternalUnknown is deprecated, use AVCaptureDeviceTypeExternal
41 let types = NSArray::from_slice(&[
42 AVCaptureDeviceTypeBuiltInWideAngleCamera,
43 AVCaptureDeviceTypeExternal,
44 ]);
45
46 // 直接获取 session,不需要 Option 解包
47 // 这个方法返回 Retained<AVCaptureDeviceDiscoverySession>,永远不为 nil
48 let session =
49 AVCaptureDeviceDiscoverySession::discoverySessionWithDeviceTypes_mediaType_position(
50 &types,
51 AVMediaTypeVideo,
52 AVCaptureDevicePosition::Unspecified,
53 );
54
55 // 直接遍历
56 // session.devices() 返回 Retained<NSArray<AVCaptureDevice>>
57 // 这是一个实现了 IntoIterator 的类型
58 for dev in session.devices() {
59 result.push(DeviceInfo {
60 name: dev.localizedName().to_string(),
61 id: dev.uniqueID().to_string(),
62 backend: "AVFoundation".to_string(),
63 bus_info: None,
64 });
65 }
66 }
67 Ok(result)
68 }
69
70 fn open(
71 &self,

Callers 2

mainFunction · 0.45
resolve_device_idMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected