Expand description
Non-blocking access to a track’s compressed samples over a ByteSource
whose reads genuinely suspend, such as a browser fetch or HTTP range
request (issue #672).
TrackSampleProvider reads through its source from inside
ExactFrameReader::get, which is synchronous, so it can only drive a
source that resolves on the first poll. This module splits the read in two
instead. A TrackSampleLoader owns the track’s index and the source, and
loads samples asynchronously into a byte-budgeted cache. The providers it
hands out answer a reader’s synchronous reads from that cache alone and
report ErrorKind::WouldBlock for a sample that is not loaded yet rather
than blocking. A provider remembers every sample it was asked for and did
not have, so the caller awaits TrackSampleLoader::load_missing and asks
again:
let frame = loop {
match reader.get(frame_index, &cancellation) {
Err(error) if error.kind() == ErrorKind::WouldBlock => {
loader.load_missing().await?;
}
result => break result?,
}
};Both readers leave their state resumable when a provider read fails, so the
retry carries on from the sample that was missing rather than decoding the
run again from its random-access point. Loading the run a request needs
before making it turns those per-sample round trips into one batch:
ExactFrameReader::decode_positions_for and
AudioSampleReader::packets_for_range name it, and
TrackSampleLoader::load loads it together with a playback readahead.
Structs§
- Prefetched
Audio Packet Provider - An
AudioPacketProviderthat answers from aTrackSampleLoader’s cache and reportsErrorKind::WouldBlockfor a packet that is not loaded yet. - Prefetched
Sample Provider - A
SampleProviderthat answers from aTrackSampleLoader’s cache and reportsErrorKind::WouldBlockfor a sample that is not loaded yet. - Sample
Cache - A byte-budgeted cache of compressed samples that several
TrackSampleLoaders can share, so loaders over different parts of one track - a lazily indexed WebM’s cue spans (issue #692) - hold no more between them than one budget allows. - Track
Sample Loader - Loads a track’s compressed samples from a
ByteSourceasynchronously, ahead of the synchronous readers that decode them.