Skip to main content

openlogi_camera/
capture_types.rs

1//! Platform-independent capture vocabulary shared by every capture backend
2//! (AVFoundation on macOS, Media Foundation on Windows, stubs elsewhere).
3
4/// One decoded camera frame, tightly-packed BGRA8 (`width * height * 4` bytes) —
5/// gpui's native texture order, so the preview uploads it without a channel
6/// swap. The snapshot path swaps to RGBA when it writes the PNG.
7#[derive(Clone)]
8pub struct Frame {
9    pub width: u32,
10    pub height: u32,
11    pub bgra: Vec<u8>,
12}
13
14/// Why a capture attempt failed.
15#[derive(Debug, Clone)]
16pub enum CaptureError {
17    /// Camera permission is denied/restricted, or this process can't request
18    /// it (e.g. an unbundled macOS binary with no `NSCameraUsageDescription`).
19    AccessDenied,
20    /// No camera matched the requested unique id.
21    NotFound,
22    /// The session ran but produced no frame within the timeout.
23    Timeout,
24    /// A platform capture object failed to construct.
25    Setup(String),
26    /// Capture has no backend on this platform.
27    Unsupported,
28}
29
30impl std::fmt::Display for CaptureError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Self::AccessDenied => write!(
34                f,
35                "camera access denied — grant Camera permission (on macOS, run inside an app bundle with NSCameraUsageDescription)"
36            ),
37            Self::NotFound => write!(f, "no camera matched that id"),
38            Self::Timeout => write!(f, "camera produced no frame in time"),
39            Self::Setup(s) => write!(f, "capture setup failed: {s}"),
40            Self::Unsupported => write!(f, "camera capture is not implemented on this platform"),
41        }
42    }
43}
44
45impl std::error::Error for CaptureError {}