pub struct Switcher<R, O> { /* private fields */ }Expand description
One incumbent and at most one replacement.
R is a running decoder and O the task opening one, so tests can use
stand-ins for both. Dropping a replacement drops its O and R, which
cancels its work.
Implementations§
Source§impl<R, O> Switcher<R, O>
impl<R, O> Switcher<R, O>
Sourcepub fn new(patience: Duration) -> Self
pub fn new(patience: Duration) -> Self
Creates a switcher with nothing playing.
patience is how long a replacement may take, from its request to
taking over, before it is given up.
Sourcepub fn switching_to(&self) -> Option<&Target>
pub fn switching_to(&self) -> Option<&Target>
Returns the target on its way in, if any.
Sourcepub fn deadline(&self) -> Option<Instant>
pub fn deadline(&self) -> Option<Instant>
Returns the moment the replacement is given up, if there is one.
Sourcepub fn replacement_generation(&self) -> Option<u64>
pub fn replacement_generation(&self) -> Option<u64>
Returns the generation of the replacement, if there is one.
Sourcepub fn incumbent_mut(&mut self) -> Option<&mut R>
pub fn incumbent_mut(&mut self) -> Option<&mut R>
Returns the running incumbent decoder.
Sourcepub fn opening_mut(&mut self) -> Option<&mut O>
pub fn opening_mut(&mut self) -> Option<&mut O>
Returns the open task of a replacement that is still opening.
Sourcepub fn warming_mut(&mut self) -> Option<&mut R>
pub fn warming_mut(&mut self) -> Option<&mut R>
Returns the decoder of a replacement that has opened.
Sourcepub fn request<E>(
&mut self,
target: Target,
now: Instant,
open: impl FnOnce(u64, &Target) -> O,
) -> Outcome<E>
pub fn request<E>( &mut self, target: Target, now: Instant, open: impl FnOnce(u64, &Target) -> O, ) -> Outcome<E>
Asks for target, starting at now.
Asking for the playing target withdraws the replacement. Asking for the
replacement’s target changes nothing. Anything else starts a new
replacement and supersedes the previous one. open gets the new
generation and target, and builds the task that opens the decoder.
Returns the replacement this request withdrew or superseded, if any.
Sourcepub fn opened<E>(&mut self, generation: u64, result: Result<R, E>) -> Outcome<E>
pub fn opened<E>(&mut self, generation: u64, result: Result<R, E>) -> Outcome<E>
Records that the replacement of generation finished opening.
Sourcepub fn incumbent_frame(&mut self, pts: Duration)
pub fn incumbent_frame(&mut self, pts: Duration)
Records that the incumbent decoded a picture at pts.
Sourcepub fn replacement_frame<E>(
&mut self,
pts: Duration,
now: Instant,
) -> (Verdict, Outcome<E>)
pub fn replacement_frame<E>( &mut self, pts: Duration, now: Instant, ) -> (Verdict, Outcome<E>)
Decides what to do with a replacement picture at pts, arriving at now.
Promotes the replacement once pts has caught up with the incumbent’s
playhead, or once CATCH_UP_PATIENCE has passed since its first
picture. The caller then shows this picture and drops any pending
incumbent picture.
Sourcepub fn release_incumbent(&mut self)
pub fn release_incumbent(&mut self)
Drops the incumbent, so the replacement takes over on its first picture.
For a step down on a link that cannot carry the incumbent: while both overlap they share the link, and the replacement’s groups age out before they arrive. The caller keeps its last picture up.
Sourcepub fn incumbent_ended<E>(&mut self) -> Outcome<E>
pub fn incumbent_ended<E>(&mut self) -> Outcome<E>
Records that the incumbent’s track ended.
Without a replacement on its way, the video has ended.
Sourcepub fn replacement_ended<E>(&mut self) -> Outcome<E>
pub fn replacement_ended<E>(&mut self) -> Outcome<E>
Records that the replacement’s track ended before it took over.