Decoder

Struct Decoder 

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

Safe wrapper around a libopus OpusDecoder.

Implementations§

Source§

impl Decoder

Source

pub fn size(channels: Channels) -> Result<usize>

Size in bytes of a decoder state for external allocation.

§Errors

Returns Error::BadArg if the channel count is invalid or libopus reports an impossible size.

Source

pub unsafe fn init_in_place( ptr: *mut OpusDecoder, sample_rate: SampleRate, channels: Channels, ) -> Result<()>

Initialize a previously allocated decoder state.

§Safety

The caller must provide a valid pointer to Decoder::size() bytes, aligned to at least align_of::<usize>() (malloc-style alignment).

§Errors

Returns Error::BadArg if ptr is null, or a mapped libopus error.

Source

pub fn new(sample_rate: SampleRate, channels: Channels) -> Result<Self>

Create a new decoder for a given sample rate and channel layout.

§Errors

Returns an error if allocation fails or arguments are invalid.

Source

pub fn decode( &mut self, input: &[u8], output: &mut [i16], fec: bool, ) -> Result<usize>

Decode a packet into 16-bit PCM.

  • input: Opus packet bytes. Pass empty slice to invoke PLC.
  • output: Interleaved output buffer sized to frame_size * channels.
  • fec: Enable in-band FEC if available.
§Errors

Returns Error::InvalidState if the decoder handle is invalid, Error::BadArg for invalid buffer sizes or frame sizes, or a mapped libopus error via Error::from_code.

Source

pub fn decode_float( &mut self, input: &[u8], output: &mut [f32], fec: bool, ) -> Result<usize>

Decode a packet into f32 PCM.

See Self::decode for parameter semantics.

§Errors

Returns Error::InvalidState if the decoder handle is invalid, Error::BadArg for invalid buffer sizes or frame sizes, or a mapped libopus error via Error::from_code.

Source

pub fn packet_samples(&self, packet: &[u8]) -> Result<usize>

Return the number of samples (per channel) in an Opus packet at this decoder’s rate.

§Errors

Returns Error::InvalidState if the decoder is invalid, Error::BadArg for overlong input, or a mapped libopus error.

Source

pub fn packet_bandwidth(&self, packet: &[u8]) -> Result<Bandwidth>

Return the bandwidth encoded in an Opus packet.

§Errors

Returns Error::InvalidState if the decoder is invalid, or Error::InvalidPacket if the packet cannot be parsed.

Source

pub fn packet_channels(&self, packet: &[u8]) -> Result<Channels>

Return the number of channels described by an Opus packet.

§Errors

Returns Error::InvalidState if the decoder is invalid, or Error::InvalidPacket if the packet cannot be parsed.

Source

pub fn reset(&mut self) -> Result<()>

Reset the decoder to its initial state.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error if resetting fails.

Source

pub const fn sample_rate(&self) -> SampleRate

The decoder’s configured sample rate.

Source

pub const fn channels(&self) -> Channels

The decoder’s channel configuration.

Source

pub fn get_sample_rate(&mut self) -> Result<i32>

Query decoder output sample rate.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn get_pitch(&mut self) -> Result<i32>

Query pitch (fundamental period) of the last decoded frame (in samples at 48 kHz domain).

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn get_last_packet_duration(&mut self) -> Result<i32>

Duration (per channel) of the last decoded packet.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn final_range(&mut self) -> Result<u32>

Final RNG state after the last decode.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn set_gain(&mut self, q8_db: i32) -> Result<()>

Set post-decode gain in Q8 dB units.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn gain(&mut self) -> Result<i32>

Query post-decode gain in Q8 dB units.

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn phase_inversion_disabled(&mut self) -> Result<bool>

Returns true if phase inversion is disabled (CELT stereo decorrelation).

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Source

pub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>

Disable/enable phase inversion (CELT stereo decorrelation).

§Errors

Returns Error::InvalidState if the decoder is invalid, or a mapped libopus error.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.