pub struct Stream<T: StreamType> { /* private fields */ }Expand description
Generic audio stream with sync Read + Seek.
T is a marker type defining the stream source (Hls, File, etc.).
Stream holds the source directly and implements Read + Seek by calling
Source::wait_range() and Source::read_at().
Implementations§
Source§impl<T: StreamType> Stream<T>
impl<T: StreamType> Stream<T>
Sourcepub async fn new(config: T::Config) -> Result<Self, SourceError>
pub async fn new(config: T::Config) -> Result<Self, SourceError>
Create a new stream from configuration.
§Errors
Returns an error if the underlying stream source cannot be created.
pub fn is_empty(&self) -> Option<bool>
Sourcepub fn seek_time_anchor(
&mut self,
position: Duration,
) -> Result<Option<SourceSeekAnchor>, Error>
pub fn seek_time_anchor( &mut self, position: Duration, ) -> Result<Option<SourceSeekAnchor>, Error>
Resolve a deterministic time-based seek anchor.
Returns None for sources without segmented time mapping.
§Errors
Returns an error when the source failed to resolve the anchor.
Sourcepub fn phase(&self) -> SourcePhase
pub fn phase(&self) -> SourcePhase
Overall source readiness at current position.
Sourcepub fn phase_at(&self, range: Range<u64>) -> SourcePhase
pub fn phase_at(&self, range: Range<u64>) -> SourcePhase
Point-in-time readiness for a specific byte range.
Sourcepub fn media_info(&self) -> Option<MediaInfo>
pub fn media_info(&self) -> Option<MediaInfo>
Get current media info if known.
Sourcepub fn abr_handle(&self) -> Option<AbrHandle>
pub fn abr_handle(&self) -> Option<AbrHandle>
Runtime ABR handle — Some for adaptive sources (HLS).
Sourcepub fn current_variant(&self) -> Option<VariantInfo>
pub fn current_variant(&self) -> Option<VariantInfo>
Current variant metadata — Some for adaptive sources (HLS).
Sourcepub fn current_segment_range(&self) -> Option<Range<u64>>
pub fn current_segment_range(&self) -> Option<Range<u64>>
Get current segment byte range (for segmented sources like HLS). Transitional — removed in Plan 06.
Sourcepub fn format_change_segment_range(&self) -> StreamResult<Range<u64>>
pub fn format_change_segment_range(&self) -> StreamResult<Range<u64>>
Header byte range for decoder recreate after a format change. Transitional — removed in Plan 06.
§Errors
Err(SourceError::FormatChangeNotApplicable) for non-HLS
sources or HLS variants activated with served_from > 0
(init prefix unreachable via Stream reads).
Sourcepub fn clear_variant_fence(&mut self)
pub fn clear_variant_fence(&mut self)
Clear variant fence, allowing reads from the next variant.
Sourcepub fn has_variant_change_pending(&self) -> bool
pub fn has_variant_change_pending(&self) -> bool
true while a cross-variant fence keeps read_at / wait_range
short-circuited to Pending(VariantChange) / Interrupted.
Sourcepub fn set_seek_epoch(&mut self, seek_epoch: u64)
pub fn set_seek_epoch(&mut self, seek_epoch: u64)
Set seek epoch for stale request invalidation.
Sourcepub fn notify_waiting(&self)
pub fn notify_waiting(&self)
Wake any blocked wait_range() calls.
Sourcepub fn make_notify_fn(&self) -> Option<Box<dyn Fn() + Send + Sync>>
pub fn make_notify_fn(&self) -> Option<Box<dyn Fn() + Send + Sync>>
Create a lock-free callback for waking blocked wait_range().
Sourcepub fn commit_seek_landing(&mut self, anchor: Option<SourceSeekAnchor>)
pub fn commit_seek_landing(&mut self, anchor: Option<SourceSeekAnchor>)
Commit the actual post-seek landing after decoder.seek(...).
Sourcepub fn take_reader_hooks(&mut self) -> Option<SharedHooks>
pub fn take_reader_hooks(&mut self) -> Option<SharedHooks>
Build a fresh reader-side hooks instance from the inner source.
Sourcepub fn as_segment_layout(&self) -> Option<Arc<dyn SegmentLayout>>
pub fn as_segment_layout(&self) -> Option<Arc<dyn SegmentLayout>>
Optional segment-layout handle for segment-aware decoders.
Sourcepub fn set_position(&self, pos: u64)
pub fn set_position(&self, pos: u64)
Absolute byte-position set — used by Stream::seek callers
and audio FSM landings. Forwards to the source’s atomic cursor.
Source§impl<T: StreamType> Stream<T>
impl<T: StreamType> Stream<T>
Sourcepub fn try_read(
&mut self,
buf: &mut [u8],
) -> Result<StreamReadOutcome, StreamReadError>
pub fn try_read( &mut self, buf: &mut [u8], ) -> Result<StreamReadOutcome, StreamReadError>
Typed read — returns a StreamReadOutcome discriminating
progress (Bytes with NonZeroUsize) from non-progress
(Pending with a typed PendingReason) and natural EOF.
Only genuine source I/O failures surface as
StreamReadError::Source. impl Read for Stream wraps this
outcome for std::io::Read consumers.
Trait Implementations§
Source§impl<T: StreamType> Read for Stream<T>
impl<T: StreamType> Read for Stream<T>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§impl<T: StreamType> Seek for Stream<T>
impl<T: StreamType> Seek for Stream<T>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)