Skip to main content

OpusDecoder

Struct OpusDecoder 

Source
pub struct OpusDecoder {
    pub last_range: u32,
    /* private fields */
}
Expand description

An Opus decoder for one mono or stereo stream.

Decodes packets from any Opus encoder at any of the five API rates and either channel count (a stereo stream can be decoded to mono and vice versa). Pass an empty packet to conceal a lost one. After the first few frames, decoding performs no heap allocation.

Fields§

§last_range: u32

Final range-decoder state of the last decoded packet (libopus OPUS_GET_FINAL_RANGE): equal to the encoder’s for a correctly transmitted packet, so it detects corruption and desynchronisation.

Implementations§

Source§

impl OpusDecoder

Source

pub fn new(sampling_rate: i32, channels: usize) -> Result<Self, Error>

§Errors

Error::BadArg if sampling_rate is not 8000, 12000, 16000, 24000 or 48000 Hz or channels is not 1 or 2.

Source

pub fn decode_fec( &mut self, packet: &[u8], frame_size: usize, output: &mut [f32], ) -> Result<usize, Error>

Forward-error-correction decode: reconstruct a LOST frame from the LBRR (low-bitrate redundancy) embedded in the NEXT received packet. Drives the SILK decoder in FLAG_DECODE_LBRR mode, which self-selects: it decodes the redundant frame when the packet carries LBRR for it, and falls back to PLC extrapolation when it doesn’t. CELT-only or multi-frame packets fall back to plain PLC (no SILK LBRR to recover). After this call the caller decodes packet normally for the following frame.

§Errors

Error::InvalidPacket if input is malformed or truncated; Error::BufferTooSmall if frame_size exceeds the decoder’s capacity or output; Error::Internal if a codec stage fails.

Source

pub fn decode( &mut self, input: &[u8], frame_size: usize, output: &mut [f32], ) -> Result<usize, Error>

§Errors

Error::InvalidPacket if input is malformed, truncated, or longer than 120 ms; Error::BufferTooSmall if output cannot hold the decoded frame; Error::Internal if a codec stage fails. A malformed packet never panics.

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 = !

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.