pub struct GstreamerAudioCapture {
child: Child,
stdout: ChildStdout,
format: AudioFormat,
next_frame: u64,
raw_buffer: Vec<u8>,
}Expand description
Streaming audio capture wrapping a gst-launch-1.0 child process.
Each Self::next_chunk call reads exactly frames frames of
audio from the child’s stdout, packages them as a normalized-f32
AudioChunk, and assigns the appropriate PTS so the chunks form
a contiguous timeline.
Fields§
§child: Child§stdout: ChildStdout§format: AudioFormat§next_frame: u64§raw_buffer: Vec<u8>Pre-allocated scratch buffer for the raw bytes of one chunk.
Sized lazily on first next_chunk; reused after.
Implementations§
Source§impl GstreamerAudioCapture
impl GstreamerAudioCapture
Sourcepub fn test_source(
format: AudioFormat,
frequency_hz: f32,
) -> Result<Self, Error>
pub fn test_source( format: AudioFormat, frequency_hz: f32, ) -> Result<Self, Error>
Build a capture from audiotestsrc at the given sine
frequency_hz. AUT-101’s “deterministic GStreamer source”
path.
Sourcepub fn from_file(path: &Path, format: AudioFormat) -> Result<Self, Error>
pub fn from_file(path: &Path, format: AudioFormat) -> Result<Self, Error>
Build a capture by decoding an audio file through GStreamer.
Companion to Self::test_source for tests that want to
exercise the histogram / waveform code against real audio.
Sourcepub fn from_microphone(
mic_id: &str,
native_id: &str,
format: AudioFormat,
) -> Result<Self, Error>
pub fn from_microphone( mic_id: &str, native_id: &str, format: AudioFormat, ) -> Result<Self, Error>
Build a capture from a specific microphone via the per-OS gst element (M-MIC.1 / AUT-278 + M-MIC.3 / AUT-284).
- macOS:
osxaudiosrc unique-id=<native_id> - Linux:
pulsesrc device=<native_id> - Windows:
wasapisrc device=<native_id>
When native_id is empty (the device didn’t expose
unique-id in gst-device-monitor output, OR the caller
wants the OS default), the pipeline falls back to
autoaudiosrc which opens the OS default mic.
format must use SampleFormat::F32 — the pipeline caps
to F32LE explicitly. Non-F32 rejects at construction (same
shape as Self::test_source).
AUT-278 originally described the pipeline as
`…audio/x-raw,format=S16LE,…`. The capture infra around this
type is F32-only (see [`Self::reject_non_f32`] and
[`AudioChunk`] normalisation); reusing it required F32LE.
`audioresample` + `audioconvert` in the pipeline handle the
downstream conversion when a future encoder wants S16.Sourcepub fn format(&self) -> AudioFormat
pub fn format(&self) -> AudioFormat
Format of the produced chunks (same as the format passed at construction).
Sourcepub fn frames_emitted(&self) -> u64
pub fn frames_emitted(&self) -> u64
Cumulative frames emitted across next_chunk calls. Used by
the sync harness (M-MEDIA.7) to assert against expected
per-source counts.
Sourcepub fn next_chunk(&mut self, frames: u64) -> Result<AudioChunk, Error>
pub fn next_chunk(&mut self, frames: u64) -> Result<AudioChunk, Error>
Read exactly frames frames of audio. Returns an
AudioChunk with the PTS pointing at the first sample.
§Errors
Error::Ioon read failures.Error::EndOfStreamif the pipeline ends beforeframesare delivered (returns the partial count for diagnosis).