Skip to main content

rustcv_backend_v4l2/
lib.rs

1pub mod controls;
2pub mod device;
3pub mod pixel_map;
4pub mod stream;
5
6use rustcv_core::error::Result;
7use rustcv_core::traits::Driver;
8use std::sync::Arc;
9
10/// V4L2 驱动单例结构体
11/// 通常作为全局单例存在
12#[derive(Debug, Clone)]
13pub struct V4l2Driver;
14
15impl Default for V4l2Driver {
16    fn default() -> Self {
17        Self::new()
18    }
19}
20
21impl V4l2Driver {
22    pub fn new() -> Self {
23        Self
24    }
25}
26
27// 实现 Driver Trait
28impl Driver for V4l2Driver {
29    fn list_devices(&self) -> Result<Vec<rustcv_core::traits::DeviceInfo>> {
30        device::list_devices()
31    }
32
33    fn open(
34        &self,
35        id: &str,
36        config: rustcv_core::builder::CameraConfig,
37    ) -> Result<(
38        Box<dyn rustcv_core::traits::Stream>,
39        rustcv_core::traits::DeviceControls,
40    )> {
41        device::open(id, config)
42    }
43}
44
45// 为了方便直接使用,提供一个默认实例
46pub fn default_driver() -> Arc<dyn Driver> {
47    Arc::new(V4l2Driver::new())
48}