camera_stream/frame.rs
1use crate::types::{PixelFormat, Size};
2
3/// A single plane of image data.
4pub struct Plane<'a> {
5 pub data: &'a [u8],
6 pub bytes_per_row: usize,
7}
8
9/// A presentation timestamp from the platform's media clock.
10///
11/// The interpretation of the underlying value depends on the platform.
12/// Use [`as_secs_f64()`](Timestamp::as_secs_f64) for a portable
13/// approximation, or access the platform-specific timestamp type
14/// (via the [`Frame::Timestamp`] associated type) for full precision.
15pub trait Timestamp {
16 /// Seconds since an unspecified epoch (lossy convenience).
17 fn as_secs_f64(&self) -> f64;
18}
19
20/// A borrowed video frame. Lifetime tied to callback scope (zero-copy).
21pub trait Frame {
22 type Timestamp: Timestamp;
23
24 fn pixel_format(&self) -> PixelFormat;
25 fn size(&self) -> Size;
26 fn planes(&self) -> &[Plane<'_>];
27 fn timestamp(&self) -> Self::Timestamp;
28}