Skip to main content

Timeline

Struct Timeline 

Source
pub struct Timeline { /* private fields */ }
Expand description

Shared playback timeline used across stream layers.

Stores canonical committed playback position. The byte cursor lives on the Source — sources own per-variant or per-file atomic cursors and expose them through Source::position / Source::advance / Source::set_position.

Implementations§

Source§

impl Timeline

Source

pub fn new() -> Self

Source

pub fn advance_committed_chunk(&self, pos: &ChunkPosition)

Advance the consumer’s playhead to the end of the consumed region described by pos. pos.frame_offset + pos.frames must equal the absolute frame the consumer has now finished playing through; the decoder owns these numbers, callers do not invent them.

committed_position_ns (UI) is derived from the new playhead frame divided by pos.sample_rate. byte_position is set from pos.source_byte_offset + pos.source_bytes when the decoder reports absolute offsets (Apple, Android API 28+); otherwise it is left untouched so the producer-side cursor (Stream::try_read / Stream::seek) continues to drive it.

Validates against total_duration in dev/test builds: a chunk pushing the playhead past the declared duration is a real arithmetic bug — the decoder’s frame counter disagrees with total_duration, somebody is wrong.

Source

pub fn clear_seek_pending(&self, epoch: u64)

Clear seek-pending flag after the decoder successfully applied the seek.

Only clears if epoch matches the current seek epoch, preventing a stale completion from clearing a newer seek.

Source

pub fn commit_seek_landed(&self, pos: &ChunkPosition)

Pin the playhead to the decoder’s actual landing frame after a seek. Called by the worker once decoder.seek returns [DecoderSeekOutcome::Landed] — the only authoritative source for “where did we actually end up”. pos.frame_offset carries the landed frame; pos.frames should be 0 (we have not yet consumed any chunk, just repositioned). pos.source_byte_offset (if known) is the byte offset the decoder is now reading from.

Source

pub fn committed_position(&self) -> Duration

Source

pub fn complete_seek(&self, epoch: u64)

Complete a seek (FLUSH_STOP).

Clears flushing flag only if epoch is still current. A superseding initiate_seek will have incremented the epoch, preventing an older completion from clearing the new seek.

Uses a double-check to guard against the race where a new initiate_seek fires between our epoch load and flushing store.

Source

pub fn did_clear_pending_seek_epoch(&self, seek_epoch: u64) -> bool

Source

pub fn did_take_decoder_node_seek(&self) -> bool

Consume the decoder-node seek latch with an Acquire swap.

Independent from take_seek_preempt: the inner audio source consumes that one inside step_track, while DecoderNode (the wrapping scheduler node) needs its own signal so it can reset preload state and drop parked chunks on a new epoch. true here means seek_epoch was just bumped and the node must run the cleanup branch; otherwise the tick falls through.

Source

pub fn did_take_seek_preempt(&self) -> bool

Consume the seek-preempt latch with an Acquire swap.

Returns true exactly once per initiate_seek call: the worker uses this to short-circuit step_track’s preempt guard without dereferencing two Arc<AtomicU64>s. The Acquire ordering synchronises with the Release in initiate_seek so observing true here means the new seek_epoch and seek_target_ns stores are also visible.

Source

pub fn initiate_seek(&self, target: Duration) -> u64

Initiate a seek (FLUSH_START).

Sets flushing flag, records target position, increments epoch. All blocking reads (wait_range) will observe is_flushing() and abort.

Returns the new seek epoch.

§Panics

Panics if target overflows u64::MAX nanoseconds (≈584 years — not reachable for any realistic seek target).

Source

pub fn is_flushing(&self) -> bool

Check if the pipeline is being flushed (seek pending).

Source

pub fn is_playing(&self) -> bool

Whether the audio FSM has claimed this Timeline as the currently active decode target.

Written by the audio pipeline (StreamAudioSource) on entry into a decode-producing state and cleared on EOF / failure / unload. Read by the Downloader peer implementations to decide whether a track’s fetches should be routed to the high-priority slot.

Source

pub fn is_seek_pending(&self) -> bool

Check if a seek has been initiated but not yet applied by the decoder.

Unlike is_flushing() (which gates I/O via wait_range), this flag stays set until the decoder successfully repositions. Used by the worker loop to trigger seek retry.

Source

pub fn mark_pending_seek_epoch(&self, seek_epoch: u64)

Source

pub fn pending_seek_epoch(&self) -> Option<u64>

Source

pub fn seek_epoch(&self) -> u64

Read the current seek epoch.

Source

pub fn seek_epoch_handle(&self) -> Arc<AtomicU64>

Cheap clone of the shared atomic seek epoch — same use case.

Source

pub fn seek_target(&self) -> Option<Duration>

Read the pending seek target position.

Source

pub fn set_committed_position(&self, position: Duration)

§Panics

Panics if position overflows u64::MAX nanoseconds (≈584 years); no realistic media stream can hit this.

Source

pub fn set_download_position(&self, position: u64)

Report the current download byte position. The value is not stored on the timeline — it exists only as a USDT probe point (#[kithara::probe]) for download-progress observability.

Source

pub fn set_playing(&self, playing: bool)

Toggle the PLAYING flag.

Orthogonal to FLUSHING / SEEK_PENDING: toggling PLAYING does not affect the seek state.

Source

pub fn set_segment_position(&self, position: u64)

Source

pub fn set_total_duration(&self, duration: Option<Duration>)

Source

pub fn total_duration(&self) -> Option<Duration>

Trait Implementations§

Source§

impl Clone for Timeline

Source§

fn clone(&self) -> Timeline

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timeline

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Timeline

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,