Skip to content

libobs: Keep PulseAudio monitoring on the chosen device - #275

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/10342-monitor-device
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/10342-monitor-device

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The audio monitoring device chosen in Settings → Audio → Advanced now stays chosen on Linux (PulseAudio and PipeWire's pipewire-pulse) when the system's default output changes.

pulseaudio-output.c connected the monitoring playback stream to the chosen sink by name but without PA_STREAM_DONT_MOVE, so the sound server moved it along with every other stream whenever the default output changed, and monitored audio played on the new default device until the setting was touched. The capture side already asks the server not to move non-default devices.

  1. test: Audio monitoring must stay on the chosen PulseAudio device (RED):
    • test_pulse_monitor_device, end to end: libobs monitoring against a private PipeWire + WirePlumber + pipewire-pulse server (its own runtime dir and D-Bus, hardware monitors disabled) started by test_pulse_monitor_device.sh, with two null sinks the test loads itself; pactl reports which sink OBS's stream plays on. Cases: the chosen device stays when the default changes (fails today: "monitoring plays on 'obs_test_sink_b', expected 'obs_test_sink_a'"); "default" follows the default output; an unplugged device falls back to the default and returns when plugged back in. Skipped (exit 77) where PipeWire, WirePlumber, pipewire-pulse or dbus-run-session are missing.
    • test_pulse_monitor_flags: the stream-flag and reset decisions, moved into pulseaudio-stream-flags.c without context or stream calls (3 of 5 fail).
  2. libobs: Keep PulseAudio monitoring on the chosen device: connect with PA_STREAM_DONT_MOVE unless the device is "default" (which is resolved to the current default sink's name and must keep following it). All cases pass.

PA_STREAM_DONT_MOVE alone would trade this bug for silence on unplug: an unmovable stream does not follow its sink away either (pipewire-pulse leaves it unlinked, PulseAudio kills it). So OBS now does what the server did: it subscribes to sink events, reopens the stream on the default sink when the chosen one is removed, and reopens it on the chosen sink when that sink appears again. A chosen sink that is missing when monitoring starts also plays on the default sink until it appears, instead of not monitoring at all.

Threading: sink events arrive on the pulse mainloop thread, which must not block, so they only queue a task; the resets run on their own os_task_queue, taking monitoring_mutex and then each monitor's playback_mutex, the same order obs_set_audio_monitoring_device() already uses. The queue is created with the first monitor and destroyed after the last one is removed, outside monitoring_mutex.

Motivation and Context

Fixes #274 (upstream obsproject/obs-studio#10342, reported by gentoo-root)

Why this one: anyone monitoring through headphones while their desktop switches the default output (plugging in a headset, a dock, Bluetooth) hears monitored audio leave the device they picked, which is easy to miss mid-stream. It reproduces on PipeWire 1.6, today's default on most distributions.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), rebased on current master:

  • test_pulse_monitor_device: 1 of 3 fails at the RED commit, 3 of 3 pass at GREEN, against PipeWire 1.6.8 / WirePlumber 0.5.17.
  • test_pulse_monitor_flags: 3 of 5 fail at RED, 5 of 5 pass at GREEN.
  • Full ctest at GREEN: 90 of 90 in each lane, under a private Xvfb with no desktop environment variables.
  • clang-format, gersemi and ci/test_registration.py are clean.
  • Without a display (like the Tier 2 Linux lane), obs_startup() fails and the new test's cases skip, as the other core tests do.

Not tested:

  • A real PulseAudio daemon (only pipewire-pulse), and real hardware hotplug; the unplug case uses a null sink being unloaded and loaded again.
  • FreeBSD, which builds the same file.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

rdoupe and others added 2 commits October 11, 2026 18:09
The audio monitoring device chosen in Settings -> Audio -> Advanced does
not stick on PulseAudio: switching the system's default output moves
OBS's monitoring stream along with every other stream, so monitored
audio plays on the new default sink although the settings still name
another device (obsproject/obs-studio#10342, reported by gentoo-root).

pulseaudio-output.c connects the monitoring playback stream to the
chosen sink by name but never sets PA_STREAM_DONT_MOVE, so the server
may move it when the default changes. The capture side already asks it
not to for non-default devices (linux-pulseaudio: "Use DONT_MOVE for
non-default devices").

Reproduced headlessly with libobs against a private PipeWire 1.6.8 with
pipewire-pulse, WirePlumber 0.5.17 and two null sinks: with sink A the
default and a source monitored to sink B, setting the default to B and
back to A leaves OBS's monitoring stream on sink A.

PA_STREAM_DONT_MOVE alone would trade this for silence on unplug: when
the chosen sink goes away, pipewire-pulse leaves an unmovable stream
unlinked (PulseAudio kills it), and it stays silent after the sink
returns until the settings are touched. Today the server moves the
stream to the default sink and back once the sink returns, so OBS must
now do both itself on sink events.

Move these decisions into pulseaudio-stream-flags.c, without context or
stream calls, and test that a chosen sink gets PA_STREAM_DONT_MOVE while
"default" stays movable (it is resolved to the current default sink's
name before connecting and must keep following it), that removing the
chosen sink reopens the stream on the default sink, that a new sink
reopens a fallback stream, and that other sink events change nothing.
The stubs keep today's behaviour, so three tests fail.

test_pulse_monitor_device runs the same scenario end to end: libobs
monitoring against a private PipeWire + WirePlumber + pipewire-pulse
server (own runtime dir and D-Bus, no hardware) started by
test_pulse_monitor_device.sh, with two null sinks. Today the stream
moves to the new default sink, so the first of its three cases fails;
"default" following the default and unplug/replug pass and guard the
fix. It is skipped where PipeWire, WirePlumber or pipewire-pulse are
missing.

Refs obs-rust#274.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The monitoring playback stream is connected to the sink chosen in the
settings, but without PA_STREAM_DONT_MOVE the server moves it to the
new default sink whenever the default output changes, so monitored
audio leaves the chosen device (obsproject/obs-studio#10342, reported
by gentoo-root).

Ask the server not to move it unless the monitoring device is
"default", like linux-pulseaudio's capture streams already do.

An unmovable stream no longer follows its sink away either, so keep
what unplugging did before: subscribe to sink events, and when the
chosen sink is removed reopen the stream on the default sink, movable;
when a sink appears while on that fallback, reopen it on the chosen
sink if it is back. A chosen sink missing when monitoring starts now
also plays on the default sink until it appears, instead of not
monitoring at all. The resets run on their own task queue because sink
events arrive on the pulse mainloop thread, which must not block.

Fixes obs-rust#274.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 22:12
@zackees
zackees merged commit 7128d1a into obs-rust:master Oct 11, 2026
22 of 23 checks passed
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 11, 2026
obs_startup() needs a display on Linux, and the Tier 2 Linux lane has
none. test_audio_clock_drift (obs-rust#271) and test_group_child_drift (obs-rust#280)
failed their group setup there instead of skipping, which turned that
lane red on master. test_pulse_monitor_device (obs-rust#275) has the same setup
and would fail the same way on a machine with PipeWire but no display.

Like the other core tests, they now skip their cases when libobs cannot
start (and the group test also when core video cannot be reset). Under
xvfb-run every case still runs.

Refs obs-rust#270, obs-rust#274 and obs-rust#279.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
zackees pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 11, 2026
obs_startup() needs a display on Linux, and the Tier 2 Linux lane has
none. test_audio_clock_drift (obs-rust#271) and test_group_child_drift (obs-rust#280)
failed their group setup there instead of skipping, which turned that
lane red on master. test_pulse_monitor_device (obs-rust#275) has the same setup
and would fail the same way on a machine with PipeWire but no display.

Like the other core tests, they now skip their cases when libobs cannot
start (and the group test also when core video cannot be reset). Under
xvfb-run every case still runs.

Refs obs-rust#270, obs-rust#274 and obs-rust#279.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=b23e288a822896090994f89892a7a96b56da5f80 secs=109 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791758098,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9087272be2f5e155c698727d45922688d933308d2c4f08bc86b0f6e131472181","lane":"lint","parents":["35bbf88c776c3a4cb7073dae0b7869a9b75af833"],"secs":15,"stamp":"25c454c9d662469fb5114491251212e2","tree":"b23e288a822896090994f89892a7a96b56da5f80","v":1,"via":"run"}
Ci-Attestation: {"at":1791758098,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9087272be2f5e155c698727d45922688d933308d2c4f08bc86b0f6e131472181","lane":"lint","parents":["35bbf88c776c3a4cb7073dae0b7869a9b75af833"],"secs":15,"stamp":"103e935b7c7d4896cf51a6593a16411a","tree":"b23e288a822896090994f89892a7a96b56da5f80","v":1,"via":"run"}
Ci-Attestation: {"at":1791758098,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"2163bf0ab811b6bf62c711d254cc4f2bbd240ef3efeeb7f5425a8b720e0132d7","lane":"rust-test","parents":["35bbf88c776c3a4cb7073dae0b7869a9b75af833"],"secs":45,"stamp":"7a7452f3822e6646eb2e2c481ee772ca","tree":"b23e288a822896090994f89892a7a96b56da5f80","v":1,"via":"run"}
Ci-Attestation: {"at":1791758098,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"93153b10b0a7fc6c2e9fe5745e8f1b417bf629afda1d66c21fe151867ea291a7","lane":"tier2-linux","parents":["35bbf88c776c3a4cb7073dae0b7869a9b75af833"],"secs":49,"stamp":"9d46f419860c544d1aeb889a3d125f74","tree":"b23e288a822896090994f89892a7a96b56da5f80","v":1,"via":"run"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: audio monitoring leaves the chosen device when the default output changes (upstream #10342)

2 participants