AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::ReadAheadWorker

Struct ReadAheadWorker 

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>

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>

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>

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>

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>

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.

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Same for T

§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.