pub struct Clock { /* private fields */ }Expand description
A clock for stamping media frames so that tracks produced concurrently, e.g. an audio and a video capture running on separate threads, land on a single timeline.
It never runs backward, and runs at the host wall clock’s rate: each read nudges it toward the wall clock by at most 500 ppm, and it jumps forward across a suspend. Clones share the timeline and the wall mapping, so handing them to several producers keeps the broadcast on one clock. Two clocks are equal only when they are one timeline.
Implementations§
Source§impl Clock
impl Clock
Sourcepub const TIMESCALE: Timescale = moq_net::Timescale::MICRO
pub const TIMESCALE: Timescale = moq_net::Timescale::MICRO
Units per second for the broadcast clock: microseconds.
Matches the hang container timescale, so media timestamps convert without loss, and fine enough that the wall value stays within the JSON-safe integer range until the year 2305.
Sourcepub fn new() -> Self
pub fn new() -> Self
Start a clock that reads ten seconds now, so PTS zero is ten seconds ago on the wall.
Without a wall mapping when the host’s wall clock is unset, or reads a time the mapping can’t name: media needs only the monotonic timeline.
Sourcepub fn at(epoch: Instant, wall: Wall) -> Result<Self>
pub fn at(epoch: Instant, wall: Wall) -> Result<Self>
Start a clock at an explicit monotonic epoch and wall time: PTS zero at both.
The deterministic constructor: synthetic sources and fixtures pin both ends instead of
sampling. epoch is an instant on the ambient clock, which the clock keeps reading wherever
it is read from. Refuses an unrepresentable wall.
Sourcepub fn capture(&self, at: Instant) -> Result<Timestamp>
pub fn capture(&self, at: Instant) -> Result<Timestamp>
Map the instant a payload was captured (a datagram’s arrival, a sensor read) onto this clock.
at is an instant on the ambient clock this one was created under, which is the host’s
outside tests. Refuses an instant ahead of now, which would claim the payload reached the
transport before it existed, and one before PTS zero, which no timestamp can name.
Sourcepub fn wall(&self) -> Option<Clock>
pub fn wall(&self) -> Option<Clock>
The catalog root section advertising this clock, or None if the broadcast has no wall mapping:
the host’s wall clock was unset, or the source advertised none.
Sourcepub fn wall_clock(&self, pts: Timestamp) -> Result<Wall>
pub fn wall_clock(&self, pts: Timestamp) -> Result<Wall>
The wall-clock time of pts under this broadcast’s mapping.
Pure in the stored mapping: a system-clock adjustment after construction changes nothing. Exact down to the nanosecond; an instant finer than that (a 90 kHz tick) is floored. Refuses an unrepresentable result, and a clock without a mapping.
Trait Implementations§
impl Eq for Clock
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin for Clock
impl UnsafeUnpin for Clock
impl UnwindSafe for Clock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.