创建驱动实例的工厂函数
()
| 11 | |
| 12 | /// 创建驱动实例的工厂函数 |
| 13 | pub fn create_driver() -> Result<Box<dyn Driver>> { |
| 14 | // 根据当前操作系统,直接选用原生后端 (不再需要 feature 门控) |
| 15 | #[cfg(target_os = "linux")] |
| 16 | { |
| 17 | Ok(Box::new(rustcv_backend_v4l2::V4l2Driver::new())) |
| 18 | } |
| 19 | |
| 20 | #[cfg(target_os = "macos")] |
| 21 | { |
| 22 | Ok(Box::new(rustcv_backend_avf::AvfDriver::new())) |
| 23 | } |
| 24 | |
| 25 | #[cfg(target_os = "windows")] |
| 26 | { |
| 27 | Ok(Box::new(rustcv_backend_msmf::MsmfDriver::new())) |
| 28 | } |
| 29 | |
| 30 | #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))] |
| 31 | { |
| 32 | // 如果没有匹配的后端,返回错误 |
| 33 | Err(anyhow!( |
| 34 | "No supported backend found for this OS. Please check Cargo features." |
| 35 | )) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// 辅助:获取首选后端类型 |
| 40 | pub fn default_backend() -> BackendType { |