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>
impl<'a> DecoderRef<'a>
Sourcepub unsafe fn from_raw(
ptr: *mut OpusDecoder,
sample_rate: SampleRate,
channels: Channels,
) -> Self
pub unsafe fn from_raw( ptr: *mut OpusDecoder, sample_rate: SampleRate, channels: Channels, ) -> Self
Wrap an externally-initialized decoder without taking ownership.
§Safety
ptrmust point to valid, initialized memory of at leastDecoder::size()bytesptrmust be aligned to at leastalign_of::<usize>()(malloc-style alignment)sample_rateandchannelsmust exactly match the decoder state already stored atptr- 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_blobbefore callingDecoderRef::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.
Sourcepub fn init_in(
buf: &'a mut AlignedBuffer,
sample_rate: SampleRate,
channels: Channels,
) -> Result<Self>
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.
Sourcepub fn decode(
&mut self,
input: &[u8],
output: &mut [i16],
fec: bool,
) -> Result<usize>
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.
Sourcepub fn decode_float(
&mut self,
input: &[u8],
output: &mut [f32],
fec: bool,
) -> Result<usize>
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.
Sourcepub fn get_sample_rate(&mut self) -> Result<i32>
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.
Sourcepub fn get_pitch(&mut self) -> Result<i32>
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.
Sourcepub fn get_last_packet_duration(&mut self) -> Result<i32>
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.
Sourcepub fn final_range(&mut self) -> Result<u32>
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.
Sourcepub fn set_gain(&mut self, q8_db: i32) -> Result<()>
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.
Sourcepub fn gain(&mut self) -> Result<i32>
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.
Sourcepub fn phase_inversion_disabled(&mut self) -> Result<bool>
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.
Methods from Deref<Target = Decoder>§
Sourcepub fn packet_samples(&self, packet: &[u8]) -> Result<usize>
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.
Sourcepub fn packet_bandwidth(&self, packet: &[u8]) -> Result<Bandwidth>
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.
Sourcepub fn packet_channels(&self, packet: &[u8]) -> Result<Channels>
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.
Sourcepub fn sample_rate(&self) -> SampleRate
pub fn sample_rate(&self) -> SampleRate
The decoder’s configured sample rate.