AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::Mp3RecordingWorker

Struct Mp3RecordingWorker 

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>

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>

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

Encoder-submitted frames, including a failing accepted batch.

pub fn dequeued_frames(&self) -> u64

Ring-dequeued frames, including a rejected source batch.

pub fn written_bytes(&self) -> u64

Actual sink-accepted bytes, including partial failed writes.

pub fn file_bytes(&self) -> u64

Current file region bytes, excluding repeated metadata writes.

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>

Resume same local codec and wait for running acknowledgement.

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>

Permanent producer Drop proves no later publication, including hidden capture adapters. Live/leaked proof preserves state.

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.

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.