Struct Recording Worker
pub struct RecordingWorker<P: RecordingPump> { /* private fields */ }Expand description
Control-owned bounded automatic recording pump. new validates the matching
prepared producer and retains the recorder; start creates a named worker.
Capture callbacks keep their unique AudioProducer and only call prepared push.
Full-ring overload remains explicit accepted-prefix/caller-drop policy; no
hidden allocation, blocking backpressure, device/path/clock choice occurs.
Pump allocations, encoding and I/O belong to the worker. Stop/join/finish/Drop
belong to control after capture shutdown; cooperative stop does not cancel
active I/O or guarantee a join deadline. Dropping the owner joins but never
drains/finalizes. A panicked worker loses its unwound recorder and reports
Failed/Poisoned, never successful finalization.
Implementations§
§impl<P: RecordingPump> RecordingWorker<P>
impl<P: RecordingPump> RecordingWorker<P>
pub fn new(
recorder: P,
producer: &AudioProducer,
) -> Result<Self, AudioFileError>
pub fn new( recorder: P, producer: &AudioProducer, ) -> Result<Self, AudioFileError>
Validate queue identity before transferring the recorder. No thread or final output is created here; recorder preparation may already have written its caller-selected file header. Capture need not start yet.
pub fn from_recorder(recorder: P) -> Self
pub fn from_recorder(recorder: P) -> Self
Prepare from the recorder’s exact owned ring, without borrowing a producer. This accepts device capture adapters that keep the producer inside their callback. Finalize only after the producer is permanently retired/dropped. The RecordingPump consumer contract must identify its actual drained ring.
pub fn start(&mut self) -> Result<(), AudioFileError>
pub fn start(&mut self) -> Result<(), AudioFileError>
Begin automatic bounded draining. An active worker rejects. Empty input uses a 2 ms park timeout. OS thread creation failure retains recorder ownership and reports Failed; callers may retry or reclaim with shutdown.
pub fn status(&self) -> RecordingStatus
pub fn status(&self) -> RecordingStatus
Concurrent diagnostic snapshot; Running is not finalized-file evidence.
pub fn stop(&mut self) -> Result<(), AudioFileError>
pub fn stop(&mut self) -> Result<(), AudioFileError>
Stop/join without draining or finalizing, retaining the recorder for a later start, explicit finish or shutdown. Pump faults remain Failed.
pub fn finish_stopped(
&mut self,
producer: &mut AudioProducer,
) -> Result<P::Destination, AudioFileError>
pub fn finish_stopped( &mut self, producer: &mut AudioProducer, ) -> Result<P::Destination, AudioFileError>
Reclaim the producer only after its capture user stops/joins. A foreign producer rejects before stopping this worker. Join, then invoke the source’s bounded remaining drain and consuming finish on control. Success yields a complete sink and Finalized; further start/finish reject. A worker pump error is returned once and leaves the owned poisoned recorder available to shutdown. A finalization error consumes its sink and cannot be retried or treated as a complete file. Late publication violates the stopped-producer lifecycle and can reject finish or lose frames.
pub fn finish_after_producer_retired(
&mut self,
) -> Result<P::Destination, AudioFileError>
pub fn finish_after_producer_retired( &mut self, ) -> Result<P::Destination, AudioFileError>
Finalize after the unique producer has been dropped, including hidden device callback producers. Live or leaked producers reject before stopping this worker. Retirement is permanent; the queue’s acquire proof synchronizes its last publication, then joining permits the source’s bounded final drain. Device/callback shutdown belongs to its owner; this method performs no device operation. Error/sink-consumption rules match finish_stopped.
pub fn shutdown(self) -> Result<RecordingExit<P>, AudioFileError>
pub fn shutdown(self) -> Result<RecordingExit<P>, AudioFileError>
Stop/join and reclaim the recorder plus its original pump error. This does no final drain/header patch/flush; queued input remains source-owned. The error is absent if already returned by either finish method. A worker panic returns Poisoned because its unwound recorder cannot be reclaimed.