pub struct SessionStore { /* private fields */ }Expand description
Per-session ad-break records.
A BTreeMap keyed by session id: the records here are small (one
BreakState per session, per the module’s design decision), so there
is no per-peer media state to bound with a cursor count the way
media-plane’s Trunk must. The store is nonetheless bounded: it holds at
most DEFAULT_MAX_SESSIONS sessions (or the bound set by
Self::with_max_sessions), and Self::begin_break for a new session id
past that is Error::SessionStoreFull, so a flood of distinct ids cannot
grow it forever. This crate has no clock of its own: the caller feeds the
time in with Self::advance and calls Self::expire_idle to drop
sessions nobody has touched for a while; Self::end evicts one directly.
Implementations§
Source§impl SessionStore
impl SessionStore
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty store bounded at DEFAULT_MAX_SESSIONS.
Sourcepub fn with_max_sessions(self, max_sessions: usize) -> Self
pub fn with_max_sessions(self, max_sessions: usize) -> Self
Bounds the store at max_sessions tracked sessions (at least 1).
Sourcepub fn advance(&mut self, now_us: u64)
pub fn advance(&mut self, now_us: u64)
Moves the store’s clock to now_us (microseconds on any monotonic
timeline the caller keeps; a value earlier than the current one is
ignored). Records touched from now on carry this time.
Sourcepub fn expire_idle(&mut self, ttl_us: u64) -> usize
pub fn expire_idle(&mut self, ttl_us: u64) -> usize
Evicts every session last touched (by Self::begin_break or
Self::resume) more than ttl_us before the store’s clock; returns
how many were evicted.
Sourcepub fn begin_break(
&mut self,
session_id: impl Into<String>,
state: BreakState,
) -> Result<()>
pub fn begin_break( &mut self, session_id: impl Into<String>, state: BreakState, ) -> Result<()>
Start a break for session_id. Errors with
Error::BreakAlreadyActive if the session already has an
unresumed break — call Self::resume or Self::end first — and
with Error::SessionStoreFull if session_id is new and the store
is at its bound.
Sourcepub fn resume(
&mut self,
session_id: &str,
resumed_at: ConditionedSplicePoint,
) -> Result<()>
pub fn resume( &mut self, session_id: &str, resumed_at: ConditionedSplicePoint, ) -> Result<()>
Record the resumption point for session_id’s active break. Errors
with Error::NoActiveBreak if there is no record for the session and
with Error::BreakAlreadyResumed if its break was already resumed
(the first resumption point is kept).
Sourcepub fn get(&self, session_id: &str) -> Option<&BreakState>
pub fn get(&self, session_id: &str) -> Option<&BreakState>
The current break record for session_id, if any. A resumed record
stays until Self::end evicts it, so a caller can still render the
just-ended break’s EXT-X-DATERANGE for one more playlist reload.
Sourcepub fn end(&mut self, session_id: &str) -> Option<BreakState>
pub fn end(&mut self, session_id: &str) -> Option<BreakState>
Evict session_id’s record entirely (session ended, or its break has
aged out of the sliding window). Returns the evicted record, if any.