pub trait AudioDecoder: Send + Sync {
// Required methods
fn reset(&mut self);
fn codec_info(&self) -> &CodecInfo;
fn codec_params(&self) -> &AudioCodecParameters;
fn decode_ref(
&mut self,
packet: &PacketRef<'_>,
) -> Result<GenericAudioBufferRef<'_>>;
fn finalize(&mut self) -> FinalizeResult;
fn last_decoded(&self) -> GenericAudioBufferRef<'_>;
// Provided method
fn decode(&mut self, packet: &Packet) -> Result<GenericAudioBufferRef<'_>> { ... }
}Expand description
An AudioDecoder implements an audio codec’s decode algorithm. It consumes Packets and
produces buffers of PCM audio.
Required Methods§
Sourcefn reset(&mut self)
fn reset(&mut self)
Reset the decoder.
A decoder must be reset when the next packet is discontinuous with respect to the last decoded packet. Most notably, this occurs after a seek.
§For Implementations
For codecs that do a lot of pre-computation, reset should only reset the absolute minimum amount of state.
Sourcefn codec_info(&self) -> &CodecInfo
fn codec_info(&self) -> &CodecInfo
Get basic information about the codec.
Sourcefn codec_params(&self) -> &AudioCodecParameters
fn codec_params(&self) -> &AudioCodecParameters
Gets a reference to an updated set of AudioCodecParameters based on the codec parameters
the decoder was instantiated with.
Sourcefn decode_ref(
&mut self,
packet: &PacketRef<'_>,
) -> Result<GenericAudioBufferRef<'_>>
fn decode_ref( &mut self, packet: &PacketRef<'_>, ) -> Result<GenericAudioBufferRef<'_>>
Decodes a PacketRef of audio data and returns a generic (untyped) audio buffer reference
containing the decoded audio.
This method is identical to decode but takes a PacketRef for zero-copy packet passing.
Sourcefn finalize(&mut self) -> FinalizeResult
fn finalize(&mut self) -> FinalizeResult
Optionally, obtain post-decode information such as the verification status.
Sourcefn last_decoded(&self) -> GenericAudioBufferRef<'_>
fn last_decoded(&self) -> GenericAudioBufferRef<'_>
Allows read access to the internal audio buffer.
After a successful call to decode, this will contain the audio content of the last decoded
Packet. If the last call to decode resulted in an error, then implementors must ensure
the returned audio buffer has zero length.
Provided Methods§
Sourcefn decode(&mut self, packet: &Packet) -> Result<GenericAudioBufferRef<'_>>
fn decode(&mut self, packet: &Packet) -> Result<GenericAudioBufferRef<'_>>
Decodes a Packet of audio data and returns a generic (untyped) audio buffer reference
containing the decoded audio.
If a DecodeError or IoError is returned, the packet is undecodeable and should be
discarded. Decoding may be continued with the next packet. If ResetRequired is returned,
consumers of the decoded audio data should expect the duration and audio specification of
the decoded audio buffer to change. All other errors are unrecoverable.
Implementors of decoders must clear the internal audio buffer if an error occurs.