use std::sync::atomic::{AtomicU32, AtomicU8, Ordering::Relaxed};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum Stage {
Idle = 0,
Encoding = 1,
Sampling = 2,
Decoding = 3,
Muxing = 4,
Upscaling = 5,
}
impl Stage {
pub fn name(self) -> &'static str {
match self {
Stage::Idle => "idle",
Stage::Encoding => "encoding",
Stage::Sampling => "sampling",
Stage::Decoding => "decoding",
Stage::Muxing => "muxing",
Stage::Upscaling => "upscaling",
}
}
}
static STAGE: AtomicU8 = AtomicU8::new(0);
static DONE: AtomicU32 = AtomicU32::new(0);
static TOTAL: AtomicU32 = AtomicU32::new(0);
pub fn stage(s: Stage) {
DONE.store(0, Relaxed);
TOTAL.store(0, Relaxed);
STAGE.store(s as u8, Relaxed);
}
pub fn count(s: Stage, done: usize, total: usize) {
DONE.store(done as u32, Relaxed);
TOTAL.store(total as u32, Relaxed);
STAGE.store(s as u8, Relaxed);
}
pub fn idle() {
stage(Stage::Idle)
}
pub fn snapshot() -> (Stage, u32, u32) {
let s = match STAGE.load(Relaxed) {
1 => Stage::Encoding,
2 => Stage::Sampling,
3 => Stage::Decoding,
4 => Stage::Muxing,
5 => Stage::Upscaling,
_ => Stage::Idle,
};
(s, DONE.load(Relaxed), TOTAL.load(Relaxed))
}