Skip to main content

BufferController

Struct BufferController 

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

The decision engine. Sans-IO: the caller passes every clock reading.

Implementations§

Source§

impl BufferController

Source

pub fn new( cfg: ControllerConfig, seed: Option<StallMemorySnapshot>, ) -> Result<Self, Error>

Build a controller, optionally seeded with a persisted stall memory (age it with StallMemorySnapshot::aged first).

§Errors

Any ControllerConfig::validate failure.

Source

pub fn config(&self) -> &ControllerConfig

The validated configuration in force.

Source

pub fn on_chunk( &mut self, arrival_us: Micros, bytes: u32, pcr_27mhz: Option<Ticks27>, )

One chunk arrived. pcr_27mhz is the chunk’s last PCR (raw, wrapped) if it has one. Call this BEFORE on_media for the same chunk.

Delivery instant. A chunk boundary is the delivery instant of the per-track granularity floor: every on_track_media call for a track between two on_chunk calls is ONE delivery (step = end after the last call - end before the first). Reporting once per delivered chunk or once per demuxed sample gives the same floor. A caller that never calls on_chunk gets calls less than COALESCE_US apart coalesced instead. The step is folded in (and the target re-evaluated) at the next on_chunk.

Source

pub fn on_media(&mut self, now_us: Micros, media_end_27mhz: Ticks27)

The demuxer’s media position advanced: media_end_27mhz is the end of the last demuxed sample in the playback (PTS) domain (27 MHz ticks; PTS90k x 300). The first value after (re)start is taken as the oldest buffered position; report the first sample’s start PTS as a zero-length first report so that sample is not skipped.

Caller contract (join point). The first end reported is the start origin (with several tracks, the earliest first report). Report the first end only from the join point (the first video random-access point) and never report an end for media before it: audio reported before the join point (normal in a TS mux, audio is ~1 s behind video) anchors the origin that much early and the start loses that much audio cushion. The controller cannot see RAPs, so the caller must withhold ends before the join point.

media_end_27mhz means the end of the media playable on ALL rendered tracks: when audio and video are both rendered the caller must pass the minimum of their ends (video is typically ~1 s ahead of audio in a TS mux; judging the lead on video alone makes audio arrive after its play time). Or use on_track_media and let the controller take the minimum.

Mixing: this is shorthand for on_track_media(now_us, DEFAULT_TRACK, media_end_27mhz) (track 0), so it participates in the same per-track minimum as any explicit track.

Source

pub fn register_track(&mut self, track: u32)

Announce that track will be rendered, so a start or resume waits for it before its first delivery. A registered track that never delivers is excluded once other tracks have delivered for ControllerConfig::track_silence_timeout_us without it (never after a global delivery gap). Optional: an unregistered track becomes active on its first delivery (join-point contract: see on_media, report only from the join point). At most MAX_TRACKS distinct tracks are kept.

Source

pub fn unregister_track(&mut self, track: u32)

Remove track (a replaced or dead audio/video track) so it can no longer hold back the lead: its end and any registration are forgotten at once, so the minimum is taken over the remaining tracks and a start/resume that was waiting on it is released on the next tick. Stats::limiting_track and the track named by a later Pause follow the remaining set. An unknown track is a no-op. If no track is left there is no effective end (ticks do nothing, as before the first delivery) until a track delivers or is registered again. The track may be reported again later; it then rejoins as a new one.

Source

pub fn on_track_media( &mut self, now_us: Micros, track: u32, media_end_27mhz: Ticks27, )

Per-track media position: media_end_27mhz is the end of the last demuxed sample of track in the playback (PTS) domain (same units and first-report rule and join-point caller contract as on_media). The controller keeps every track’s end and measures the lead against the minimum over the active tracks. A track is excluded only when it is silent relative to the other tracks: its last delivery is at least ControllerConfig::track_silence_timeout_us before the most recent delivery on any track. A global delivery gap (nothing delivered anywhere) excludes nobody: the minimum of the last ends is kept, so a reconnect does not make the controller resume on stale data. A Pause for starvation names the limiting track in Event::Pause::track and Stats::limiting_track.

Source

pub fn on_tick(&mut self, now_us: Micros, playback_27mhz: Option<Ticks27>)

Periodic tick (recommended 50 ms). playback_27mhz is the renderer clock in the PTS domain, None while it is not running; it is only read while Playing (while paused the controller uses the position it told the caller to hold).

Source

pub fn on_hint(&mut self, now_us: Micros, hint: Hint)

Report an out-of-band hint. Reconnected must be sent before the first chunk of the new connection is fed.

Source

pub fn poll_event(&mut self) -> Option<Event>

Next pending event, oldest first. An EventsDropped precedes the survivors after an overflow.

Source

pub fn state(&self) -> State

Current state.

Source

pub fn target_us(&self) -> Micros

Current desired lead; always within [min_us, max_us].

Source

pub fn stats(&self) -> Stats

Statistics snapshot.

Source

pub fn snapshot_memory(&self) -> StallMemorySnapshot

The stall memory, for persistence (age it on restore with StallMemorySnapshot::aged).

Source

pub fn restore_memory(&mut self, snapshot: StallMemorySnapshot)

Install a stall memory and lift the target to what it implies.

Source

pub fn reset(&mut self, keep_memory: bool)

New channel (keep_memory = false) or reconnect-style restart (keep_memory = true): back to the first fill; counters are kept.

Trait Implementations§

Source§

impl Clone for BufferController

Source§

fn clone(&self) -> Self

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 BufferController

Source§

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

Formats the value using the given formatter. 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, 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.