use crate::backend::Backend;
use crate::error::Error;
use crate::types::{Frame, StreamConfig};
use crossbeam_channel::{Receiver, RecvTimeoutError};
use std::time::Duration;
pub(crate) type NativeHandle = <crate::ActiveBackend as Backend>::SessionHandle;
pub(crate) enum Handle {
Native(#[expect(dead_code)] NativeHandle),
#[cfg(all(feature = "rtsp", any(target_os = "macos", target_os = "windows")))]
Rtsp(#[expect(dead_code)] crate::rtsp::SessionHandle),
}
pub struct Camera {
pub config: StreamConfig,
pub(crate) frame_rx: Receiver<Result<Frame, Error>>,
#[expect(dead_code)]
pub(crate) handle: Handle,
}
pub fn next_frame(camera: &Camera, timeout: Duration) -> Result<Frame, Error> {
match camera.frame_rx.recv_timeout(timeout) {
Ok(frame) => frame,
Err(RecvTimeoutError::Timeout) => Err(Error::Timeout),
Err(RecvTimeoutError::Disconnected) => Err(Error::StreamEnded),
}
}
pub fn try_next_frame(camera: &Camera) -> Option<Result<Frame, Error>> {
camera.frame_rx.try_recv().ok()
}