pub struct Clock { /* private fields */ }Expand description
Shared wall-clock reference for pacing decoded frames to their presentation time. Whichever branch (video, audio, …) processes a frame first sets the anchor; every other branch reads the same one, so they agree on t=0 instead of each drifting from its own first frame.
Owned by crate::pipeline::Pipeline (one per pipeline, shared with
every crate::elements::Pacer via the wire closure) so
Pipeline::pause/resume can keep it in sync with the rest of the
pipeline — see those for why a Pacer, mid-playback, needs this to be
pause-aware and not just a fixed anchor.
Implementations§
Source§impl Clock
impl Clock
pub fn new() -> Self
Sourcepub fn start(&self) -> Instant
pub fn start(&self) -> Instant
The instant playback started, set on first call — shifted forward
on every Clock::resume by however long the clock spent paused,
so now - start() stays continuous across a pause/resume cycle
instead of jumping by the pause’s real duration. Callers that pace
against this (see Pacer::wait_for) need to
call it fresh each time, not cache the first result — the whole
point is that it can move.
Sourcepub fn pause(&self)
pub fn pause(&self)
Freezes the clock in place. No-op if unset (nothing running yet) or already paused.
Sourcepub fn resume(&self)
pub fn resume(&self)
Undoes Clock::pause by shifting start forward by however long
this pause lasted. No-op if not currently paused.
Sourcepub fn reset(&self)
pub fn reset(&self)
Back to the same “never started” state as a freshly constructed
Clock — the next Clock::start call re-anchors t=0 to
that moment, same lazy-first-caller-wins semantics as initial
startup (see the type docs). Unconditional, regardless of current
state.
Called on crate::control::ControlMsg::Seek
(see crate::pipeline::Pipeline::seek): the old anchor measured
real time elapsed for the pre-seek position — after a jump, a
Pacer’s elapsed_secs (relative to its own now-reset
first_pts) starts over from ~0 too, so pairing it with the
stale anchor would compute a due far in the past and skip
sleeping entirely, dumping every post-seek frame with no pacing.
This is the wall-clock half of that same fix — Pacer::first_pts
resetting is the pts half; both are needed together.