pub struct AudioSampleReader<D> { /* private fields */ }Expand description
Exact presentation-range access over a track’s sequential audio packets.
Implementations§
Source§impl<D: AudioDecoder> AudioSampleReader<D>
impl<D: AudioDecoder> AudioSampleReader<D>
Sourcepub fn new(
decoder: D,
packets: Vec<EncodedAudioSample>,
sample_rate: u32,
channels: u16,
timing: AudioTrackTiming,
preroll_packets: usize,
limits: Limits,
) -> Result<Self>
pub fn new( decoder: D, packets: Vec<EncodedAudioSample>, sample_rate: u32, channels: u16, timing: AudioTrackTiming, preroll_packets: usize, limits: Limits, ) -> Result<Self>
preroll_packets is how many packets before the first one a request
needs are decoded first after a reset, so the decoder’s state has
converged by the time it reaches the samples that are returned.
Sourcepub fn from_provider(
decoder: D,
packets: Box<dyn AudioPacketProvider>,
sample_rate: u32,
channels: u16,
timing: AudioTrackTiming,
preroll_packets: usize,
limits: Limits,
) -> Result<Self>
pub fn from_provider( decoder: D, packets: Box<dyn AudioPacketProvider>, sample_rate: u32, channels: u16, timing: AudioTrackTiming, preroll_packets: usize, limits: Limits, ) -> Result<Self>
Builds a reader over any AudioPacketProvider, such as one that
reads compressed bytes from a container track and a
crate::io::ByteSource on demand instead of owning every packet.
Behaves exactly as Self::new, which is this constructor with an
owned Vec<EncodedAudioSample> as the provider.
The packets’ intervals must be contiguous. They normally start at zero, as a whole track’s do; a provider holding only a window of a track’s packets starts at its first packet’s interval, and the reader then refuses requests for samples before it.
Sourcepub fn replace_packets(
&mut self,
packets: Box<dyn AudioPacketProvider>,
timing: AudioTrackTiming,
) -> Result<()>
pub fn replace_packets( &mut self, packets: Box<dyn AudioPacketProvider>, timing: AudioTrackTiming, ) -> Result<()>
Reads from packets and with timing from now on, for a track whose
packets are indexed as playback reaches them (issue #692): a window of
them that grows as playback goes on, or a new one where a seek lands.
When packets begins with every packet the reader had, at the same
intervals, the decoder and the samples it has decoded are kept, so
reading on past the old window’s end continues the decode rather than
resetting it. Otherwise both are dropped, as Self::reset does. The
packets are validated as Self::from_provider validates them.
Sourcepub fn packet_count(&self) -> usize
pub fn packet_count(&self) -> usize
The number of packets the reader reads from.
pub const fn sample_rate(&self) -> u32
pub const fn channels(&self) -> u16
pub const fn presentation_length(&self) -> u64
pub fn timing(&self) -> &AudioTrackTiming
Sourcepub fn get_range(
&mut self,
range: SampleRange,
cancellation: &CancellationToken,
) -> Result<AudioBuffer>
pub fn get_range( &mut self, range: SampleRange, cancellation: &CancellationToken, ) -> Result<AudioBuffer>
Returns exactly the requested contiguous half-open presentation range.
pub fn get( &mut self, timeline: Timeline, frame: FrameIndex, cancellation: &CancellationToken, ) -> Result<AudioBuffer>
Sourcepub fn packets_for_range(&self, range: SampleRange) -> Result<Vec<Range<usize>>>
pub fn packets_for_range(&self, range: SampleRange) -> Result<Vec<Range<usize>>>
The packets whose compressed bytes Self::get_range of range reads from the provider,
as runs of packet indexes, so a caller can load them before asking.
Each run is what one of the request’s media ranges decodes from the reader’s current
state: nothing when its packets are already decoded, the packets after the decoded run
when the request continues it, and the preroll packets onwards when it resets. A request
whose provider reports ErrorKind::WouldBlock for a packet keeps what it decoded before
it, so asking again once that packet is loaded carries on from there.