Skip to main content

Module microphone

Module microphone 

Source
Expand description

Microphone device enumeration (M-MIC.0 / AUT-277) — CLI-pipe pattern.

Spawns gst-device-monitor-1.0 Audio/Source and parses its human-readable text output into a Vec<MicrophoneDevice>. Direct sister of crate::camera (M-CAM.1 / AUT-255).

```admonish note title=“Differences from camera” Two interesting deltas from the camera enumerator:

  • gst-device-monitor-1.0 Audio/Source exposes a real is-default = true|false line in the properties: block on macOS. That’s authoritative — we use it instead of falling back to “first device listed.” When no device carries is-default = true (e.g. the property is absent on some Linux backends) we degrade to the first-listed heuristic so the picker still has a reasonable preselection.
  • The first caps line carries rate= and channels= for the device’s preferred native format. Those are parsed into MicrophoneDevice::sample_rate_hz and MicrophoneDevice::channels respectively. Either field degrades to 0 (“unknown”) if the parser can’t find it — downstream code (M-MIC.1’s capture pipeline) defaults to 48 kHz / 2 channels when the value is 0.

Structs§

MicrophoneDevice
One attached microphone with a stable ID, a human-readable label, a default-device flag, and the native channel + sample-rate hint reported by GStreamer.
ParsedDevice 🔒
Per-device intermediate parse result. explicit_default carries only the is-default = true signal at first; the fallback “first-listed” rule is applied in parse_device_monitor_output after every block has been parsed.

Functions§

extract_caps_int_field 🔒
Extract an int-valued field from a gst caps string. Caps fields look like rate=(int)48000 or rate=48000; both shapes appear in the wild depending on the gst version. Continues past non-matching tokens (format=F32LE, layout=interleaved, …) and stops as soon as it finds the first match, so a trailing channel-mask=0x… for the channels query never bleeds in (strip_prefix("channels") fails on channel-mask).
find_by_id
Locate the MicrophoneDevice whose stable id matches id by re-probing the OS via list_microphones. Used by callers (the app crate’s start_mic_capture) to resolve the picker’s mic id back to its native gst device-uid on every session start (M-MIC.3 / AUT-284). Returns None when the mic was unplugged between enumeration and start.
list_microphones
Enumerate every microphone the OS exposes via gst-device-monitor-1.0.
parse_device_monitor_output
Pure-Rust parser for gst-device-monitor-1.0 Audio/Source text output. Split out from list_microphones so the parser is testable against captured fixtures without needing gst installed.
parse_one_device_block 🔒
parse_property 🔒
Match a properties:-block line shaped like key = value and return the trimmed value. gst pads with tabs and a single =.
split_into_device_blocks 🔒
Cut the gst output into one String per Device found: block. Anything before the first Device found: line (the Probing devices... banner) is discarded.
stable_id_for
Derive a stable ID for a microphone from its human-readable label using FNV-1a. Deterministic, dependency-free. Mirrors crate::camera::stable_id_for but emits a mic- prefix so the two ID spaces never collide.