Skip to main content

OpusDecoder

Struct OpusDecoder 

Source
pub struct OpusDecoder { /* private fields */ }
Expand description

Stateful Opus decoder for one inbound stream.

Also not Copy — the decoder state is what makes conceal and decode_fec possible, so it must see every packet of its stream in order.

Implementations§

Source§

impl OpusDecoder

Source

pub fn new() -> Result<Self, CoreError>

Create a decoder producing 16 kHz mono PCM.

Source

pub fn decode( &mut self, payload: &[u8], out: &mut Vec<i16>, ) -> Result<usize, CoreError>

Decode one received Opus packet. Appends the PCM samples to out and returns how many were produced.

The count is normally OPUS_FRAME_SAMPLES but the far end chooses its own frame size — up to OPUS_MAX_FRAME_SAMPLES — so consumers must use the returned length, not assume 20 ms.

Source

pub fn decode_fec( &mut self, next_payload: &[u8], out: &mut Vec<i16>, ) -> Result<usize, CoreError>

Recover a lost frame from the packet that followed it.

Call this when a sequence gap shows exactly one packet was lost: pass the packet after the gap, and the decoder reconstructs the missing frame from that packet’s embedded redundancy (falling back to concealment when the sender embedded none). Then decode the passed packet normally with decode — this call consumes only its redundancy, not its own frame.

Source

pub fn conceal(&mut self, out: &mut Vec<i16>) -> Result<usize, CoreError>

Produce one concealment frame for a packet that never arrived and can’t be recovered (no follow-up packet yet, or a multi-packet gap). The decoder extrapolates from what it last heard, which sounds far better than a gap of silence.

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.