use std::time::{Duration, Instant};
use crate::{FrameView, Result};
pub trait FrameSource {
fn next_frame(&mut self) -> Result<Option<(FrameView<'_>, Duration)>>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LateFramePolicy {
Render,
Skip,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PlaybackOptions {
pub late_policy: LateFramePolicy,
}
impl Default for PlaybackOptions {
fn default() -> Self {
Self {
late_policy: LateFramePolicy::Render,
}
}
}
pub fn wait_until(start: Instant, presentation_time: Duration) {
let deadline = start + presentation_time;
let now = Instant::now();
if deadline > now {
std::thread::sleep(deadline - now);
}
}