Struct Mp3Recording Worker
pub struct Mp3RecordingWorker<W: Write + Seek + Send + 'static> { /* private fields */ }Expand description
Prepared-ring automatic MP3 owner. The encoder is constructed, pumped,
explicitly finalized and dropped on one named worker. Capture keeps its
unique prepared producer; callback push adds no heap, lock, I/O or implicit
backpressure. Pause acknowledges quiescence after the active batch and I/O.
Control operations, join and Drop may block indefinitely on caller sink I/O.
Drop requests abort and joins; it never drains, rewrites metadata or flushes.
Sink destructors retain their own contract. Worker panic loses unwound owners.
An outer Ok proves recovery only; inspect Mp3RecordingExit::completion
before treating the destination as complete. Writer format, source, metadata,
physical-write budgets and independent LGPL requirements remain applicable.
No physical device, perceptual, resampling or callback deadline claim.
use ravet_audio_file::{audio_ring, Mp3Format, Mp3Bitrate,
Mp3RecordingWorker, Mp3RecordingCompletion};
let (mut producer, consumer) = audio_ring(1, 4).unwrap();
let mut worker = Mp3RecordingWorker::new(std::io::Cursor::new(Vec::new()),
Mp3Format { channels: 1, sample_rate: 48000,
bit_rate: Mp3Bitrate::Kbps256 }, consumer, 2, 4, 65536)?;
worker.start()?;
producer.push(&[0.25, -0.25]).unwrap();
drop(producer); // after capture stop; proves no future publication
let exit = worker.finish_after_producer_retired()?;
match exit.completion() {
Mp3RecordingCompletion::Finalized => assert!(!exit.destination.into_inner().is_empty()),
Mp3RecordingCompletion::Failed(error) => panic!("recording failed: {error:?}"),
Mp3RecordingCompletion::Aborted => panic!("recording was aborted"),
}Implementations§
§impl<W: Write + Seek + Send + 'static> Mp3RecordingWorker<W>
impl<W: Write + Seek + Send + 'static> Mp3RecordingWorker<W>
pub fn new(
sink: W,
format: Mp3Format,
consumer: AudioConsumer,
batch_frames: usize,
maximum_frames: u64,
maximum_bytes: u64,
) -> Result<Self, Error>
pub fn new( sink: W, format: Mp3Format, consumer: AudioConsumer, batch_frames: usize, maximum_frames: u64, maximum_bytes: u64, ) -> Result<Self, Error>
Validate configuration/queue and prepare 1..4096-frame source scratch, without codec/thread/header creation.
pub fn start(&mut self) -> Result<(), Error>
pub fn start(&mut self) -> Result<(), Error>
Acknowledge OS spawn only; startup faults are carried by status/eventual completion. Spawn failure keeps preparation for retry/abort.
pub fn status(&self) -> Mp3RecordingStatus
pub fn accepted_frames(&self) -> u64
pub fn accepted_frames(&self) -> u64
Encoder-submitted frames, including a failing accepted batch.
pub fn dequeued_frames(&self) -> u64
pub fn dequeued_frames(&self) -> u64
Ring-dequeued frames, including a rejected source batch.
pub fn written_bytes(&self) -> u64
pub fn written_bytes(&self) -> u64
Actual sink-accepted bytes, including partial failed writes.
pub fn file_bytes(&self) -> u64
pub fn file_bytes(&self) -> u64
Current file region bytes, excluding repeated metadata writes.
pub fn pause(&mut self) -> Result<(), Error>
pub fn pause(&mut self) -> Result<(), Error>
Wait for active I/O and acknowledgement; no later dequeue until resume/finalize. No I/O cancellation/deadline.
pub fn resume(&mut self) -> Result<(), Error>
pub fn resume(&mut self) -> Result<(), Error>
Resume same local codec and wait for running acknowledgement.
pub fn finish_stopped(
&mut self,
producer: &mut AudioProducer,
) -> Result<Mp3RecordingExit<W>, Error>
pub fn finish_stopped( &mut self, producer: &mut AudioProducer, ) -> Result<Mp3RecordingExit<W>, Error>
Validate matching stopped producer before bounded tail drain/metadata rewrite/flush. Foreign proof preserves state; inspect completion, outer Ok proves recovery only.
pub fn finish_after_producer_retired(
&mut self,
) -> Result<Mp3RecordingExit<W>, Error>
pub fn finish_after_producer_retired( &mut self, ) -> Result<Mp3RecordingExit<W>, Error>
Permanent producer Drop proves no later publication, including hidden capture adapters. Live/leaked proof preserves state.
pub fn abort(self) -> Result<Mp3RecordingExit<W>, Error>
pub fn abort(self) -> Result<Mp3RecordingExit<W>, Error>
Reclaim incomplete sink/source/original fault without tail drain/metadata rewrite/flush. Prepared abort touches no sink; panic loses unwound owners.