Skip to main content

AudioSampleReader

Struct AudioSampleReader 

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub fn packet_count(&self) -> usize

The number of packets the reader reads from.

Source

pub const fn sample_rate(&self) -> u32

Source

pub const fn channels(&self) -> u16

Source

pub const fn presentation_length(&self) -> u64

Source

pub fn timing(&self) -> &AudioTrackTiming

Source

pub fn get_range( &mut self, range: SampleRange, cancellation: &CancellationToken, ) -> Result<AudioBuffer>

Returns exactly the requested contiguous half-open presentation range.

Source

pub fn get( &mut self, timeline: Timeline, frame: FrameIndex, cancellation: &CancellationToken, ) -> Result<AudioBuffer>

Source

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.

Source

pub fn reset(&mut self) -> Result<()>

Cancels are caller-owned; reset drops queued decode state before a seek.

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for AudioSampleReader<D>

§

impl<D> !Sync for AudioSampleReader<D>

§

impl<D> !UnwindSafe for AudioSampleReader<D>

§

impl<D> Forget for AudioSampleReader<D>

§

impl<D> Freeze for AudioSampleReader<D>

§

impl<D> Move for AudioSampleReader<D>

§

impl<D> Send for AudioSampleReader<D>
where D: Send, BoxRaw<dyn AudioPacketProvider>: Send, NodeRef<Owned, u64, AudioBuffer, LeafOrInternal>: Send, BoxRaw<(u64, AudioBuffer)>: Send, RawVecInner: Send,

§

impl<D> Unpin for AudioSampleReader<D>
where D: Unpin, Box<dyn AudioPacketProvider>: Unpin, *const LeafNode<u64, AudioBuffer> is !null: Unpin, Box<(u64, AudioBuffer)>: Unpin, *const u8 is !null: Unpin,

§

impl<D> UnsafeUnpin for AudioSampleReader<D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.