Skip to main content

Received

Enum Received 

Source
pub enum Received {
    Frame,
    NeedsInput,
    Ended,
}
Expand description

What a drain call answered.

Returned by every receive_frame in this crate — VideoStreamDecoder, AudioStreamDecoder, SubtitleDecoder, AudioResampler, and their future mirrors — so one vocabulary covers every backend and every generic consumer.

§The drain loop

use mediadecode::{Received, decoder::AudioStreamDecoder};
/// Drains everything ready right now. Answers `true` once the
/// stream is over, so the caller knows not to feed it again.
fn drain<D: AudioStreamDecoder>(
  decoder: &mut D,
  dst: &mut Frame<D>,
  mut on_frame: impl FnMut(&Frame<D>),
) -> Result<bool, D::Error> {
  loop {
    // `?` means what it says again: only a fault leaves here.
    match decoder.receive_frame(dst)? {
      Received::Frame => on_frame(dst),
      Received::NeedsInput => return Ok(false),
      Received::Ended => return Ok(true),
    }
  }
}

The loop terminates by construction: the two non-frame arms both return, and neither can be reached without the callee having decided which one it is. Under the older convention — both conditions arriving as unnamed Err variants — a caller that had already sent end-of-stream could not tell “send me more” from “there is no more”, and a drain that answered the first forever was an ordinary, silent infinite loop.

Variants§

§

Frame

A frame was written into dst. Take it and call again.

§

NeedsInput

Nothing is ready. The session is waiting on input: send another packet (or frame, for a resampler), or signal end-of-stream and drain the tail.

Never returned after the stream has ended — that is Ended’s job, and keeping the two apart is what makes a drain loop terminate.

§

Ended

The stream is over and every buffered frame has been delivered. Nothing but flush changes this answer.

Implementations§

Source§

impl Received

Source

pub const fn is_frame(&self) -> bool

Returns true if this value is of type Frame. Returns false otherwise

Source

pub const fn is_needs_input(&self) -> bool

Returns true if this value is of type NeedsInput. Returns false otherwise

Source

pub const fn is_ended(&self) -> bool

Returns true if this value is of type Ended. Returns false otherwise

Trait Implementations§

Source§

impl Clone for Received

Source§

fn clone(&self) -> Received

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Received

Source§

impl Debug for Received

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Received

Source§

impl Hash for Received

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Received

Source§

fn eq(&self, other: &Received) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Received

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <T as TryFrom<U>>::Error>

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.