pub struct Decoder { /* private fields */ }Expand description
Safe wrapper around a libopus OpusDecoder.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn size(channels: Channels) -> Result<usize>
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.
Sourcepub unsafe fn init_in_place(
ptr: *mut OpusDecoder,
sample_rate: SampleRate,
channels: Channels,
) -> Result<()>
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.
Sourcepub fn new(sample_rate: SampleRate, channels: Channels) -> Result<Self>
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.
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 const fn sample_rate(&self) -> SampleRate
pub const 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.