Skip to main content

euv_core/media/video/
enum.rs

1use super::*;
2
3/// ISO/IEC 23091-2 (CICP) color primaries identifying the video gamut.
4#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
5pub enum ColorPrimaries {
6    /// ITU-R BT.709 / sRGB primaries (`1`).
7    #[default]
8    Bt709,
9    /// ITU-R BT.601 525/625-line standard definition primaries (`5` / `6`).
10    Bt601,
11    /// ITU-R BT.2020 wide color gamut primaries (`9`).
12    Bt2020,
13    /// DCI-P3 / Display P3 primaries (`12`).
14    DisplayP3,
15    /// Unrecognized CICP primary code preserved verbatim.
16    Unknown(u16),
17}
18
19/// ISO/IEC 23091-2 (CICP) electro-optical transfer function identifying SDR vs HDR tone curves.
20#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
21pub enum TransferCharacteristics {
22    /// Standard sRGB piecewise transfer curve (`13`).
23    Srgb,
24    /// ITU-R BT.709 SDR transfer curve (`1`).
25    #[default]
26    Bt709,
27    /// Linear light transfer curve (`8`).
28    Linear,
29    /// SMPTE ST 2084 Perceptual Quantizer HDR10 transfer curve (`16`).
30    PqSt2084,
31    /// ARIB STD-B67 Hybrid Log-Gamma HDR transfer curve (`18`).
32    Hlg,
33    /// Unrecognized CICP transfer code preserved verbatim.
34    Unknown(u16),
35}
36
37/// ISO/IEC 23091-2 (CICP) YCbCr matrix coefficients for YUV-to-RGB conversion.
38#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
39pub enum MatrixCoefficients {
40    /// RGB identity matrix (`0`).
41    Identity,
42    /// ITU-R BT.709 matrix (`1`).
43    #[default]
44    Bt709,
45    /// ITU-R BT.601 matrix (`5` / `6`).
46    Bt601,
47    /// ITU-R BT.2020 non-constant luminance matrix (`9`).
48    Bt2020Ncl,
49    /// Unrecognized CICP matrix code preserved verbatim.
50    Unknown(u16),
51}
52
53/// Signal quantization range of luma/chroma samples.
54#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
55pub enum ColorRange {
56    /// Broadcast / studio limited range (`Y: 16..=235`, `Cb/Cr: 16..=240`).
57    #[default]
58    Limited,
59    /// Full 8-bit/10-bit swing (`0..=255`).
60    Full,
61}
62
63/// Surface pixel layout for GPU zero-copy surfaces and CPU pooled frames.
64#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
65pub enum VideoPixelFormat {
66    /// Packed 8-bit per channel RGBA.
67    #[default]
68    Rgba8,
69    /// Packed 8-bit per channel BGRA.
70    Bgra8,
71    /// Bi-planar 8-bit 4:2:0 Y + interleaved UV (`CVPixelBuffer` / `HardwareBuffer` / DXGI).
72    Nv12,
73    /// Bi-planar 10-bit 4:2:0 HDR Y + interleaved UV (`P010`).
74    P010,
75    /// Tri-planar 8-bit 4:2:0 Y + U + V.
76    Yuv420p,
77}
78
79/// Target hardware or software video decode backend identifier.
80#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
81pub enum HardwareDecoderKind {
82    /// Apple VideoToolbox (`CVPixelBuffer` -> Metal zero-copy texture).
83    VideoToolbox,
84    /// Android MediaCodec (`AHardwareBuffer` / SurfaceTexture -> Vulkan/GLES zero-copy).
85    MediaCodec,
86    /// Linux VA-API / V4L2 (`DMA-BUF` -> Vulkan/GLES zero-copy).
87    Vaapi,
88    /// Windows DXVA / D3D11VA (`ID3D11Texture2D` shared handle -> D3D12/Vulkan zero-copy).
89    Dxva,
90    /// Browser WebCodecs (`VideoFrame` -> WebGPU/WebGL zero-copy).
91    WebCodecs,
92    /// Pure-Rust CPU software decoder writing into a bounded reusable `VideoFramePool`.
93    #[default]
94    SoftwareFallback,
95}
96
97/// Storage backing for a decoded video frame: either a zero-copy GPU texture handle or a pooled CPU buffer.
98#[derive(Clone, Debug, PartialEq)]
99pub enum VideoFrameBacking {
100    /// Zero-copy GPU surface/texture interop handle composited directly without CPU readback.
101    GpuSurface(VideoGpuSurfaceHandle),
102    /// Bounded reusable CPU RGBA8 frame buffer fallback.
103    CpuPooled(PooledVideoFrame),
104}
105
106/// Clock source driving A/V synchronization.
107#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
108pub enum AvSyncClockSource {
109    /// Hardware audio playback timestamp serves as master clock.
110    AudioMaster,
111    /// Monotonic steady clock fallback when track is silent, muted, or audio-less.
112    #[default]
113    MonotonicFallback,
114}
115
116/// Per-VSync frame presentation decision produced by `AvSyncScheduler`.
117#[derive(Clone, Debug, PartialEq)]
118pub enum VideoPresentDecision {
119    /// A new frame is due at the active playback clock and should replace the displayed texture.
120    PresentNewFrame(DecodedVideoFrame),
121    /// Display refresh cadence is faster than video frame rate; hold the current frame without forging pixels.
122    HoldCurrentFrame,
123    /// Pipeline is waiting for the background decoder to fill the PTS queue.
124    Buffering,
125    /// Timeline reached end-of-stream and all queued frames have been presented.
126    Ended,
127}
128
129/// Zero-clone presentation outcome returned by `VideoPlaybackPipeline::present_vsync`.
130#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
131pub enum VideoPresentOutcome {
132    /// A new frame replaced `pipeline.current_frame()` without cloning frame pixel storage.
133    Presented {
134        /// Presentation timestamp in microseconds of the newly active frame.
135        pts_us: i64,
136        /// Decode-order sample index of the newly active frame.
137        sample_index: usize,
138        /// Pipeline seek generation tag of the newly active frame.
139        generation: u64,
140        /// `true` when the newly active frame is backed by a zero-copy GPU surface handle.
141        zero_copy_gpu: bool,
142    },
143    /// Display refresh cadence is faster than video frame rate; held existing frame without forging pixels.
144    #[default]
145    HoldCurrentFrame,
146    /// Background decoder is filling the PTS queue.
147    Buffering,
148    /// Stream reached end-of-stream and all queued frames were presented.
149    Ended,
150}