pub trait Decoder: Send + Sync {
    // Required methods
    fn try_new(
        params: &CodecParameters,
        options: &DecoderOptions
    ) -> Result<Self>
       where Self: Sized;
    fn supported_codecs() -> &'static [CodecDescriptor]
       where Self: Sized;
    fn reset(&mut self);
    fn codec_params(&self) -> &CodecParameters;
    fn decode(&mut self, packet: &Packet) -> Result<AudioBufferRef<'_>>;
    fn finalize(&mut self) -> FinalizeResult;
    fn last_decoded(&self) -> AudioBufferRef<'_>;
}
Expand description

A Decoder implements a codec’s decode algorithm. It consumes Packets and produces AudioBuffers.

Required Methods§

source

fn try_new(params: &CodecParameters, options: &DecoderOptions) -> Result<Self>
where Self: Sized,

Attempts to instantiates a Decoder using the provided CodecParameters.

source

fn supported_codecs() -> &'static [CodecDescriptor]
where Self: Sized,

Gets a list of codec descriptors for the codecs supported by this Decoder.

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 codecs that do a lot of pre-computation, reset should only reset the absolute minimum amount of state.

source

fn codec_params(&self) -> &CodecParameters

Gets a reference to an updated set of CodecParameters based on the parameters the Decoder was instantiated with.

source

fn decode(&mut self, packet: &Packet) -> Result<AudioBufferRef<'_>>

Decodes a Packet of audio data and returns a copy-on-write generic (untyped) audio buffer of 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 SignalSpec of the decoded audio buffer to change. All other errors are unrecoverable.

Implementors of decoders must clear the internal buffer if an error occurs.

source

fn finalize(&mut self) -> FinalizeResult

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

source

fn last_decoded(&self) -> AudioBufferRef<'_>

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.

Implementors§