Skip to main content

Switcher

Struct Switcher 

Source
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>

Source

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.

Source

pub fn current(&self) -> Option<&Target>

Returns the target playing, if any.

Source

pub fn switching_to(&self) -> Option<&Target>

Returns the target on its way in, if any.

Source

pub fn deadline(&self) -> Option<Instant>

Returns the moment the replacement is given up, if there is one.

Source

pub fn replacement_generation(&self) -> Option<u64>

Returns the generation of the replacement, if there is one.

Source

pub fn incumbent_mut(&mut self) -> Option<&mut R>

Returns the running incumbent decoder.

Source

pub fn opening_mut(&mut self) -> Option<&mut O>

Returns the open task of a replacement that is still opening.

Source

pub fn warming_mut(&mut self) -> Option<&mut R>

Returns the decoder of a replacement that has opened.

Source

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.

Source

pub fn opened<E>(&mut self, generation: u64, result: Result<R, E>) -> Outcome<E>

Records that the replacement of generation finished opening.

Source

pub fn incumbent_frame(&mut self, pts: Duration)

Records that the incumbent decoded a picture at pts.

Source

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.

Source

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.

Source

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.

Source

pub fn replacement_ended<E>(&mut self) -> Outcome<E>

Records that the replacement’s track ended before it took over.

Source

pub fn expire<E>(&mut self, now: Instant) -> Outcome<E>

Gives the replacement up if its deadline has passed at now.

Trait Implementations§

Source§

impl<R: Debug, O: Debug> Debug for Switcher<R, O>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, O> Freeze for Switcher<R, O>
where R: Freeze, O: Freeze,

§

impl<R, O> RefUnwindSafe for Switcher<R, O>

§

impl<R, O> Send for Switcher<R, O>
where R: Send, O: Send,

§

impl<R, O> Sync for Switcher<R, O>
where R: Sync, O: Sync,

§

impl<R, O> Unpin for Switcher<R, O>
where R: Unpin, O: Unpin,

§

impl<R, O> UnsafeUnpin for Switcher<R, O>
where R: UnsafeUnpin, O: UnsafeUnpin,

§

impl<R, O> UnwindSafe for Switcher<R, O>
where R: UnwindSafe, O: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more