Screen share: system audio survives ended streams on PipeWire, and a failed start is shown (#751) #757

Closed
charles wants to merge 0 commits from fix-751-stream-audio-pipewire into textchat
Owner

Closes #751

Cause

"Entire system audio" on Linux links every playback stream into a hidden private null sink and records that sink. The PipeWire session destroyed each link it let go of twice: once with Core::destroy_object(link), and again when the moved proxy was dropped, because pw_proxy_destroy sends its own core.destroy. When an application's stream ended during the share (a notification, a paused video, a browser tab), the daemon had already removed that stream's links. The extra destroy then named a link that no longer existed, and the daemon answered with an error on the core: id=0 res=-2 "unknown resource N op:7". N is the client-side link proxy id, op 7 is core.destroy, and -2 is ENOENT. The session's core error handler treated every error on the core as a broken connection, so it quit its loop and tore down the sink. From then on the share sent silence and logged nothing else. The iec958-stereo default sink was not involved: its monitor ports are the usual monitor_FL/monitor_FR, and the design does not use them.

Reproduced on this machine (PipeWire 1.6.11 with pipewire-pulse) with the same rule the app starts (AudioRule::default(), the client's pid tree excluded), using a tone played into a private null sink. After the first stream ended, the old backend logged the exact lines from the report (unknown resource 16/17 op:7, three times) and delivered 0 frames. Diagnostic prints of the link proxy ids confirmed that 16 and 17 were the links from the ended pw-play node.

Fix

  • Releasing links: links are let go of by dropping their proxies only, so there is one destroy, and none when the daemon has already removed the link. A link whose port or node went (the daemon is removing it) is kept in dying until the proxy's removed event, so no destroy races its removal.

  • Fatal errors: only EPIPE on the core, or an error on the sink's own proxy, ends the session. Other daemon errors are logged at warn and the session goes on. start also fails if the sink is not in the graph after the round trip.

  • Logging: each step logs at info:

    • the capture target and rule
    • the sink and its input ports
    • each linked stream (node and port ids only)
    • the capture stream streaming
    • the first frame and the first non-silent frame
    • voice: screen share audio published and the first non-silent frame sent on that track

    A warn with the reason is logged when capture cannot start, when the sink is removed, or when the connection breaks.

  • Telling the sharer: this follows the original (ScreenShareStartFlow.ts failRequestedAudioCapture, ScreenSharePickerModal.tsx). When the stream audio a share asked for cannot start, the capture worker reports the new CaptureEvent::AudioFailed(reason). The store then ends the share and shows the original's notice, "Screen share audio couldn't start" / "Turn off audio sharing for this source or try again in a moment.", until it is closed. The notice is RefusalModal::STREAM_AUDIO through voice_refusal, the same alert as the voice refusals, closed by DismissVoiceError.

Verification

  • fluxer-capture tests/pipewire_real.rs system_capture_survives_a_stream_that_ends (opt-in, FLUXER_CAPTURE_TESTS=1, real PipeWire): it plays a tone, lets that stream end, then plays another tone. It failed before the fix ("the session stopped after the first stream ended: only 0 frames in 1.5 s") and passes after. It also checks that no own node is left in the graph after stop. All 7 tests of the file pass, with no warn in the log.
  • pipewire_audio::tests::only_a_broken_connection_ends_the_session (unit).
  • fluxer-core stream_golive::stream_audio_failure_ends_the_share_and_says_so: covers a share that is starting, a live share (normal stop order), and a late report with no share.
  • apps/fluxer screenshare_runtime::stream_audio_that_cannot_start_ends_the_share_and_says_so: the runtime with a fake screen and an unsupported audio backend. It shows the notice, ends the share, publishes nothing, and the notice closes. It fails without the capture worker change (it times out waiting for the notice).
  • apps/fluxer tests/stream_audio_livekit.rs (opt-in: FLUXER_CAPTURE_TESTS=1 FLUXER_LIVEKIT_TESTS=1, --ignored): end to end on a real desktop.
    • Steps: the real PipeWire capture with the "Entire system audio" rule feeds push_screen_audio of a share published on a local livekit-server --dev; another application's sound plays and ends; then a 1234 Hz tone plays. A second session subscribed to screen_share_audio must hear that tone.
    • After the fix: passes. The viewer heard 2000 ms with a tone amplitude of 0.46. The log shows the published track and the first non-silent frame captured and sent.
    • With the old backend: fails with "the viewer heard no sound from the share", after exactly the reported unknown resource 16/17 op:7 warnings.
  • Gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci passes ("all steps passed"; LiveKit interop skipped because FLUXER_LIVEKIT_TESTS was not set for the gate).

The real-PipeWire and LiveKit tests skip cleanly on CI: the Linux runner has no PipeWire daemon and does not set FLUXER_CAPTURE_TESTS. The tests played their tones into a private null sink through a pw-play --target wrapper, so nothing was heard on the speakers. The sink was removed afterwards.

Not verified: the full app (AppImage) sharing to the real instance, and the new notice as rendered pixels. The notice reuses the existing voice refusal alert, so there is no new golden.

🤖 Generated with Claude Code

Closes #751 ## Cause "Entire system audio" on Linux links every playback stream into a hidden private null sink and records that sink. The PipeWire session destroyed each link it let go of **twice**: once with `Core::destroy_object(link)`, and again when the moved proxy was dropped, because `pw_proxy_destroy` sends its own `core.destroy`. When an application's stream ended during the share (a notification, a paused video, a browser tab), the daemon had already removed that stream's links. The extra `destroy` then named a link that no longer existed, and the daemon answered with an error on the core: `id=0 res=-2 "unknown resource N op:7"`. N is the client-side link proxy id, op 7 is `core.destroy`, and -2 is ENOENT. The session's core error handler treated every error on the core as a broken connection, so it quit its loop and tore down the sink. From then on the share sent silence and logged nothing else. The `iec958-stereo` default sink was not involved: its monitor ports are the usual `monitor_FL`/`monitor_FR`, and the design does not use them. Reproduced on this machine (PipeWire 1.6.11 with pipewire-pulse) with the same rule the app starts (`AudioRule::default()`, the client's pid tree excluded), using a tone played into a private null sink. After the first stream ended, the old backend logged the exact lines from the report (`unknown resource 16/17 op:7`, three times) and delivered 0 frames. Diagnostic prints of the link proxy ids confirmed that 16 and 17 were the links from the ended `pw-play` node. ## Fix - **Releasing links:** links are let go of by dropping their proxies only, so there is one `destroy`, and none when the daemon has already removed the link. A link whose port or node went (the daemon is removing it) is kept in `dying` until the proxy's `removed` event, so no `destroy` races its removal. - **Fatal errors:** only `EPIPE` on the core, or an error on the sink's own proxy, ends the session. Other daemon errors are logged at `warn` and the session goes on. `start` also fails if the sink is not in the graph after the round trip. - **Logging:** each step logs at `info`: - the capture target and rule - the sink and its input ports - each linked stream (node and port ids only) - the capture stream streaming - the first frame and the first non-silent frame - `voice: screen share audio published` and the first non-silent frame sent on that track A `warn` with the reason is logged when capture cannot start, when the sink is removed, or when the connection breaks. - **Telling the sharer:** this follows the original (`ScreenShareStartFlow.ts` `failRequestedAudioCapture`, `ScreenSharePickerModal.tsx`). When the stream audio a share asked for cannot start, the capture worker reports the new `CaptureEvent::AudioFailed(reason)`. The store then ends the share and shows the original's notice, "Screen share audio couldn't start" / "Turn off audio sharing for this source or try again in a moment.", until it is closed. The notice is `RefusalModal::STREAM_AUDIO` through `voice_refusal`, the same alert as the voice refusals, closed by `DismissVoiceError`. ## Verification - `fluxer-capture` `tests/pipewire_real.rs` `system_capture_survives_a_stream_that_ends` (opt-in, `FLUXER_CAPTURE_TESTS=1`, real PipeWire): it plays a tone, lets that stream end, then plays another tone. **It failed before the fix** ("the session stopped after the first stream ended: only 0 frames in 1.5 s") and passes after. It also checks that no own node is left in the graph after `stop`. All 7 tests of the file pass, with no `warn` in the log. - `pipewire_audio::tests::only_a_broken_connection_ends_the_session` (unit). - `fluxer-core` `stream_golive::stream_audio_failure_ends_the_share_and_says_so`: covers a share that is starting, a live share (normal stop order), and a late report with no share. - `apps/fluxer` `screenshare_runtime::stream_audio_that_cannot_start_ends_the_share_and_says_so`: the runtime with a fake screen and an unsupported audio backend. It shows the notice, ends the share, publishes nothing, and the notice closes. **It fails without the capture worker change** (it times out waiting for the notice). - `apps/fluxer` `tests/stream_audio_livekit.rs` (opt-in: `FLUXER_CAPTURE_TESTS=1 FLUXER_LIVEKIT_TESTS=1`, `--ignored`): end to end on a real desktop. - Steps: the real PipeWire capture with the "Entire system audio" rule feeds `push_screen_audio` of a share published on a local `livekit-server --dev`; another application's sound plays and ends; then a 1234 Hz tone plays. A second session subscribed to `screen_share_audio` must hear that tone. - **After the fix:** passes. The viewer heard 2000 ms with a tone amplitude of 0.46. The log shows the published track and the first non-silent frame captured and sent. - **With the old backend:** fails with "the viewer heard no sound from the share", after exactly the reported `unknown resource 16/17 op:7` warnings. - Gate: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` passes ("all steps passed"; LiveKit interop skipped because `FLUXER_LIVEKIT_TESTS` was not set for the gate). The real-PipeWire and LiveKit tests skip cleanly on CI: the Linux runner has no PipeWire daemon and does not set `FLUXER_CAPTURE_TESTS`. The tests played their tones into a private null sink through a `pw-play --target` wrapper, so nothing was heard on the speakers. The sink was removed afterwards. Not verified: the full app (AppImage) sharing to the real instance, and the new notice as rendered pixels. The notice reuses the existing voice refusal alert, so there is no new golden. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Cause: the PipeWire session destroyed every link it let go of twice,
once with `Core::destroy_object` and once more when the moved proxy was
dropped (`pw_proxy_destroy` sends its own `core.destroy`). For a link
the daemon had already removed with its stream (any application whose
sound ends during the share), the daemon answered ENOENT on the core:
"unknown resource N op:7" (N = the link proxy, op 7 = core.destroy).
The core error handler took every error on the core for a broken
connection and quit the session's loop, which tore down the private
sink: from then on the share carried silence, and nothing said so.
Reproduced on PipeWire 1.6.11 with the log lines of the report.

Fix:
- Links are let go of by dropping their proxies only. A link whose
  port or node went is kept (`dying`) until the daemon confirms its
  removal, so no `destroy` names a link that is gone.
- Only EPIPE on the core (or an error on the sink's own proxy) ends the
  session; other daemon errors are logged at warn and it goes on.
- `start` fails when the sink is not in the graph after the round trip.
- INFO logs for each step: the rule, the sink and its ports, each linked
  stream (ids only), the capture stream streaming, first frame, first
  non-silent frame, the published screen-share audio track and its
  first non-silent frame; warn with the reason when capture cannot
  start, when the sink is removed, or the connection breaks.
- As the original (`failRequestedAudioCapture`): when the stream audio
  a share asked for cannot start, the capture worker reports
  `CaptureEvent::AudioFailed`, the store ends the share and shows
  "Screen share audio couldn't start" / "Turn off audio sharing for
  this source or try again in a moment." until it is closed.

Tests:
- fluxer-capture `pipewire_real::system_capture_survives_a_stream_that_ends`
  (opt-in, FLUXER_CAPTURE_TESTS=1): fails before (0 frames after the
  first stream ended), passes after; also checks no own node is left.
- `only_a_broken_connection_ends_the_session` (unit).
- fluxer-core `stream_audio_failure_ends_the_share_and_says_so`.
- apps/fluxer `stream_audio_that_cannot_start_ends_the_share_and_says_so`
  (runtime with an unsupported audio backend; fails without the worker
  change).
- apps/fluxer `stream_audio_livekit` (opt-in, FLUXER_CAPTURE_TESTS=1 and
  FLUXER_LIVEKIT_TESTS=1): real PipeWire capture of a tone, after
  another stream ended, published on a local livekit-server and heard
  by a second session; fails on the old backend with the reported
  "unknown resource 16/17 op:7" warnings.

Refs #751

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

Merged into textchat by hand (the merge API returns 405); the commits are in the branch.

Merged into `textchat` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-16 07:32:29 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.