Struct symphonia_core::io::MediaSourceStream

source ·
pub struct MediaSourceStream { /* private fields */ }
Expand description

MediaSourceStream is the main reader type for Symphonia.

By using type erasure and dynamic dispatch, MediaSourceStream wraps and hides the inner reader from the consumer, allowing any typical Reader to be used with Symphonia in a generic way, selectable at runtime.

MediaSourceStream is designed to provide speed and flexibility in a number of challenging I/O scenarios.

First, to minimize system call and dynamic dispatch overhead on the inner reader, and to amortize that overhead over many bytes, MediaSourceStream implements an exponentially growing read-ahead buffer. The read-ahead length starts at 1kB, and doubles in length as more sequential reads are performed until it reaches 32kB. Growing the read-ahead length over time reduces the excess data buffered on consecutive seek() calls.

Second, to better support non-seekable sources, MediaSourceStream implements a configurable length buffer cache. By default, the buffer caches allows backtracking by up-to the minimum of either buffer_len - 32kB or the total number of bytes read since instantiation or the last buffer cache invalidation. Note that regular a seek() will invalidate the buffer cache.

Implementations§

source§

impl MediaSourceStream

source

pub fn new( source: Box<dyn MediaSource>, options: MediaSourceStreamOptions, ) -> Self

Trait Implementations§

source§

impl MediaSource for MediaSourceStream

source§

fn is_seekable(&self) -> bool

Returns if the source is seekable. This may be an expensive operation.
source§

fn byte_len(&self) -> Option<u64>

Returns the length in bytes, if available. This may be an expensive operation.
source§

impl Read for MediaSourceStream

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl ReadBytes for MediaSourceStream

source§

fn read_byte(&mut self) -> Result<u8>

Reads a single byte from the stream and returns it or an error.
source§

fn read_double_bytes(&mut self) -> Result<[u8; 2]>

Reads two bytes from the stream and returns them in read-order or an error.
source§

fn read_triple_bytes(&mut self) -> Result<[u8; 3]>

Reads three bytes from the stream and returns them in read-order or an error.
source§

fn read_quad_bytes(&mut self) -> Result<[u8; 4]>

Reads four bytes from the stream and returns them in read-order or an error.
source§

fn read_buf(&mut self, buf: &mut [u8]) -> Result<usize>

Reads up-to the number of bytes required to fill buf or returns an error.
source§

fn read_buf_exact(&mut self, buf: &mut [u8]) -> Result<()>

Reads exactly the number of bytes required to fill be provided buffer or returns an error.
source§

fn scan_bytes_aligned<'a>( &mut self, _: &[u8], _: usize, _: &'a mut [u8], ) -> Result<&'a mut [u8]>

Reads bytes from a stream into a supplied buffer until a byte patter is matched on an aligned byte boundary. Returns a mutable slice to the valid region of the provided buffer.
source§

fn ignore_bytes(&mut self, count: u64) -> Result<()>

Ignores the specified number of bytes from the stream or returns an error.
source§

fn pos(&self) -> u64

Gets the position of the stream.
source§

fn read_u8(&mut self) -> Result<u8>

Reads a single unsigned byte from the stream and returns it or an error.
source§

fn read_i8(&mut self) -> Result<i8>

Reads a single signed byte from the stream and returns it or an error.
source§

fn read_u16(&mut self) -> Result<u16>

Reads two bytes from the stream and interprets them as an unsigned 16-bit little-endian integer or returns an error.
source§

fn read_i16(&mut self) -> Result<i16>

Reads two bytes from the stream and interprets them as an signed 16-bit little-endian integer or returns an error.
source§

fn read_be_u16(&mut self) -> Result<u16>

Reads two bytes from the stream and interprets them as an unsigned 16-bit big-endian integer or returns an error.
source§

fn read_be_i16(&mut self) -> Result<i16>

Reads two bytes from the stream and interprets them as an signed 16-bit big-endian integer or returns an error.
source§

fn read_u24(&mut self) -> Result<u32>

Reads three bytes from the stream and interprets them as an unsigned 24-bit little-endian integer or returns an error.
source§

fn read_i24(&mut self) -> Result<i32>

Reads three bytes from the stream and interprets them as an signed 24-bit little-endian integer or returns an error.
source§

fn read_be_u24(&mut self) -> Result<u32>

Reads three bytes from the stream and interprets them as an unsigned 24-bit big-endian integer or returns an error.
source§

