Text chat 51: fluxer-audio PipeWire device lists and PipeWire I/O (#341) #346
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "textchat-51-audio-pipewire-devices"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was built (audio devices spec §3.1, #220)
fluxer-audio::pipewire_devices(new):PwNodeProps,DefaultNodes { sink, source }+from_metadata(key, value)(andapply) reading{"name":"…"}from thedefaultmetadata with a small JSON reader (no new dependency),devices_from_nodes(&[PwNodeProps], &DefaultNodes) -> Devices(outputsAudio/Sink/Audio/Duplex; inputsAudio/Source,Audio/Source/Virtual,Audio/Duplex; nonode.hidden, nofluxer-native-stream-audio-*, no labels containing the original'sINTERNAL_VIRTUAL_AUDIO_DEVICE_LABELSor "Fluxer Native Stream Audio"; idpipewire:<node.name>; name description ∥ nick ∥ name with the USB id suffix stripped; de-duplicated),filter_alsa. Linux only: a registry snapshot that binds the audio nodes (for their full props:node.hiddenis not in the global props) and thedefaultmetadata, ends on the lastdone, and is bounded by a 2 s loop timer on the calling thread (no thread spawned).CpalHost: backend chosen once —FLUXER_AUDIO_HOST=alsa→ ALSA (initialiser not called); elseinit()(false → ALSA), thencpal::host_from_id(HostId::PipeWire)(fails → ALSA). PipeWire: lists from the snapshot (the 3 s watcher takes one snapshot for both directions);Some(id)→device_by_idon the kept cpal host, remade once if not found, thenDeviceNotAvailable(ids of another host are refused without a remake);None→ cpal's default device. ALSA: as before, list throughfilter_alsa. Windows/macOS unchanged.with_pipewire_init(fn() -> bool),new()=with_pipewire_init(pipewire::init)on Linux,backend() -> &'static str,HOST_ENV.Cargo.toml: cpalfeatures = ["pipewire"](comment names this task and spec §8);fluxer-audiogetspipewireon Linux.Cargo.lockgains only edges, no new crates. README updated.How it was tested
alsa_env_forces_the_alsa_backend,failed_pipewire_initialiser_means_alsa;listing_devices_never_panicskept.FLUXER_AUDIO_DEVICE_TESTS=1, run on this machine (CachyOS, PipeWire + WirePlumber, Wayland desktop):pipewire_lists_the_default_sink_and_source,opens_a_listed_pipewire_device_by_id(opened the default sink and source by theirpipewire:ids, 48 kHz, audio flowed), and the existingopens_the_default_devices_when_asked— all pass. The lists matchpw-dump(6 inputs, 6 outputs, correct defaults, no ALSA PCMs).FLUXER_SCREENSHOT_TESTS=1 cargo xtask cigreen locally (one earlier run hit the known exit-time abort of thefluxerlib test binary after all its tests passed, #338/#304; reran green).Deviations / for the reviewer
apps/fluxerstill callsCpalHost::new()(Task 52 switches it towith_pipewire_init(fluxer_capture::initialize_pipewire)). In that libwebrtc-linked binary,new()now callspw_initon Linux, which perfluxer-capturepipewire_audio/mod.rslands in libwebrtc's null stubs. Merge this together with, or right before, Task 52; until then a real (non--audio-null) Linux run of the app may crash at voice backend start. No test in CI exercises that path.DefaultNodes::apply(&mut self, key, value)added next tofrom_metadatato fold several metadata entries; a malformed value clears that default.Audio/Source/Virtualinputs are listed per the spec, but cpal 0.18.2's PipeWire host does not enumerate that class, so they cannot be opened (the engine falls back to the default mic): follow-up #344.Closes #341
🤖 Generated with Claude Code
Independent review: Text chat 51 (audio-pipewire-devices)
Reviewed
git diff 9fcc13d..origin/textchat-51-audio-pipewire-devices(0c58507) cold, against plan Task 51 and audio spec §3.1, §5 and §8.(1) Planned tests. All 14 unit tests are there and assert the spec's rules: the classes (Sink→out; Source and Source/Virtual→in; Duplex→both), streams/MIDI/video/no-class left out, a sink never offered as an input,
node.hidden=trueand own nodes left out (fluxer-native-stream-audio-prefix, the original's 4 internal labels plus "Fluxer Native Stream Audio", contained and case-insensitive), idspipewire:<node.name>that cpal parses back toHostId::PipeWire, name order description → nick → name, the USB id suffix/\s*\([0-9a-f]{4}:[0-9a-f]{4}\)\s*$/istripped,{"name":"…"}defaults, malformed metadata giving no default, de-duplication by id, and the ALSA fallback (default/pipewire/pulseplus onesysdefault:CARD=…per card; baresysdefault,hw:,dmix:,jack,nulldropped).listing_devices_never_panicsis kept. The two real tests (pipewire_lists_the_default_sink_and_source,opens_a_listed_pipewire_device_by_id) are gated onFLUXER_AUDIO_DEVICE_TESTS=1. I ran the listing test on this machine's PipeWire and it passed.(2) Interfaces. These are present as written:
PwNodeProps,DefaultNodes { sink, source }withfrom_metadata(key, value)(plus an extraapply),devices_from_nodes(&[PwNodeProps], &DefaultNodes) -> Devices,filter_alsa(&[DeviceInfo]) -> Vec<DeviceInfo>,CpalHost::with_pipewire_init(fn() -> bool),CpalHost::new()(=pipewire::initon Linux),CpalHost::backend() -> &'static str, andFLUXER_AUDIO_HOST=alsa.AudioHost,DeviceInfo,AudioEngineandEngineEventare unchanged. The snapshot uses a loop timer and runs on the calling thread, so no thread is spawned. TheRccycle betweenStateand the listeners is broken by clearingbound_nodes/bound_metadatabefore return.find_pipewirerebuilds the host once, then returnsDeviceNotAvailable.Noneopens cpal's default device.(3) Constraints. Only
fluxer-audioand the workspace manifest change. Cargo.lock adds no crate (cpal now depends on the existingpipewire0.10.1). The hand-written JSON reader cannot panic on daemon data: it slices only at char boundaries, every loop consumes input, and bad input returnsNone. There are no secrets or paths, and the README is updated.(4) Review Focus. There is no item for this task.
(5) CI.
FLUXER_SCREENSHOT_TESTS=1 cargo xtask ciin the review worktree: green (all steps passed).Findings
apps/fluxer/src/voice_rt.rs:95still callsCpalHost::new(). On Linux, in a binary that links libwebrtc, that now runspipewire::initbeforewebrtc::InitializePipeWire(), which jumps into libwebrtc's null stubs. This matches the plan's interface, and Task 52 is what fixes it. But this PR must not land ontextchatwithout Task 52 in the same merge (or immediately before it). Otherwise starting real voice crashes the Linux app. CI does not catch this.devices(Input)anddevices(Output)each take their own registry snapshot, so each makes a round trip of up to 2 s. One snapshot could serve both lists, asBackend::snapshotalready does for the watcher. This costs time but gives correct results.Audio/Source/Virtualnodes are listed as the spec asks, but cpal 0.18.2 cannot open them, so they fall back to the default mic. Follow-up #344 is open for this.Claude Opus 5.5, whileCLAUDE.mdsaysClaude Fable 5.2.Verdict: approved, with no blocking findings. Merge together with Task 52 (#342), not alone.