pub struct BufferController { /* private fields */ }Expand description
The decision engine. Sans-IO: the caller passes every clock reading.
Implementations§
Source§impl BufferController
impl BufferController
Sourcepub fn new(
cfg: ControllerConfig,
seed: Option<StallMemorySnapshot>,
) -> Result<Self, Error>
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.
Sourcepub fn config(&self) -> &ControllerConfig
pub fn config(&self) -> &ControllerConfig
The validated configuration in force.
Sourcepub fn on_chunk(
&mut self,
arrival: Duration,
bytes: u32,
pcr_27mhz: Option<Clock27>,
)
pub fn on_chunk( &mut self, arrival: Duration, bytes: u32, pcr_27mhz: Option<Clock27>, )
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
apart coalesced instead. The step is folded in (and the target
re-evaluated) at the next on_chunk.
Sourcepub fn on_media(&mut self, now: Duration, media_end: Clock27)
pub fn on_media(&mut self, now: Duration, media_end: Clock27)
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, DEFAULT_TRACK, media_end) (track 0), so
it participates in the same per-track minimum as any explicit track.
Sourcepub fn register_track(&mut self, track: u32)
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 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.
Sourcepub fn unregister_track(&mut self, track: u32)
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.
Sourcepub fn on_track_media(&mut self, now: Duration, track: u32, media_end: Clock27)
pub fn on_track_media(&mut self, now: Duration, track: u32, media_end: Clock27)
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 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.
A now earlier than the latest instant seen on any call is clamped to it, as
on_hint does, so a stepped-back clock cannot stamp a delivery in the past.
Sourcepub fn on_tick(&mut self, now: Duration, playback_27mhz: Option<Clock27>)
pub fn on_tick(&mut self, now: Duration, playback_27mhz: Option<Clock27>)
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).
Sourcepub fn on_hint(&mut self, now: Duration, hint: Hint)
pub fn on_hint(&mut self, now: Duration, hint: Hint)
Report an out-of-band hint. Reconnected must be sent before the
first chunk of the new connection is fed.
Sourcepub fn poll_event(&mut self) -> Option<Event>
pub fn poll_event(&mut self) -> Option<Event>
Next pending event, oldest first. An EventsDropped precedes the
survivors after an overflow.
Sourcepub fn snapshot_memory(&self) -> StallMemorySnapshot
pub fn snapshot_memory(&self) -> StallMemorySnapshot
The stall memory, for persistence (age it on restore with
StallMemorySnapshot::aged).
Sourcepub fn restore_memory(&mut self, snapshot: StallMemorySnapshot)
pub fn restore_memory(&mut self, snapshot: StallMemorySnapshot)
Install a stall memory and lift the target to what it implies.