//! Time, timestamps and the rational base between them. /// A media timestamp, in [`TimeBase`] ticks. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct Timestamp(pub i64); impl Timestamp { /// A timestamp of `ticks`. pub fn new(ticks: i64) -> Timestamp { Timestamp(ticks) } /// The tick count. pub fn value(&self) -> i64 { self.0 } } /// A duration in [`TimeBase`] ticks. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)] pub struct Duration(pub u64); impl Duration { /// A duration of `ticks`. pub fn new(ticks: u64) -> Duration { Duration(ticks) } /// The tick count. pub fn value(&self) -> u64 { self.0 } } /// Wall-clock time, split so that no fraction is lost to a float. #[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct Time { /// Whole seconds. pub seconds: u64, /// Fraction of a second, 0.0..1.0. pub frac: f64, } impl Time { /// A time from whole seconds and a fraction. pub fn new(seconds: u64, frac: f64) -> Time { Time { seconds, frac } } /// A time from seconds, or [`None`] for a negative or non-finite input — /// which is what makes a caller check before seeking to it. pub fn try_from_secs_f64(secs: f64) -> Option