Skip to main content

GstreamerAudioCapture

Struct GstreamerAudioCapture 

Source
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

Source

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.

Source

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.

Source

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.
Source

pub fn format(&self) -> AudioFormat

Format of the produced chunks (same as the format passed at construction).

Source

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.

Source

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::Io on read failures.
  • Error::EndOfStream if the pipeline ends before frames are delivered (returns the partial count for diagnosis).
Source

fn spawn(args: &[&str], format: AudioFormat) -> Result<Self, Error>

Source

fn reject_non_f32(format: AudioFormat) -> Result<(), Error>

Trait Implementations§

Source§

impl Debug for GstreamerAudioCapture

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for GstreamerAudioCapture

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.

§

impl<T> Instrument for T

§

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

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

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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