pub trait Decoder: Send + Sync {
// Required methods
fn decode_into(
&mut self,
data: &[u8],
out: &mut [Sample],
) -> Result<usize, CodecError>;
fn max_decode_samples(&self, n_bytes: usize) -> usize;
fn sample_rate(&self) -> u32;
fn channels(&self) -> u16;
// Provided method
fn decode(&mut self, data: &[u8]) -> PcmBuf { ... }
}Expand description
Decoder trait: converts codec-specific bytes into PCM samples.
The slice-based decode_into is the primary, always-available method
(works in no_std). The convenience decode returning a Vec is only
available with the std feature and has a default implementation that
delegates to decode_into.
Required Methods§
Sourcefn decode_into(
&mut self,
data: &[u8],
out: &mut [Sample],
) -> Result<usize, CodecError>
fn decode_into( &mut self, data: &[u8], out: &mut [Sample], ) -> Result<usize, CodecError>
Decode data into out, returning the number of samples written.
Returns CodecError::BufferTooSmall if out cannot hold the
decoded samples (use max_decode_samples to size it).
Sourcefn max_decode_samples(&self, n_bytes: usize) -> usize
fn max_decode_samples(&self, n_bytes: usize) -> usize
Upper bound on the number of samples that decode_into will write
for an input of n_bytes bytes.
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Get the sample rate of the decoded audio.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".