pub struct Timestamp { /* private fields */ }Expand description
A presentation timestamp, expressed as a PTS value in units of an associated Timebase.
§Equality and ordering
Comparison is value-based (same instant compares equal even across
different timebases): Timestamp(1000, 1/1000) equals
Timestamp(90_000, 1/90_000). Hash hashes the reduced-form rational
instant (pts · num, den), so equal timestamps hash the same.
Cross-timebase comparisons use 128-bit cross-multiplication — no division,
no rounding error. Same-timebase comparisons take a fast path on pts.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub const fn new(pts: i64, timebase: Timebase) -> Timestamp
pub const fn new(pts: i64, timebase: Timebase) -> Timestamp
Creates a new Timestamp with the given PTS and timebase.
Sourcepub const fn pts(&self) -> i64
pub const fn pts(&self) -> i64
Returns the presentation timestamp, in units of Self::timebase.
To obtain a Duration, use Self::duration_since against a reference
timestamp, or rescale via Self::rescale_to.
Sourcepub const fn with_pts(self, pts: i64) -> Timestamp
pub const fn with_pts(self, pts: i64) -> Timestamp
Set the value of the presentation timestamp.
Sourcepub const fn set_pts(&mut self, pts: i64) -> &mut Timestamp
pub const fn set_pts(&mut self, pts: i64) -> &mut Timestamp
Set the value of the presentation timestamp in place.
Sourcepub const fn rescale_to(self, target: Timebase) -> Timestamp
pub const fn rescale_to(self, target: Timebase) -> Timestamp
Returns a new Timestamp representing the same instant in a different timebase.
Rounds toward zero via Timebase::rescale_pts; round-tripping through a
coarser timebase can lose precision.
Sourcepub const fn saturating_sub_duration(self, d: Duration) -> Timestamp
pub const fn saturating_sub_duration(self, d: Duration) -> Timestamp
Returns a new Timestamp representing this instant shifted backward
by d, in the same timebase. Saturates at i64::MIN if the subtraction
would underflow (pathological for real video).
Useful for “virtual past” seeding: e.g., initializing a warmup-filter
state to ts - min_duration so the first detected cut can fire
immediately.
Sourcepub const fn cmp_semantic(&self, other: &Timestamp) -> Ordering
pub const fn cmp_semantic(&self, other: &Timestamp) -> Ordering
const fn form of Ord::cmp. Compares two timestamps by the instant
they represent, rescaling if timebases differ.
Uses a 128-bit cross-multiply for the mixed-timebase case; no division, so no rounding error. Same-timebase comparisons take a direct fast path.
Sourcepub const fn duration_since(&self, earlier: &Timestamp) -> Option<Duration>
pub const fn duration_since(&self, earlier: &Timestamp) -> Option<Duration>
Returns the elapsed Duration from earlier to self, or None if
earlier is after self.
Works across different timebases. Computes the exact rational difference
first using a common denominator, then truncates once when converting to
nanoseconds for the returned Duration.
If the result would exceed Duration::MAX (pathological: seconds don’t
fit in u64), saturates to Duration::MAX rather than wrapping.