Skip to main content

AudioPacketProvider

Trait AudioPacketProvider 

Source
pub trait AudioPacketProvider: Send {
    // Required methods
    fn len(&self) -> usize;
    fn decoded_range(&self, index: usize) -> SampleRange;
    fn read(&self, index: usize) -> Result<Cow<'_, [u8]>>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Supplies AudioSampleReader with compressed audio packets by index, so a reader does not have to own every packet of a track up front.

An owned Vec<EncodedAudioSample> implements this directly and is what AudioSampleReader::new wraps, so that constructor and its callers are unchanged. AudioSampleReader::from_provider accepts any other implementation, such as one that reads through a container track’s index and a crate::io::ByteSource on demand.

len and decoded_range answer from the index alone and must not read packet data; only Self::read may do that, and only for the one packet it is asked for. So a provider has to know every packet’s decoded interval before it reads any packet, which depends on the codec. An AAC packet’s comes from the track’s sample durations. A Vorbis packet’s depends on its own block size and the previous packet’s, which the mode number in each packet’s first byte names; the WebM demuxer records those bytes as it indexes the track. An Opus packet’s own table of contents gives its interval, so an Opus provider takes it from the sample table and checks each packet as it reads it. zvidlib-container’s TrackAudioPacketProvider is the on-demand provider for AAC and Vorbis tracks, and its TrackSampleLoader builds non-blocking providers for all three codecs.

Implementations used from a decode thread must be Send.

Required Methods§

Source

fn len(&self) -> usize

The number of packets.

Source

fn decoded_range(&self, index: usize) -> SampleRange

Source

fn read(&self, index: usize) -> Result<Cow<'_, [u8]>>

Returns the compressed bytes of one packet.

Provided Methods§

Source

fn is_empty(&self) -> bool

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AudioPacketProvider for Vec<EncodedAudioSample>

Source§

fn len(&self) -> usize

Source§

fn decoded_range(&self, index: usize) -> SampleRange

Source§

fn read(&self, index: usize) -> Result<Cow<'_, [u8]>>

Implementors§