Repository navigation
libobs: Keep PulseAudio monitoring on the chosen device - #275
Merged
Merged
Conversation
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
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]>
This was referenced Oct 11, 2026
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"}
This was referenced Oct 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cconnected the monitoring playback stream to the chosen sink by name but withoutPA_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.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 bytest_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 intopulseaudio-stream-flags.cwithout context or stream calls (3 of 5 fail).libobs: Keep PulseAudio monitoring on the chosen device: connect withPA_STREAM_DONT_MOVEunless 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_MOVEalone 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, takingmonitoring_mutexand then each monitor'splayback_mutex, the same orderobs_set_audio_monitoring_device()already uses. The queue is created with the first monitor and destroyed after the last one is removed, outsidemonitoring_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_LIBOBSOFF 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.ci/test_registration.pyare clean.obs_startup()fails and the new test's cases skip, as the other core tests do.Not tested:
Types of changes
Checklist:
🤖 Generated with Claude Code