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
impl RecordingReader
Sourcepub fn from_samples(samples: &[f32]) -> Self
pub fn from_samples(samples: &[f32]) -> Self
A finished recording of samples, held in memory.
Sourcepub fn from_samples_in(
spool_dir: &Path,
samples: &[f32],
) -> Result<Self, CaptureError>
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.
Sourcepub fn from_pcm16_in(
spool_dir: &Path,
samples: &[i16],
) -> Result<Self, CaptureError>
pub fn from_pcm16_in( spool_dir: &Path, samples: &[i16], ) -> Result<Self, CaptureError>
RecordingReader::from_samples_in for samples already in 16-bit PCM.
Sourcepub fn fill_through(&mut self, position: u64) -> Result<bool, CaptureError>
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.
Sourcepub fn fill(&mut self) -> Result<(), CaptureError>
pub fn fill(&mut self) -> Result<(), CaptureError>
Waits for capture to end.
Sourcepub fn fork(&self) -> Self
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.
Sourcepub fn span(&self, span: Range<u64>) -> &[f32]
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.
Sourcepub fn release_before(&mut self, position: u64)
pub fn release_before(&mut self, position: u64)
Frees this reader’s audio before position; other readers keep their
own copies.
Sourcepub fn reached_end(&self) -> bool
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.
Sourcepub fn finished_audio(&mut self) -> Result<&RecordedAudio, CaptureError>
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.
Sourcepub fn wait_for_end(&self, timeout: Duration) -> bool
pub fn wait_for_end(&self, timeout: Duration) -> bool
Waits up to timeout for capture to end, reading nothing. Returns
whether it ended.
Sourcepub fn ended_at(&self) -> Option<Instant>
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§impl RecordingReader
impl RecordingReader
Sourcepub fn from_wav_file(path: impl AsRef<Path>) -> Result<Self, CaptureError>
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.
impl Drop for RecordingReader
Retires this reader’s queue, so capture stops copying audio nobody will read into it.