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§
fn decoded_range(&self, index: usize) -> SampleRange
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".