(&self)
| 35 | |
| 36 | impl 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, |
no outgoing calls
no test coverage detected