Screen share 14: Linux stream audio capture (PipeWire) (#161) #198

Manually merged
charles merged 4 commits from screenshare-14-audio-capture-linux into screenshare 2026-11-12 07:59:50 +00:00
Owner

What this builds

Linux stream audio for screen share (spec §9), ported from the original's fluxer_desktop/native/linux-audio-capture (AGPL, attribution headers in each file), without napi:

  • fluxer_capture::pipewire_audio::PipeWireAudioCapturer: StreamAudioCapturer. new() probes the daemon (none → CaptureError::Unsupported); with_remote(name) for tests. start spawns one PipeWire thread per session: hidden private null sink (fluxer-native-stream-audio-<pid>-<n>), registry watch, passive L/R links from every node the rule selects (mono feeds both), and once the sink is in the registry a capture stream on its monitor (F32 48 kHz stereo) → FrameChunker → 10 ms stereo i16 frames to the sink. set_rule re-routes live; stop/drop tears down links, stream and sink and joins the thread (sink dropped before stop returns).
  • routing.rs (pure): the original's should_route_node, matches_pattern, targets_default_sink, parse_default_sink_name, pick_node_ports, client enrichment, desired-link computation; RoutingRule::from_audio_rule builds the rule as ScreenShareStartFlow.ts + NativeAudio.ts normalizeLinuxRoutingRule do (System: only/default speakers or every playback stream; Applications: application.name / application.process.binary / PID tree, any output; empty Applications falls back to System like the original; ignore_input_media, ignore_virtual, ignore_devices).
  • self_identity.rs: PID tree of exclude_pid_tree from /proc, plus a parent-chain walk so descendants started after start are excluded too; binary names from /proc/<pid>/{comm,exe}; product names fluxer-native, Fluxer Native, Fluxer, Fluxer Canary and the original's prefixes.
  • list_applications() -> Vec<AudioApp { name, pid: Option<u32>, binary: Option<String> }> (one-shot registry enumeration, client hidden). AudioApp lives in audio.rs (OS-neutral) and is re-exported.
  • default_backends() on Linux returns the PipeWire capturer when a daemon answers, else Unsupported with the reason.

fluxer-audio's identity in PipeWire (verified, recorded in the README)

On PipeWire 1.6.11, an ALSA (cpal) playback stream shows as node alsa_playback.<binary>, application.name = PipeWire ALSA [<binary>], with the client's application.process.id = PID and application.process.binary = the executable name. cpal cannot set application.name to fluxer-native, so the PID tree and binary name exclude the client's own audio (the spec's stated fallback). No change to fluxer-audio.

Tests

  • Unit (Linux): rule_matches_like_the_fork (table: default sink by name/serial, other sink, non-playback classes, only-speakers off, applications by name/binary/PID tree, empty applications, ignore_virtual, pattern details), self_identity_excludes_own_tree_and_names, input_media_and_devices_ignored_by_default, default_sink_name_parses_like_the_fork, graph_links_left_and_right_into_the_sink_and_enriches_from_the_client, stat_parsing_and_tree_walk, f32_chunks_become_10ms_stereo_i16_frames.
  • CI: tests/pipewire_real.rs::no_pipewire_daemon_is_an_error.
  • Real (FLUXER_CAPTURE_TESTS=1), ran on this machine (CachyOS, KDE Wayland session, PipeWire 1.6.11 + WirePlumber, other audio playing in Firefox at the time), 3 runs, all green: system_capture_hears_a_test_tone_from_another_process (1234 Hz tone from a pw-play re-parented outside our tree, Goertzel amplitude > 0.1), own_playback_not_captured (a pw-play child of the test is silent even when the rule names it; control: the same rule hears the detached one), list_applications_shows_a_playing_stream_but_not_ourselves.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally.

Deviations / notes for the reviewer

  • Fail-first: the routing and self-identity code is a port, so it was written together with its tests; only the integration test file was compiled against a missing PipeWireAudioCapturer first.
  • The stream's process runs on the session's own (non-real-time) PipeWire thread instead of the original's RT_PROCESS data thread, so the sink may allocate a frame; nothing runs on PipeWire's RT thread.
  • Electron's binary names are not excluded (the original excludes them because it is Electron; here it would silence every Electron app).
  • tests/fake.rs::unsupported_backends_return_errors now checks the audio side on Unsupported itself, because on a desktop with PipeWire default_backends() returns the real backend.
  • deny.toml: license exception for target-lexicon (Apache-2.0 WITH LLVM-exception, build-time only via system-deps).
  • New dependency pipewire 0.10 (default features, works with Ubuntu 22.04's libpipewire 0.3.48); bindgen needs libclang, which the Linux runner already has (clang-21 depends on libclang1-21, checked in an ubuntu:22.04 container), so no CI workflow change. apps/fluxer does not link fluxer-capture yet; when Screen share 21 wires it, the AppImage needs libpipewire-0.3.so.0 (system library, present on every PipeWire desktop) — Screen share 30's concern.
  • Findings are in crates/fluxer-capture/README.md (the task's Files list), not in the spikes doc.

Update: merged origin/screenshare (Screen share 1-8, 15)

  • Conflicts resolved in fluxer-capture (Cargo.toml, README.md, src/lib.rs, tests/fake.rs), deny.toml and Cargo.lock. default_backends() now returns DesktopScreenCapturer (Linux), PipeWireAudioCapturer (Linux, daemon present) and WasapiAudioCapturer (Windows with process loopback), each falling back to Unsupported with the reason. tests/fake.rs::unsupported_backends_return_errors builds default_backends() (must not panic) and then tests both Unsupported stubs directly.
  • Bug found by the merge, fixed here (fix(capture): initialise libwebrtc's PipeWire stubs before pw_init): once libwebrtc is linked into the same binary (the desktop backend from Screen share 4, and fluxer-voice), the pipewire crate's pw_* calls bind to libwebrtc's generated pipewire_stubs.o, whose function pointers are null until libwebrtc dlopens libpipewire, so PipeWireAudioCapturer::new() segfaulted in pw_init (gdb: jump to 0x0 from pipewire::init). Every PipeWire entry point now calls webrtc::InitializePipeWire() first (extern by its mangled name _ZN6webrtc18InitializePipeWireEv; no arguments, no libwebrtc type crosses the boundary), which fills the stubs once per process; if libpipewire-0.3.so.0 cannot be loaded the capturer is Unsupported. This matters for Screen share 21: apps/fluxer links both.
  • After the merge: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally; FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1 re-ran on this machine (CachyOS, KDE Wayland, PipeWire 1.6.11), 4/4 green, now with libwebrtc in the test binary.

Update: merged origin/screenshare again (Screen share 4, 5, 9, 16)

  • Conflicts were in fluxer-capture (Cargo.toml, README.md, src/lib.rs, tests/fake.rs). desktop.rs is now src/desktop/ and runs on Linux and Windows. default_backends() still returns the PipeWire capturer on Linux when a daemon answers, and WASAPI on Windows.
  • After this merge, FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green locally. FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1 also passes 4/4 on this machine (CachyOS, KDE Wayland, PipeWire 1.6.11).
  • The deferred review findings (review 1 findings 1 to 5, re-review findings 1 and 3) are in follow-up #225.

Closes #161

🤖 Generated with Claude Code

## What this builds Linux stream audio for screen share (spec §9), ported from the original's `fluxer_desktop/native/linux-audio-capture` (AGPL, attribution headers in each file), without napi: - `fluxer_capture::pipewire_audio::PipeWireAudioCapturer: StreamAudioCapturer`. `new()` probes the daemon (none → `CaptureError::Unsupported`); `with_remote(name)` for tests. `start` spawns one PipeWire thread per session: hidden private null sink (`fluxer-native-stream-audio-<pid>-<n>`), registry watch, passive L/R links from every node the rule selects (mono feeds both), and once the sink is in the registry a capture stream on its monitor (F32 48 kHz stereo) → `FrameChunker` → 10 ms stereo `i16` frames to the sink. `set_rule` re-routes live; `stop`/drop tears down links, stream and sink and joins the thread (sink dropped before `stop` returns). - `routing.rs` (pure): the original's `should_route_node`, `matches_pattern`, `targets_default_sink`, `parse_default_sink_name`, `pick_node_ports`, client enrichment, desired-link computation; `RoutingRule::from_audio_rule` builds the rule as `ScreenShareStartFlow.ts` + `NativeAudio.ts normalizeLinuxRoutingRule` do (System: only/default speakers or every playback stream; Applications: `application.name` / `application.process.binary` / PID tree, any output; empty Applications falls back to System like the original; `ignore_input_media`, `ignore_virtual`, `ignore_devices`). - `self_identity.rs`: PID tree of `exclude_pid_tree` from `/proc`, plus a parent-chain walk so descendants started after `start` are excluded too; binary names from `/proc/<pid>/{comm,exe}`; product names `fluxer-native`, `Fluxer Native`, `Fluxer`, `Fluxer Canary` and the original's prefixes. - `list_applications() -> Vec<AudioApp { name, pid: Option<u32>, binary: Option<String> }>` (one-shot registry enumeration, client hidden). `AudioApp` lives in `audio.rs` (OS-neutral) and is re-exported. - `default_backends()` on Linux returns the PipeWire capturer when a daemon answers, else `Unsupported` with the reason. ## fluxer-audio's identity in PipeWire (verified, recorded in the README) On PipeWire 1.6.11, an ALSA (cpal) playback stream shows as node `alsa_playback.<binary>`, `application.name` = `PipeWire ALSA [<binary>]`, with the client's `application.process.id` = PID and `application.process.binary` = the executable name. cpal cannot set `application.name` to `fluxer-native`, so the PID tree and binary name exclude the client's own audio (the spec's stated fallback). No change to `fluxer-audio`. ## Tests - Unit (Linux): `rule_matches_like_the_fork` (table: default sink by name/serial, other sink, non-playback classes, only-speakers off, applications by name/binary/PID tree, empty applications, ignore_virtual, pattern details), `self_identity_excludes_own_tree_and_names`, `input_media_and_devices_ignored_by_default`, `default_sink_name_parses_like_the_fork`, `graph_links_left_and_right_into_the_sink_and_enriches_from_the_client`, `stat_parsing_and_tree_walk`, `f32_chunks_become_10ms_stereo_i16_frames`. - CI: `tests/pipewire_real.rs::no_pipewire_daemon_is_an_error`. - Real (`FLUXER_CAPTURE_TESTS=1`), **ran on this machine** (CachyOS, KDE Wayland session, PipeWire 1.6.11 + WirePlumber, other audio playing in Firefox at the time), 3 runs, all green: `system_capture_hears_a_test_tone_from_another_process` (1234 Hz tone from a `pw-play` re-parented outside our tree, Goertzel amplitude > 0.1), `own_playback_not_captured` (a `pw-play` child of the test is silent even when the rule names it; control: the same rule hears the detached one), `list_applications_shows_a_playing_stream_but_not_ourselves`. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. ## Deviations / notes for the reviewer - Fail-first: the routing and self-identity code is a port, so it was written together with its tests; only the integration test file was compiled against a missing `PipeWireAudioCapturer` first. - The stream's `process` runs on the session's own (non-real-time) PipeWire thread instead of the original's `RT_PROCESS` data thread, so the sink may allocate a frame; nothing runs on PipeWire's RT thread. - Electron's binary names are not excluded (the original excludes them because it is Electron; here it would silence every Electron app). - `tests/fake.rs::unsupported_backends_return_errors` now checks the audio side on `Unsupported` itself, because on a desktop with PipeWire `default_backends()` returns the real backend. - `deny.toml`: license exception for `target-lexicon` (`Apache-2.0 WITH LLVM-exception`, build-time only via `system-deps`). - New dependency `pipewire` 0.10 (default features, works with Ubuntu 22.04's libpipewire 0.3.48); bindgen needs libclang, which the Linux runner already has (`clang-21` depends on `libclang1-21`, checked in an ubuntu:22.04 container), so no CI workflow change. `apps/fluxer` does not link `fluxer-capture` yet; when Screen share 21 wires it, the AppImage needs `libpipewire-0.3.so.0` (system library, present on every PipeWire desktop) — Screen share 30's concern. - Findings are in `crates/fluxer-capture/README.md` (the task's Files list), not in the spikes doc. ## Update: merged origin/screenshare (Screen share 1-8, 15) - Conflicts resolved in `fluxer-capture` (`Cargo.toml`, `README.md`, `src/lib.rs`, `tests/fake.rs`), `deny.toml` and `Cargo.lock`. `default_backends()` now returns `DesktopScreenCapturer` (Linux), `PipeWireAudioCapturer` (Linux, daemon present) and `WasapiAudioCapturer` (Windows with process loopback), each falling back to `Unsupported` with the reason. `tests/fake.rs::unsupported_backends_return_errors` builds `default_backends()` (must not panic) and then tests both `Unsupported` stubs directly. - **Bug found by the merge, fixed here** (`fix(capture): initialise libwebrtc's PipeWire stubs before pw_init`): once libwebrtc is linked into the same binary (the `desktop` backend from Screen share 4, and `fluxer-voice`), the `pipewire` crate's `pw_*` calls bind to libwebrtc's generated `pipewire_stubs.o`, whose function pointers are null until libwebrtc dlopens libpipewire, so `PipeWireAudioCapturer::new()` segfaulted in `pw_init` (gdb: jump to 0x0 from `pipewire::init`). Every PipeWire entry point now calls `webrtc::InitializePipeWire()` first (extern by its mangled name `_ZN6webrtc18InitializePipeWireEv`; no arguments, no libwebrtc type crosses the boundary), which fills the stubs once per process; if `libpipewire-0.3.so.0` cannot be loaded the capturer is `Unsupported`. This matters for Screen share 21: `apps/fluxer` links both. - After the merge: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally; `FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1` re-ran on this machine (CachyOS, KDE Wayland, PipeWire 1.6.11), 4/4 green, now with libwebrtc in the test binary. ## Update: merged origin/screenshare again (Screen share 4, 5, 9, 16) - Conflicts were in `fluxer-capture` (`Cargo.toml`, `README.md`, `src/lib.rs`, `tests/fake.rs`). `desktop.rs` is now `src/desktop/` and runs on Linux and Windows. `default_backends()` still returns the PipeWire capturer on Linux when a daemon answers, and WASAPI on Windows. - After this merge, `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green locally. `FLUXER_CAPTURE_TESTS=1 cargo test -p fluxer-capture --test pipewire_real -- --test-threads 1` also passes 4/4 on this machine (CachyOS, KDE Wayland, PipeWire 1.6.11). - The deferred review findings (review 1 findings 1 to 5, re-review findings 1 and 3) are in follow-up #225. Closes #161 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(video): frames, conversions, frame bus, test pattern and preview JPEG
All checks were successful
ci / Linux (x86_64) (push) Successful in 15m16s
ci / Windows (x64) (push) Successful in 16m21s
8b8a359082
Refs #148

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(capture): capture traits and fake backends
All checks were successful
ci / Windows (x64) (push) Successful in 16m9s
ci / Linux (x86_64) (push) Successful in 35m35s
d821f19097
Refs #150

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
feat(capture): Linux stream audio
Some checks failed
ci / Linux (x86_64) (push) Failing after 4m56s
ci / Windows (x64) (push) Successful in 15m9s
136a1a6429
PipeWireAudioCapturer: a hidden private null sink, passive links from the
Stream/Output/Audio nodes the AudioRule selects, a capture stream on the
sink converted to 10 ms 48 kHz stereo i16 frames. Self-exclusion by the
excluded PID tree (including later descendants), binary and product names.
list_applications for the "Audio sources" submenu. Ported from the
original's linux-audio-capture without napi.

Refs #161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Independent review: Screen share 14 (Linux stream audio, PipeWire)

Reviewed d821f19..136a1a6 cold, against the plan's Task 14, spec §9 and the fork's linux-audio-capture.

Plan tests (1): all named tests exist and assert what the plan says: rule_matches_like_the_fork, self_identity_excludes_own_tree_and_names, input_media_and_devices_ignored_by_default (unit); no_pipewire_daemon_is_an_error (CI); system_capture_hears_a_test_tone_from_another_process, own_playback_not_captured (gated on FLUXER_CAPTURE_TESTS=1). should_route_node, targets_default_sink, matches_pattern and parse_default_sink_name match the fork line for line. The defaults come from Task 3's AudioRule::default(), which matches spec §9.
Interfaces (2): PipeWireAudioCapturer: StreamAudioCapturer, list_applications() -> Vec<AudioApp { name, pid, binary }>, hidden private null sink, passive links, F32 to i16 10 ms stereo 48 kHz frames, and exclusion by PID tree, binary and name are all present. Attribution headers are present.
Invariants (3): fluxer-capture gains only pipewire (Linux only) and tracing. It has no fluxer-core or livekit dependency, and no PipeWire type appears in a public signature. With no daemon, every failure path returns CaptureError::Unsupported or Backend and never panics. Buffer slicing is bounds-checked. There are no secrets.
Review Focus 7: own-output exclusion is by PID tree (including descendants started later, through the ppid walk), by binary name and by product names. The README records that cpal/ALSA cannot set application.name, so the spec's PID-only fallback applies. That is acceptable. Note that the real test uses a pw-play child, not fluxer-audio's cpal path. The ALSA plug-in's client carries our pipewire.sec.pid, so the PID match covers it.
CI (5): FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green in the review worktree. All task tests ran. I did not re-run the real tests, because they play an audible tone on the desktop. The implementer reports 3 passing runs.

Findings

  1. minor: list_applications is an inherent method of PipeWireAudioCapturer, but default_backends() returns a Box<dyn StreamAudioCapturer>. Task 21 therefore cannot reach it through the default backend. It must keep a concrete PipeWireAudioCapturer (cfg linux) or add a trait method. The Interfaces block does not specify which, so Task 21 should be told.
  2. minor: SessionState::recompute runs on every registry global, ports included. Each run calls SelfIdentity::matches for every node, and for unknown PIDs that walks up to 64 /proc/<pid>/stat reads. On a busy graph this is O(globals × nodes × depth) file reads on the PipeWire thread before the sync done arrives, which eats into the 2 s READY_TIMEOUT. Suggested fix: cache ancestry results per PID, or defer recompute until after the initial sync.
  3. minor: AppMatch::Pid is expanded into a PID set once, at start/set_rule. Children the target app spawns later (browser audio processes) are not routed, unlike self-exclusion, which walks ancestry. The fork resolves the tree once too, so this is not a regression.
  4. minor: if the private sink is removed (global_remove of sink_id) or the capture stream errors, the session silently stops producing frames, and the trait gives no way to report it. This is worth a follow-up issue for Task 21 (e.g. treat a long gap as "stream audio lost").
  5. minor: the process callback allocates a Vec<f32> per buffer. It runs on the session's non-RT thread (no RT_PROCESS), so this does not break the real-time rule. The deviation is documented, and the allocation is avoidable.

No blocking findings. Electron names are not excluded, which is a justified deviation. The tests/fake.rs change is justified, and the deny.toml exception for target-lexicon is build-time only and fine.

Verdict: approve. No blocking findings; local CI is green.

## Independent review: Screen share 14 (Linux stream audio, PipeWire) Reviewed `d821f19..136a1a6` cold, against the plan's Task 14, spec §9 and the fork's `linux-audio-capture`. **Plan tests (1):** all named tests exist and assert what the plan says: `rule_matches_like_the_fork`, `self_identity_excludes_own_tree_and_names`, `input_media_and_devices_ignored_by_default` (unit); `no_pipewire_daemon_is_an_error` (CI); `system_capture_hears_a_test_tone_from_another_process`, `own_playback_not_captured` (gated on `FLUXER_CAPTURE_TESTS=1`). `should_route_node`, `targets_default_sink`, `matches_pattern` and `parse_default_sink_name` match the fork line for line. The defaults come from Task 3's `AudioRule::default()`, which matches spec §9. **Interfaces (2):** `PipeWireAudioCapturer: StreamAudioCapturer`, `list_applications() -> Vec<AudioApp { name, pid, binary }>`, hidden private null sink, passive links, F32 to i16 10 ms stereo 48 kHz frames, and exclusion by PID tree, binary and name are all present. Attribution headers are present. **Invariants (3):** `fluxer-capture` gains only `pipewire` (Linux only) and `tracing`. It has no `fluxer-core` or livekit dependency, and no PipeWire type appears in a public signature. With no daemon, every failure path returns `CaptureError::Unsupported` or `Backend` and never panics. Buffer slicing is bounds-checked. There are no secrets. **Review Focus 7:** own-output exclusion is by PID tree (including descendants started later, through the ppid walk), by binary name and by product names. The README records that cpal/ALSA cannot set `application.name`, so the spec's PID-only fallback applies. That is acceptable. Note that the real test uses a `pw-play` child, not `fluxer-audio`'s cpal path. The ALSA plug-in's client carries our `pipewire.sec.pid`, so the PID match covers it. **CI (5):** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green in the review worktree. All task tests ran. I did not re-run the real tests, because they play an audible tone on the desktop. The implementer reports 3 passing runs. ### Findings 1. **minor**: `list_applications` is an inherent method of `PipeWireAudioCapturer`, but `default_backends()` returns a `Box<dyn StreamAudioCapturer>`. Task 21 therefore cannot reach it through the default backend. It must keep a concrete `PipeWireAudioCapturer` (cfg linux) or add a trait method. The Interfaces block does not specify which, so Task 21 should be told. 2. **minor**: `SessionState::recompute` runs on every registry global, ports included. Each run calls `SelfIdentity::matches` for every node, and for unknown PIDs that walks up to 64 `/proc/<pid>/stat` reads. On a busy graph this is O(globals × nodes × depth) file reads on the PipeWire thread before the sync `done` arrives, which eats into the 2 s `READY_TIMEOUT`. Suggested fix: cache ancestry results per PID, or defer recompute until after the initial sync. 3. **minor**: `AppMatch::Pid` is expanded into a PID set once, at `start`/`set_rule`. Children the target app spawns later (browser audio processes) are not routed, unlike self-exclusion, which walks ancestry. The fork resolves the tree once too, so this is not a regression. 4. **minor**: if the private sink is removed (`global_remove` of `sink_id`) or the capture stream errors, the session silently stops producing frames, and the trait gives no way to report it. This is worth a follow-up issue for Task 21 (e.g. treat a long gap as "stream audio lost"). 5. **minor**: the `process` callback allocates a `Vec<f32>` per buffer. It runs on the session's non-RT thread (no `RT_PROCESS`), so this does not break the real-time rule. The deviation is documented, and the allocation is avoidable. No blocking findings. Electron names are not excluded, which is a justified deviation. The `tests/fake.rs` change is justified, and the `deny.toml` exception for `target-lexicon` is build-time only and fine. **Verdict: approve.** No blocking findings; local CI is green.
Refs #161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With libwebrtc linked into the same binary (fluxer-capture's desktop backend
since Screen share 4, and fluxer-voice), the pipewire crate's pw_* calls bind
to libwebrtc's generated stubs, whose pointers are null until libwebrtc
dlopens libpipewire: PipeWireAudioCapturer::new() segfaulted in pw_init.
Call webrtc::InitializePipeWire() first; it fills the stubs once per process.

Refs #161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Independent re-review: Screen share 14 after the merge of screenshare (f3fd2a0..2e267f7)

I read the diff f3fd2a0..origin/screenshare-14-audio-capture-linux cold, focusing on what changed since the approving review (comment 3961): the merge resolution and the InitializePipeWire fix.

Plan tests (1): every named test exists and asserts what the plan says. Unit tests: rule_matches_like_the_fork, self_identity_excludes_own_tree_and_names, input_media_and_devices_ignored_by_default. CI test: no_pipewire_daemon_is_an_error. Real tests, which need FLUXER_CAPTURE_TESTS=1: system_capture_hears_a_test_tone_from_another_process and own_playback_not_captured. The defaults match spec §9: System, true, true, true, true, false.
Interfaces (2): PipeWireAudioCapturer: StreamAudioCapturer, list_applications() -> Vec<AudioApp { name, pid, binary }> and AudioApp (re-exported from the crate root) exist as written. default_backends() keeps its signature. Linux and Windows each get a cfg-gated default_audio_backend, and each falls back to Unsupported with the reason.
Invariants (3): fluxer-capture gains only pipewire (Linux) and tracing. It has no fluxer-core or livekit dependency, and no PipeWire or libwebrtc type appears in a public signature. The merged Linux dependency table is correct: pipewire plus libwebrtc with glib-main-loop. The deny.toml target-lexicon note is build-time only. Graph data from PipeWire cannot panic the client: parse_default_sink_name only slices at " bytes, and the buffer slicing is checked. There are no secrets.
The InitializePipeWire fix: I verified it. The prebuilt libwebrtc.a (linux-x64) defines T webrtc::InitializePipeWire() and references pw_init through its stubs. The function body is a function-local static, so it is thread-safe and runs once. Both probe, run_session and snapshot_graph call it before pw::init(). The C++ bool() signature with no arguments is ABI-compatible with the Rust declaration.
Review Focus 7: own output is excluded by PID tree (with an ancestry walk for later descendants), by binary name and by product names. The README records what cpal/ALSA reports to PipeWire. This is unchanged from the first review.
CI (5): FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci is green in the review worktree (all steps passed), and all of the task's unit tests and the CI test ran. I did not run the real tests, because they play an audible tone. The implementer reports 4/4 passing on PipeWire 1.6.11.

Findings

  1. minor: pipewire_audio/mod.rs declares the libwebrtc C++ symbol _ZN6webrtc18InitializePipeWireEv itself. No libwebrtc type crosses the boundary, so the Global Constraint (types confined to desktop.rs / rtc.rs) holds as written. It does add a second place that depends on libwebrtc's ABI, and the mangled name ties it to the pinned 0.4.0 build. Moving the extern into desktop.rs as a pub(crate) fn initialize_pipewire() -> bool would keep every libwebrtc coupling in one file. If the symbol ever disappears, the link fails loudly, so nothing breaks silently.
  2. minor (carried over from finding 1 of the first review): list_applications is inherent to the concrete type, and default_backends() returns Box<dyn StreamAudioCapturer>. Task 21 must construct PipeWireAudioCapturer itself on Linux to fill the "Audio sources" submenu. It should also call InitializePipeWire-dependent code only through this crate, which it does by construction.
  3. minor: list_applications gives up after 2 s, but the spawned fluxer-pipewire-list thread keeps waiting in mainloop.run() for a done that may never come, for example from a wedged daemon. That thread leaks. Each call would leak at most one thread, so this is not blocking.
  4. minor: findings 2 to 5 of the first review (recompute cost, the PID set fixed at start, silent sink loss, and the per-buffer allocation) are still unaddressed. They belong in a follow-up issue linked from this PR before merge, as CLAUDE.md requires.

No blocking findings.

Verdict: approve. There are no blocking findings and local CI is green.

## Independent re-review: Screen share 14 after the merge of screenshare (f3fd2a0..2e267f7) I read the diff `f3fd2a0..origin/screenshare-14-audio-capture-linux` cold, focusing on what changed since the approving review (comment 3961): the merge resolution and the `InitializePipeWire` fix. **Plan tests (1):** every named test exists and asserts what the plan says. Unit tests: `rule_matches_like_the_fork`, `self_identity_excludes_own_tree_and_names`, `input_media_and_devices_ignored_by_default`. CI test: `no_pipewire_daemon_is_an_error`. Real tests, which need `FLUXER_CAPTURE_TESTS=1`: `system_capture_hears_a_test_tone_from_another_process` and `own_playback_not_captured`. The defaults match spec §9: System, true, true, true, true, false. **Interfaces (2):** `PipeWireAudioCapturer: StreamAudioCapturer`, `list_applications() -> Vec<AudioApp { name, pid, binary }>` and `AudioApp` (re-exported from the crate root) exist as written. `default_backends()` keeps its signature. Linux and Windows each get a `cfg`-gated `default_audio_backend`, and each falls back to `Unsupported` with the reason. **Invariants (3):** `fluxer-capture` gains only `pipewire` (Linux) and `tracing`. It has no `fluxer-core` or `livekit` dependency, and no PipeWire or libwebrtc type appears in a public signature. The merged Linux dependency table is correct: `pipewire` plus `libwebrtc` with `glib-main-loop`. The `deny.toml` `target-lexicon` note is build-time only. Graph data from PipeWire cannot panic the client: `parse_default_sink_name` only slices at `"` bytes, and the buffer slicing is checked. There are no secrets. **The `InitializePipeWire` fix:** I verified it. The prebuilt `libwebrtc.a` (linux-x64) defines `T webrtc::InitializePipeWire()` and references `pw_init` through its stubs. The function body is a function-local static, so it is thread-safe and runs once. Both `probe`, `run_session` and `snapshot_graph` call it before `pw::init()`. The C++ `bool()` signature with no arguments is ABI-compatible with the Rust declaration. **Review Focus 7:** own output is excluded by PID tree (with an ancestry walk for later descendants), by binary name and by product names. The README records what cpal/ALSA reports to PipeWire. This is unchanged from the first review. **CI (5):** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` is green in the review worktree (`all steps passed`), and all of the task's unit tests and the CI test ran. I did not run the real tests, because they play an audible tone. The implementer reports 4/4 passing on PipeWire 1.6.11. ### Findings 1. **minor**: `pipewire_audio/mod.rs` declares the libwebrtc C++ symbol `_ZN6webrtc18InitializePipeWireEv` itself. No libwebrtc type crosses the boundary, so the Global Constraint (types confined to `desktop.rs` / `rtc.rs`) holds as written. It does add a second place that depends on libwebrtc's ABI, and the mangled name ties it to the pinned 0.4.0 build. Moving the `extern` into `desktop.rs` as a `pub(crate) fn initialize_pipewire() -> bool` would keep every libwebrtc coupling in one file. If the symbol ever disappears, the link fails loudly, so nothing breaks silently. 2. **minor** (carried over from finding 1 of the first review): `list_applications` is inherent to the concrete type, and `default_backends()` returns `Box<dyn StreamAudioCapturer>`. Task 21 must construct `PipeWireAudioCapturer` itself on Linux to fill the "Audio sources" submenu. It should also call `InitializePipeWire`-dependent code only through this crate, which it does by construction. 3. **minor**: `list_applications` gives up after 2 s, but the spawned `fluxer-pipewire-list` thread keeps waiting in `mainloop.run()` for a `done` that may never come, for example from a wedged daemon. That thread leaks. Each call would leak at most one thread, so this is not blocking. 4. **minor**: findings 2 to 5 of the first review (recompute cost, the PID set fixed at start, silent sink loss, and the per-buffer allocation) are still unaddressed. They belong in a `follow-up` issue linked from this PR before merge, as `CLAUDE.md` requires. No blocking findings. **Verdict: approve.** There are no blocking findings and local CI is green.
Conflicts in fluxer-capture (Cargo.toml, README.md, src/lib.rs, tests/fake.rs):
keep the PipeWire stream-audio backend next to the shared desktop backend.

Refs #161

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Independent review: Screen share 14 (Linux stream audio, PipeWire), head 2e75321

I reviewed only 61a073c..2e75321 and focused on how the merge conflicts were resolved.

Merge resolution

  • src/lib.rs: default_audio_backend is now three cfg-gated functions. Linux uses PipeWireAudioCapturer::new() or Unsupported(err). Windows uses WasapiAudioCapturer or Unsupported(reason). Every other OS gets Unsupported. The doc comment matches the code, and nothing from Screen share 4/5 (the desktop re-export, default_screen) was lost. OK.
  • Cargo.toml: the Linux target block now holds both pipewire and libwebrtc with glib-main-loop, with no duplicate table. tempfile is a dev-dependency. OK.
  • README: the module table, backend table and dependency list cover desktop, wasapi and pipewire_audio together. OK.
  • tests/fake.rs: unsupported_backends_return_errors now checks that default_backends() builds without panicking, and tests the stubs directly. That fits now that every desktop OS has a real backend. OK.
  • deny.toml: the target-lexicon exception comment now names both users. OK.

Plan checks

  1. Tests: the unit tests rule_matches_like_the_fork, self_identity_excludes_own_tree_and_names and input_media_and_devices_ignored_by_default, the CI test no_pipewire_daemon_is_an_error, and the real tests system_capture_hears_a_test_tone_from_another_process and own_playback_not_captured (the last with a control) are all present. Frames are checked at 480×2 samples, 2 channels.
  2. Interfaces: PipeWireAudioCapturer: StreamAudioCapturer, list_applications() -> Vec<AudioApp { name, pid, binary }> and AudioApp re-exported from the crate root are all present as written.
  3. Invariants: fluxer-capture does not pull in fluxer-core or livekit. No libwebrtc or LiveKit type appears in a public signature. Server data, such as chunk offset and size, PIDs and prop strings, is handled with checked arithmetic, get and parse-or-ignore, so it cannot panic the client. The diff contains no secrets.
  4. Review Focus 7 (self-exclusion) holds. The client is excluded by the PID tree, including descendants started later (found through the ppid walk), by binary names and by product names. The README records the cpal/ALSA application.name and application.process.id, as the plan asks.
  5. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci in a fresh review worktree: all steps passed.

Findings

  • minor: init_pipewire declares an extern "C" to libwebrtc's webrtc::InitializePipeWire (by mangled name) in pipewire_audio/mod.rs, outside src/desktop/. No libwebrtc type crosses the boundary, so the constraint on types is met, but the libwebrtc coupling sits outside the sanctioned module. This is already tracked in #225.
  • minor: list_applications is an inherent method, so the runtime cannot reach it through the Box<dyn StreamAudioCapturer> that default_backends() returns. Screen share 21/26 will need a way to reach it. This is tracked in #225, and it does not break any interface written in the plan.

Verdict: approve. No blocking findings, and local CI is green.

## Independent review: Screen share 14 (Linux stream audio, PipeWire), head 2e75321 I reviewed only `61a073c..2e75321` and focused on how the merge conflicts were resolved. **Merge resolution** - `src/lib.rs`: `default_audio_backend` is now three cfg-gated functions. Linux uses `PipeWireAudioCapturer::new()` or `Unsupported(err)`. Windows uses `WasapiAudioCapturer` or `Unsupported(reason)`. Every other OS gets `Unsupported`. The doc comment matches the code, and nothing from Screen share 4/5 (the `desktop` re-export, `default_screen`) was lost. OK. - `Cargo.toml`: the Linux target block now holds both `pipewire` and `libwebrtc` with `glib-main-loop`, with no duplicate table. `tempfile` is a dev-dependency. OK. - README: the module table, backend table and dependency list cover `desktop`, `wasapi` and `pipewire_audio` together. OK. - `tests/fake.rs`: `unsupported_backends_return_errors` now checks that `default_backends()` builds without panicking, and tests the stubs directly. That fits now that every desktop OS has a real backend. OK. - `deny.toml`: the `target-lexicon` exception comment now names both users. OK. **Plan checks** 1. Tests: the unit tests `rule_matches_like_the_fork`, `self_identity_excludes_own_tree_and_names` and `input_media_and_devices_ignored_by_default`, the CI test `no_pipewire_daemon_is_an_error`, and the real tests `system_capture_hears_a_test_tone_from_another_process` and `own_playback_not_captured` (the last with a control) are all present. Frames are checked at 480×2 samples, 2 channels. 2. Interfaces: `PipeWireAudioCapturer: StreamAudioCapturer`, `list_applications() -> Vec<AudioApp { name, pid, binary }>` and `AudioApp` re-exported from the crate root are all present as written. 3. Invariants: `fluxer-capture` does not pull in `fluxer-core` or `livekit`. No libwebrtc or LiveKit type appears in a public signature. Server data, such as chunk offset and size, PIDs and prop strings, is handled with checked arithmetic, `get` and parse-or-ignore, so it cannot panic the client. The diff contains no secrets. 4. Review Focus 7 (self-exclusion) holds. The client is excluded by the PID tree, including descendants started later (found through the ppid walk), by binary names and by product names. The README records the cpal/ALSA `application.name` and `application.process.id`, as the plan asks. 5. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` in a fresh review worktree: **all steps passed**. **Findings** - minor: `init_pipewire` declares an `extern "C"` to libwebrtc's `webrtc::InitializePipeWire` (by mangled name) in `pipewire_audio/mod.rs`, outside `src/desktop/`. No libwebrtc type crosses the boundary, so the constraint on types is met, but the libwebrtc coupling sits outside the sanctioned module. This is already tracked in #225. - minor: `list_applications` is an inherent method, so the runtime cannot reach it through the `Box<dyn StreamAudioCapturer>` that `default_backends()` returns. Screen share 21/26 will need a way to reach it. This is tracked in #225, and it does not break any interface written in the plan. Verdict: **approve**. No blocking findings, and local CI is green.
charles manually merged commit 5096dd1ee4 into screenshare 2026-11-12 07:59:50 +00:00
Sign in to join this conversation.
No description provided.