Skip to main content

DecoderRef

Struct DecoderRef 

Source
pub struct DecoderRef<'a> { /* private fields */ }
Expand description

Borrowed wrapper around a decoder state.

The owning handle cannot be moved out of this borrowed wrapper:

use opus_codec::decoder::DecoderRef;
use opus_codec::Decoder;
fn extract<'a>(state: &mut DecoderRef<'a>, replacement: Decoder) -> Decoder {
    std::mem::replace(&mut **state, replacement)
}

Implementations§

Source§

impl<'a> DecoderRef<'a>

Source

pub unsafe fn from_raw( ptr: *mut OpusDecoder, sample_rate: SampleRate, channels: Channels, ) -> Self

Wrap an externally-initialized decoder without taking ownership.

§Safety
  • ptr must point to valid, initialized memory of at least Decoder::size() bytes
  • ptr must be aligned to at least align_of::<usize>() (malloc-style alignment)
  • sample_rate and channels must exactly match the decoder state already stored at ptr
  • The memory must remain valid for the lifetime 'a
  • Caller is responsible for freeing the memory after this wrapper is dropped
  • If the external state already uses runtime-loaded DNN weights, register that blob again through DecoderRef::set_dnn_blob before calling DecoderRef::reset

Passing mismatched metadata is undefined behavior: later safe methods may validate buffer sizes against the wrong channel/rate and then call libopus with out-of-bounds buffers.

§Panics

Panics if ptr is null or not pointer-aligned.

Use Decoder::init_in_place to initialize the memory before calling this.

Source

pub fn init_in( buf: &'a mut AlignedBuffer, sample_rate: SampleRate, channels: Channels, ) -> Result<Self>

Initialize and wrap an externally allocated buffer.

§Errors

Returns Error::BadArg if the buffer is too small, or a mapped libopus error.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Calls the corresponding operation on this borrowed libopus state.

§Errors

Returns the same errors as the corresponding owning-handle method.

Source

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

Reset the decoder and restore the last successfully registered external DNN model.

§Errors

Returns a mapped libopus error if the reset or model restoration fails.

Methods from Deref<Target = Decoder>§

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 sample_rate(&self) -> SampleRate

The decoder’s configured sample rate.

Source

pub fn channels(&self) -> Channels

The decoder’s channel configuration.

Trait Implementations§

Source§

impl Deref for DecoderRef<'_>

Source§

type Target = Decoder

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Send for DecoderRef<'_>

Auto Trait Implementations§

§

impl<'a> !Sync for DecoderRef<'a>

§

impl<'a> !UnwindSafe for DecoderRef<'a>

§

impl<'a> Freeze for DecoderRef<'a>

§

impl<'a> RefUnwindSafe for DecoderRef<'a>

§

impl<'a> Unpin for DecoderRef<'a>

§

impl<'a> UnsafeUnpin for DecoderRef<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.