Skip to main content

RecordingReader

Struct RecordingReader 

Source
pub struct RecordingReader { /* private fields */ }
Expand description

A window onto a recording, readable while capture is still writing it. One reader; RecordingReader::fork adds another.

The window holds what this reader has collected and not yet released. Audio is addressed by stream position — counted from the first sample capture ever appended — so a position keeps meaning what it meant after a release moves the window forward.

Implementations§

Source§

impl RecordingReader

Source

pub fn from_samples(samples: &[f32]) -> Self

A finished recording of samples, held in memory.

Source

pub fn from_samples_in( spool_dir: &Path, samples: &[f32], ) -> Result<Self, CaptureError>

A finished recording of samples, saved as a private WAV in spool_dir.

Source

pub fn from_pcm16_in( spool_dir: &Path, samples: &[i16], ) -> Result<Self, CaptureError>

RecordingReader::from_samples_in for samples already in 16-bit PCM.

Source

pub fn fill_through(&mut self, position: u64) -> Result<bool, CaptureError>

Waits until the window reaches position, or until capture ends short of it. Returns whether it reached position.

Source

pub fn fill(&mut self) -> Result<(), CaptureError>

Waits for capture to end.

Source

pub fn fork(&self) -> Self

A second reader of the same recording, with its own window and its own release floor: what one reader frees, the other still holds.

The recording keeps no history, so a fork opens where capture stands rather than at the beginning — ask RecordingReader::held_from where that was.

Every sample written from here on is copied into its queue until it drops, so a fork nobody reads grows without bound.

Source

pub fn held_from(&self) -> u64

Stream position of the first sample this reader still holds.

Source

pub fn samples(&self) -> &[f32]

Samples this reader has collected and not yet released.

Source

pub fn held_to(&self) -> u64

Stream position just past the last sample held.

Source

pub fn span(&self, span: Range<u64>) -> &[f32]

The audio in span, clamped to the window. A span that ran off either edge yields what survives of it, which may be nothing.

Source

pub fn release_before(&mut self, position: u64)

Frees this reader’s audio before position; other readers keep their own copies.

Source

pub fn reached_end(&self) -> bool

Whether this reader has seen capture end. It learns that only when it reads past the audio it holds, so it can lag. RecordingReader::ended_at does not.

Source

pub fn finished_audio(&mut self) -> Result<&RecordedAudio, CaptureError>

The finished WAV. Waits for capture to end, and keeps none of the samples it waits through.

§Panics

On a fork: only the reader that opened the recording owns its audio.

Source

pub fn wait_for_end(&self, timeout: Duration) -> bool

Waits up to timeout for capture to end, reading nothing. Returns whether it ended.

Source

pub fn ended_at(&self) -> Option<Instant>

When capture ended. Unlike RecordingReader::reached_end, it does not wait for this reader to catch up.

Source

pub fn duration(&self) -> Duration

How much audio capture has written, whether or not it has been read.

Source§

impl RecordingReader

Source

pub fn from_wav_file(path: impl AsRef<Path>) -> Result<Self, CaptureError>

Opens a caller-owned canonical 16 kHz mono WAV as a finished recording.

The file is validated for format, not trust — trust policy is for artifacts a daemon loads on a user’s behalf, and this file is the caller’s own. The file is borrowed, never deleted.

Trait Implementations§

Source§

impl Drop for RecordingReader

Retires this reader’s queue, so capture stops copying audio nobody will read into it.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more