fn read_be_i24(&mut self) -> Result<i32>

Reads three bytes from the stream and interprets them as an signed 24-bit big-endian integer or returns an error.
source§

fn read_u32(&mut self) -> Result<u32>

Reads four bytes from the stream and interprets them as an unsigned 32-bit little-endian integer or returns an error.
source§

fn read_i32(&mut self) -> Result<i32>

Reads four bytes from the stream and interprets them as an signed 32-bit little-endian integer or returns an error.
source§

fn read_be_u32(&mut self) -> Result<u32>

Reads four bytes from the stream and interprets them as an unsigned 32-bit big-endian integer or returns an error.
source§

fn read_be_i32(&mut self) -> Result<i32>

Reads four bytes from the stream and interprets them as a signed 32-bit big-endian integer or returns an error.
source§

fn read_u64(&mut self) -> Result<u64>

Reads eight bytes from the stream and interprets them as an unsigned 64-bit little-endian integer or returns an error.
source§

fn read_i64(&mut self) -> Result<i64>

Reads eight bytes from the stream and interprets them as an signed 64-bit little-endian integer or returns an error.
source§

fn read_be_u64(&mut self) -> Result<u64>

Reads eight bytes from the stream and interprets them as an unsigned 64-bit big-endian integer or returns an error.
source§

fn read_be_i64(&mut self) -> Result<i64>

Reads eight bytes from the stream and interprets them as an signed 64-bit big-endian integer or returns an error.
source§

fn read_f32(&mut self) -> Result<f32>

Reads four bytes from the stream and interprets them as a 32-bit little-endian IEEE-754 floating-point value.
source§

fn read_be_f32(&mut self) -> Result<f32>

Reads four bytes from the stream and interprets them as a 32-bit big-endian IEEE-754 floating-point value.
source§

fn read_f64(&mut self) -> Result<f64>

Reads four bytes from the stream and interprets them as a 64-bit little-endian IEEE-754 floating-point value.
source§

fn read_be_f64(&mut self) -> Result<f64>

Reads four bytes from the stream and interprets them as a 64-bit big-endian IEEE-754 floating-point value.
source§

fn read_boxed_slice(&mut self, len: usize) -> Result<Box<[u8]>>

Reads up-to the number of bytes requested, and returns a boxed slice of the data or an error.
source§

fn read_boxed_slice_exact(&mut self, len: usize) -> Result<Box<[u8]>>

Reads exactly the number of bytes requested, and returns a boxed slice of the data or an error.
source§

fn scan_bytes<'a>( &mut self, pattern: &[u8], buf: &'a mut [u8], ) -> Result<&'a mut [u8]>

Reads bytes from the stream into a supplied buffer until a byte pattern is matched. Returns a mutable slice to the valid region of the provided buffer.
source§

impl Seek for MediaSourceStream

source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Seek to an offset, in bytes, in a stream. Read more
1.55.0 · source§

fn rewind(&mut self) -> Result<(), Error>

Rewind to the beginning of a stream. Read more
source§

fn stream_len(&mut self) -> Result<u64, Error>

🔬This is a nightly-only experimental API. (seek_stream_len)
Returns the length of this stream (in bytes). Read more
1.51.0 · source§

fn stream_position(&mut self) -> Result<u64, Error>

Returns the current seek position from the start of the stream. Read more
1.80.0 · source§

fn seek_relative(&mut self, offset: i64) -> Result<(), Error>

Seeks relative to the current position. Read more
source§

impl SeekBuffered for MediaSourceStream

source§

fn ensure_seekback_buffer(&mut self, len: usize)

Ensures that len bytes will be available for backwards seeking if len bytes have been previously read.
source§

fn unread_buffer_len(&self) -> usize

Get the number of bytes buffered but not yet read. Read more
source§

fn read_buffer_len(&self) -> usize

Gets the number of bytes buffered and read. Read more
source§

fn seek_buffered(&mut self, pos: u64) -> u64

Seek within the buffered data to an absolute position in the stream. Returns the position seeked to.
source§

fn seek_buffered_rel(&mut self, delta: isize) -> u64

Seek within the buffered data relative to the current position in the stream. Returns the position seeked to. Read more
source§

fn seek_buffered_rev(&mut self, delta: usize)

Seek backwards within the buffered data. Read more

Auto Trait Implementations§

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.