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/Sourceexposes a realis-default = true|falseline in theproperties:block on macOS. That’s authoritative — we use it instead of falling back to “first device listed.” When no device carriesis-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
capsline carriesrate=andchannels=for the device’s preferred native format. Those are parsed intoMicrophoneDevice::sample_rate_hzandMicrophoneDevice::channelsrespectively. Either field degrades to0(“unknown”) if the parser can’t find it — downstream code (M-MIC.1’s capture pipeline) defaults to48 kHz/2 channelswhen the value is0.
Structs§
- Microphone
Device - 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.
- Parsed
Device 🔒 - Per-device intermediate parse result.
explicit_defaultcarries only theis-default = truesignal at first; the fallback “first-listed” rule is applied inparse_device_monitor_outputafter every block has been parsed.
Functions§
- extract_
caps_ 🔒int_ field - Extract an
int-valued field from a gst caps string. Caps fields look likerate=(int)48000orrate=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 trailingchannel-mask=0x…for thechannelsquery never bleeds in (strip_prefix("channels")fails onchannel-mask). - find_
by_ id - Locate the
MicrophoneDevicewhose stable id matchesidby re-probing the OS vialist_microphones. Used by callers (the app crate’sstart_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). ReturnsNonewhen 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/Sourcetext output. Split out fromlist_microphonesso the parser is testable against captured fixtures without needing gst installed. - parse_
one_ 🔒device_ block - parse_
property 🔒 - Match a
properties:-block line shaped likekey = valueand return the trimmed value. gst pads with tabs and a single=. - split_
into_ 🔒device_ blocks - Cut the gst output into one
StringperDevice found:block. Anything before the firstDevice found:line (theProbing 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_forbut emits amic-prefix so the two ID spaces never collide.