pub struct PlaybackClock { /* private fields */ }Expand description
A monotonic clock that tracks elapsed playback time.
The clock supports start, stop, pause, resume, and playback-rate scaling.
It is used by PreviewPlayer internally to drive frame presentation timing
and A/V synchronisation. Callers may also query it directly.
PlaybackClock is a value type — it is not Arc<Mutex<...>> internally.
When multi-thread access is required, wrap it in a Mutex.
§Usage
let mut clock = PlaybackClock::new();
clock.start();
let pts = clock.current_pts();
clock.pause();
// current_pts() is now frozen
clock.resume();
// current_pts() continues advancing from the frozen point
clock.set_rate(2.0); // fast-forward at 2×
clock.set_position(Duration::from_secs(30)); // seek to 30 sImplementations§
Source§impl PlaybackClock
impl PlaybackClock
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Start the clock from the current position.
- If the clock is
Stopped, it starts from the position last set byset_position, orDuration::ZEROif no seek has been performed. - If the clock is
Paused, it starts from the frozen position. - If the clock is already
Running, this is a no-op.
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Stop the clock and reset the position to Duration::ZERO.
current_time() and current_pts() will return Duration::ZERO
until start() or set_position() is called again.
Sourcepub fn pause(&mut self)
pub fn pause(&mut self)
Pause the clock at the current position.
current_time() and current_pts() are frozen until
resume is called. If already Paused or Stopped, no-op.
Sourcepub fn current_time(&self) -> Duration
pub fn current_time(&self) -> Duration
Current wall-clock elapsed time since start (affected by rate).
Equivalent to current_pts for clocks that
start at zero; use current_pts() when a seek offset has been set.
Sourcepub fn current_pts(&self) -> Duration
pub fn current_pts(&self) -> Duration
Current presentation timestamp (elapsed time since position zero).
Identical to current_time() when the clock was started from zero.
When a set_position(t) was called before start(), the clock
advances from t and this method returns values ≥ t.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the clock is actively advancing.
Sourcepub fn set_rate(&mut self, rate: f64)
pub fn set_rate(&mut self, rate: f64)
Set the playback rate. Values ≤ 0.0 are ignored (rate stays unchanged).
When the clock is Running, the current position is re-anchored at
Instant::now() so that current_time() does not jump.
Sourcepub fn set_position(&mut self, pts: Duration)
pub fn set_position(&mut self, pts: Duration)
Jump to an arbitrary position in media time.
Running: the clock continues advancing fromptsimmediately.Paused: the frozen position is updated topts.Stopped:ptsis stored and applied as the starting position whenstartis next called.
After set_position(t) + start(), current_pts
will immediately return values ≥ t.