use std::sync::Arc;
use std::time::Instant;
#[derive(Debug, Clone)]
pub struct PTSClock {
start: Arc<Instant>,
}
impl PTSClock {
pub fn new() -> Self {
Self {
start: Arc::new(Instant::now()),
}
}
pub fn from_instant(start: Instant) -> Self {
Self {
start: Arc::new(start),
}
}
#[inline]
pub fn pts(&self) -> f64 {
self.start.elapsed().as_secs_f64()
}
#[inline]
pub fn pts_at(&self, instant: Instant) -> f64 {
instant.duration_since(*self.start).as_secs_f64()
}
pub fn start_instant(&self) -> Instant {
*self.start
}
}
impl Default for PTSClock {
fn default() -> Self {
Self::new()
}
}