pub struct MediaStore { /* private fields */ }std only.Expand description
In-RAM rolling window for one served stream: bytes + timing, shared by every adapter serving that stream.
Implementations§
Source§impl MediaStore
impl MediaStore
Sourcepub fn resolve_playlist(
&self,
track_id: u32,
query: BlockingQuery,
) -> PlaylistOutcome
pub fn resolve_playlist( &self, track_id: u32, query: BlockingQuery, ) -> PlaylistOutcome
Resolve a GET media.m3u8 request against _HLS_msn/_HLS_part
blocking-reload semantics (RFC 8216bis §6.2.5.2), rendering
media_playlist_m3u8 for track_id once the awaited condition is
satisfied (or immediately, if query carries no blocking
parameters).
_HLS_msn alone waits for segment msn to close; _HLS_msn+
_HLS_part waits only for that part of the (possibly still open)
segment — these are genuinely different conditions (treating a bare
_HLS_msn as _HLS_part=0 would resolve as soon as the segment
merely opens with one live part, before it has an #EXTINF/URI at
all). _HLS_part without _HLS_msn is meaningless (a part is only
addressable relative to a segment) and a _HLS_msn unreasonably far
beyond the live edge is either a broken client or abuse — both
PlaylistOutcome::BadRequest immediately rather than
PlaylistOutcome::WouldBlocking.
Sourcepub fn resolve_resource(&self, name: &str) -> ResourceOutcome
pub fn resolve_resource(&self, name: &str) -> ResourceOutcome
Resolve a dynamic origin filename (init-{track}.mp4, seg-{track}- {seq}.m4s, part-{track}-{seq}.{idx}.m4s) to its bytes.
A part request is the preload-hinted Partial Segment a client fetches
ahead of time (RFC 8216bis §6.2.2, §6.3.1). If the origin promised it
via #EXT-X-PRELOAD-HINT but hasn’t produced it yet,
ResourceOutcome::WouldBlock — the caller should hold the request
open (not 404 immediately, which spams errors and defeats low
latency). ResourceOutcome::NotFound is returned promptly
(without the caller needing to wait out its own timeout) once the
part can no longer appear: its segment has closed (now only
addressable as a whole segment via seg-…), or the in-progress
segment has advanced past it — a legitimate 404 the client answers by
fetching the next segment/part.
Source§impl MediaStore
impl MediaStore
Sourcepub fn new(
target_duration_secs: f64,
part_target_ms: u32,
window_segments: usize,
) -> Self
pub fn new( target_duration_secs: f64, part_target_ms: u32, window_segments: usize, ) -> Self
New empty store; window_segments = full segments retained.
Sourcepub fn add_part(&self, part: PartInfo)
pub fn add_part(&self, part: PartInfo)
Append a completed part to the in-progress segment.
Caps live_parts at max_live_parts worth of entries, dropping the
oldest live part(s) first if the cap is exceeded — this bounds RAM
use even if the current segment never closes (see
compute_max_live_parts).
Sourcepub fn add_segment(&self, seg: SegmentInfo)
pub fn add_segment(&self, seg: SegmentInfo)
Close a full segment into the window (evicting the oldest). Its
in-progress parts move out of live_parts into a bounded recent_parts
buffer — still fetchable (so an in-flight preload-hint request for the
segment’s final part resolves) but no longer rendered as open parts.
recent_parts is capped like live_parts, oldest-first.
Sourcepub fn init_bytes(&self) -> Option<Vec<u8>>
pub fn init_bytes(&self) -> Option<Vec<u8>>
The fMP4 init segment bytes, if present — the one accessor kept
public beyond add_*/set_*/health/listen, since callers (e.g.
multimux’s pipeline/supervisor tests) commonly need to assert media
has actually landed without going through resolve_resource.
Sourcepub fn latest_progress(&self) -> (u32, u32)
pub fn latest_progress(&self) -> (u32, u32)
(in-progress segment seq, count of live parts available for it) —
used to resolve blocking _HLS_msn/_HLS_part requests.
The second value is a count, not the last part’s index: the
blocking-reload resolver treats “part P ready” as count > P (0
means no parts of the in-progress segment are available yet).
pub (not pub(crate)) since issue #663 P4.2: multimux::output::ll_dash
needs the in-progress segment’s identity to address its live parts
(part-{track}-{seq}.{idx}.m4s) from a SegmentTemplate — the same
cross-crate exception already made for
Self::target_duration_secs/Self::part_target_ms/
Self::track_specs.
Sourcepub fn progress_version(&self) -> u64
pub fn progress_version(&self) -> u64
The current monotonic progress version — bumped by every mutation. Mostly useful for a caller wanting to detect “did anything change” without registering a listener (e.g. a cheap pre-check).
Sourcepub fn listen(&self) -> EventListener
pub fn listen(&self) -> EventListener
Register for the next change notification. Register before
re-checking the condition you’re waiting on (see this module’s
super-level doc for the wait-loop shape) — event-listener
guarantees any notify call that happens after listen() returns
will wake this listener, so there is no missed-wakeup race as long as
the re-check happens after listen(), not before.
The returned EventListener is a plain Future<Output = ()> — any
async runtime (or none, via its blocking .wait()) can drive it; this
is what keeps server runtime-agnostic (unlike a
tokio::sync::watch::Receiver, which only ever paired with tokio).
Sourcepub fn set_health(&self, state: HealthState)
pub fn set_health(&self, state: HealthState)
Set the route’s ingest health. Bumps the progress notification
only when the state actually changes, so a caller blocked on
Self::listen (e.g. an LL-HLS blocking playlist reload) wakes on a
health transition too, not just new media.
Sourcepub fn health(&self) -> HealthState
pub fn health(&self) -> HealthState
The current ingest health (default HealthState::Connecting until
the supervisor sets it).
Sourcepub fn target_duration_secs(&self) -> f64
pub fn target_duration_secs(&self) -> f64
The full-segment target duration, in seconds, this store was built
with — timing configuration a manifest renderer needs (e.g. LL-HLS’s
#EXT-X-TARGETDURATION, or a DASH Output’s minimumUpdatePeriod/
timeShiftBufferDepth). pub (not pub(crate)) since issue #663 P4:
multimux::output::dash needs it too, not just this crate’s own
engine.
Sourcepub fn part_target_ms(&self) -> u32
pub fn part_target_ms(&self) -> u32
The part target duration, in milliseconds, this store was built with.
pub for the same cross-Output reason as
Self::target_duration_secs.
Sourcepub fn created_at(&self) -> SystemTime
pub fn created_at(&self) -> SystemTime
Wall-clock time this store was constructed (issue #663 P4) — used as
a live DASH presentation’s availabilityStartTime anchor. An
approximation (the route’s start time, not the first segment’s
exact cut time — the first segment typically closes
target_duration_secs or so later), acceptable for a manifest
attribute that only needs to establish a consistent, monotonic
timeline, not wall-clock precision.
Sourcepub fn set_track_specs(&self, specs: Vec<TrackSpec>)
pub fn set_track_specs(&self, specs: Vec<TrackSpec>)
Store the track specs the feeding pipeline built its segmenter from —
called once, before the first sample is pushed. See
Inner::track_specs for why this exists (DASH’s codecs string
needs real codec identity; LL-HLS never reads this).
Sourcepub fn track_specs(&self) -> Vec<TrackSpec>
pub fn track_specs(&self) -> Vec<TrackSpec>
The track specs set by Self::set_track_specs, empty if never
called (e.g. in a test that only exercises playlist rendering).
Sourcepub fn window_segments(&self) -> Vec<SegmentWindowEntry>
pub fn window_segments(&self) -> Vec<SegmentWindowEntry>
Snapshot of the closed segments currently retained in the rolling
window, oldest first — enough for a manifest renderer to enumerate
fetchable segments (issue #663 P4: DASH’s SegmentTemplate/
$Number$ addressing) without depending on the LL-HLS-specific
playlist rendering in the playlist renderer.