pub struct DecoderRef<'a> { /* private fields */ }Expand description
Borrowed wrapper around a decoder state.
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)- The memory must remain valid for the lifetime
'a - Caller is responsible for freeing the memory after this wrapper is dropped
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.
Methods from Deref<Target = Decoder>§
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>
Decode a packet into 16-bit PCM.
input: Opus packet bytes. Pass empty slice to invoke PLC.output: Interleaved output buffer sized toframe_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.
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>
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.
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 reset(&mut self) -> Result<()>
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.
Sourcepub fn sample_rate(&self) -> SampleRate
pub fn sample_rate(&self) -> SampleRate
The decoder’s configured sample rate.
Sourcepub fn get_sample_rate(&mut self) -> Result<i32>
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.
Sourcepub fn get_pitch(&mut self) -> Result<i32>
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.
Sourcepub fn get_last_packet_duration(&mut self) -> Result<i32>
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.
Sourcepub fn final_range(&mut self) -> Result<u32>
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.
Sourcepub fn set_gain(&mut self, q8_db: i32) -> Result<()>
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.
Sourcepub fn gain(&mut self) -> Result<i32>
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.
Sourcepub fn phase_inversion_disabled(&mut self) -> Result<bool>
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.
Sourcepub fn set_phase_inversion_disabled(&mut self, disabled: bool) -> Result<()>
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.