mediaway_common/frame.rs
1//! Uncompressed video/audio frames for encode input and decode output.
2
3#![forbid(unsafe_code)]
4
5use crate::formats::{PixelFormat, SampleFormat};
6use crate::gpu::GpuBufferHandle;
7use bytes::Bytes;
8
9/// One video frame — CPU planes or a GPU handle (Zero-Copy).
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct VideoFrame {
12 /// Presentation timestamp in the stream timebase.
13 pub pts: i64,
14 /// Duration in timebase units (`0` if unknown).
15 pub duration: u64,
16 /// Width in pixels.
17 pub width: u32,
18 /// Height in pixels.
19 pub height: u32,
20 /// Pixel layout.
21 pub format: PixelFormat,
22 /// Backing store.
23 pub storage: VideoFrameStorage,
24}
25
26/// Where pixel data lives.
27#[derive(Debug, Clone, PartialEq, Eq)]
28#[non_exhaustive]
29pub enum VideoFrameStorage {
30 /// CPU-accessible tightly packed or planar bytes (may imply copy into HW).
31 ///
32 /// Prefer [`VideoFrameStorage::Gpu`] on hot encode paths. Using CPU storage
33 /// with a HW encoder typically requires upload — backends must document that.
34 Cpu {
35 /// Plane bytes (layout implied by [`PixelFormat`]).
36 data: Bytes,
37 },
38 /// GPU texture / surface — Zero-Copy when the backend accepts the variant.
39 Gpu(GpuBufferHandle),
40}
41
42/// One audio buffer (interleaved PCM).
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct AudioFrame {
45 /// Presentation timestamp in the stream timebase.
46 pub pts: i64,
47 /// Duration in timebase units.
48 pub duration: u64,
49 /// Sample rate (Hz).
50 pub sample_rate: u32,
51 /// Channel count.
52 pub channels: u16,
53 /// PCM sample format.
54 pub format: SampleFormat,
55 /// Interleaved sample bytes.
56 pub data: Bytes,
57}