Skip to main content

AudioDecoder

Trait AudioDecoder 

Source
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§

Source

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.

Source

fn codec_info(&self) -> &CodecInfo

Get basic information about the codec.

Source

fn codec_params(&self) -> &AudioCodecParameters

Gets a reference to an updated set of AudioCodecParameters based on the codec parameters the decoder was instantiated with.

Source

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.

Source

fn finalize(&mut self) -> FinalizeResult

Optionally, obtain post-decode information such as the verification status.

Source

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§

Source

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.

Implementors§