use std::collections::BTreeMap;
use async_trait::async_trait;
use rmpv::Value;
use super::{Bus, DriverResult, SampleStream};
#[derive(Debug, Clone, PartialEq)]
pub struct CameraCandidate {
pub driver_id: String,
pub device_id: String,
pub label: String,
pub bus: Bus,
pub vid_pid: Option<(u16, u16)>,
pub metadata: BTreeMap<String, Value>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CameraCapabilities {
pub radiometric: bool,
pub bit_depth: u32,
pub width: u32,
pub height: u32,
pub fps: f32,
pub pixel_format: String,
pub streaming_protocol: String,
pub color_spaces: Vec<String>,
pub has_audio: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FrameBuffer {
pub timestamp_ns: i64,
pub sequence: u64,
pub width: u32,
pub height: u32,
pub pixel_format: String,
pub data: Vec<u8>,
pub radiometric_k: Option<Vec<u8>>,
pub metadata: BTreeMap<String, Value>,
}
#[async_trait]
pub trait CameraDriver: Send + Sync {
type Session: Send + Sync;
async fn discover(&self) -> DriverResult<Vec<CameraCandidate>>;
async fn open(
&self,
candidate: &CameraCandidate,
config: &BTreeMap<String, Value>,
) -> DriverResult<Self::Session>;
async fn close(&self, session: Self::Session) -> DriverResult<()>;
fn capabilities(&self, session: &Self::Session) -> CameraCapabilities;
async fn frame_iterator(
&self,
session: &Self::Session,
) -> DriverResult<SampleStream<FrameBuffer>>;
async fn set_param(
&self,
session: &Self::Session,
param: &str,
value: Value,
) -> DriverResult<()>;
}