Struct Read Ahead Worker
pub struct ReadAheadWorker<P: ReadAheadPump> { /* private fields */ }Expand description
Control-owned automatic worker. Explicit start starts a named thread; a full ring
parks the worker with a 2 ms timeout before retrying, without callback-side wake
calls. Pump working allocations/I/O remain source-specific. Control stop/seek/
shutdown/Drop can block while joining and must never run in audio callbacks.
Stop is cooperative between bounded pump calls; it does not cancel active file
I/O and cannot guarantee a join deadline. Worker panic reports Failed, loses
the unwound source and causes control reclamation to return Poisoned.
The transfer mutex is used only during startup/exit/control operations; pumping
and callback rendering never take it. Thread creation failure retains the pump.
Callback positions require the source’s sample rate; no clock is created.
Implementations§
§impl<P: ReadAheadPump> ReadAheadWorker<P>
impl<P: ReadAheadPump> ReadAheadWorker<P>
pub fn new(
pump: P,
consumer: AudioConsumer,
maximum_frames: usize,
) -> Result<(Self, BufferedPlayback), AudioFileError>
pub fn new( pump: P, consumer: AudioConsumer, maximum_frames: usize, ) -> Result<(Self, BufferedPlayback), AudioFileError>
Prepare matching endpoints, no pending/queued frames, source rate 1..768000
and 1..65536 render frames. An already-positioned empty pump is accepted.
Playback is paused and the worker stopped until start. No device,
filesystem path or callback thread is selected implicitly.
pub fn start(&mut self) -> Result<(), AudioFileError>
pub fn start(&mut self) -> Result<(), AudioFileError>
Start the automatic worker after preparation. An active worker rejects; a completed worker is joined before restarting. OS thread creation failure returns an I/O error, retains the owned pump and reports Failed; callers may retry or reclaim it through shutdown. No source seek/reset is implicit.
pub fn seek_stopped(
&mut self,
playback: &mut BufferedPlayback,
frame: u64,
) -> Result<(), AudioFileError>
pub fn seek_stopped( &mut self, playback: &mut BufferedPlayback, frame: u64, ) -> Result<(), AudioFileError>
Reclaim the callback endpoint after stopping/joining its user. Foreign endpoints reject before stopping this worker. Join before source seek; seek failure preserves queue/pending/source/audio state and resumes the old generation. Success clears old audio, updates source position and preserves play/pause. OS restart failure retains the pump but sets Failed; generation changes already completed are not rolled back.
pub fn stop_stopped(
&mut self,
playback: &mut BufferedPlayback,
) -> Result<(), AudioFileError>
pub fn stop_stopped( &mut self, playback: &mut BufferedPlayback, ) -> Result<(), AudioFileError>
Reclaim the stopped callback endpoint, seek to frame zero and pause.
The restarted worker may prefetch the new generation while playback is
paused. The source-seek/restart failure limits match seek_stopped.
pub fn shutdown(self) -> Result<ReadAheadExit<P>, AudioFileError>
pub fn shutdown(self) -> Result<ReadAheadExit<P>, AudioFileError>
Stop/join and reclaim the source together with its original pump error. Earlier delivered audio remains consumed. A worker panic returns Poisoned; its unwound source cannot be reclaimed. Destruction never finalizes a recording or performs a hidden seek.