Repository navigation
linux-pulseaudio: Follow the default device - #2271
Merged
Merged
Conversation
An Audio Output Capture set to "Default" must record the monitor of the current default output. On PulseAudio it keeps recording the old one after the default output changes, which is silent once the applications' playback has moved on. When the default output is unplugged, the server moves the stream to the default source, so Desktop Audio records the microphone. Upstream reports: obsproject/obs-studio#4828, obs-rust#3211, obs-rust#2316. test_pulse_default_follow loads the real linux-pulseaudio module into libobs and runs it against a private sound server with null sinks, a pacat playback stream as the desktop (+0.25) and a pipe source as the microphone (-0.5), so each sample tells where it came from. pactl reports which source the capture's stream records from. Cases: switch the default output, unplug it and plug it back, plug in a new output and make it the default. A capture of a named output stays on it, a "Default" Audio Input Capture follows the default source (control), and saving unchanged "Default" settings keeps the stream. It runs twice: against a private PulseAudio daemon started by the new test_pulse_pulseaudio.sh (own runtime dir, HOME and D-Bus, only the native protocol module), which skips when no pulseaudio binary is installed, and against pipewire-pulse through test_pulse_monitor_device.sh. On master, PulseAudio: the switch and new-output cases record silence from the old monitor, the unplug case records the microphone, and saving the settings restarts the stream. pipewire-pulse: only the last fails. Refs obs-rust#2260
An Audio Output Capture set to "Default" resolved the default sink once, when its stream started, and recorded that sink's monitor from then on. Its stream was allowed to move, and the shared context only listened for source events. On PulseAudio, a change of the default output left it on the old monitor, which goes silent once the applications' playback has moved. When the default output was unplugged, the server rescued the stream to the default source, the microphone, and moved it with every default source change after that. pipewire-pulse moved it to the new monitor, so it was not affected. Subscribe to server events as well. On a server change, a source set to "default" asks the server for its default device again (the default sink's monitor for output capture, the default source for input capture). If that is not the device it records from, it restarts the stream there through the existing UI-thread path, without the startup skip, as after a failed stream. Every stream, "default" included, is now connected with PA_STREAM_DONT_MOVE, so the server can no longer move Desktop Audio onto a microphone. A "default" stream whose device goes away fails and restarts on the new default. pulse_update() compared the saved "default" with the device it resolved to, so saving unchanged properties restarted the stream every time. Compare "default" with "default". test_pulse_reconnect covers the new PULSE_SERVER_CHANGED decision. Fixes obs-rust#2260
rdoupe
force-pushed
the
fix/pulse-default-follow
branch
from
October 25, 2026 00:32
088f07b to
22a0b64
Compare
rdoupe
marked this pull request as ready for review
October 25, 2026 00:32
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.
Fixes #2260
What and why
An Audio Output Capture set to "Default" (
pulse_output_capture, devicedefault) resolved the default sink once, when its stream started, and recorded that sink's monitor from then on. On a PulseAudio server (not pipewire-pulse):Upstream reports that match: obsproject/obs-studio#4828, obsproject/obs-studio#3211 and obsproject/obs-studio#2316. Upstream's plugin still resolves the default once and subscribes to nothing.
Fix (plugins/linux-pulseaudio):
PA_SUBSCRIPTION_MASK_SERVER. A serverCHANGEreaches the sources as the newPULSE_SERVER_CHANGEDevent.PA_STREAM_DONT_MOVE, so the server can no longer move Desktop Audio onto a microphone. When the device of a "default" stream goes away, the stream fails and restarts on the new default.pulse_update()compared the saveddefaultwith the device it had resolved to, so saving unchanged properties restarted the stream every time. It now comparesdefaultwithdefault.On pipewire-pulse, "default" already followed the default output, and it still does: the same test runs there and passes.
RED → GREEN
test: Default Desktop Audio follows the output. It addstest_pulse_default_follow, which uses the real libobs and the reallinux-pulseaudiomodule. The test runs against a private PulseAudio daemon started by the newtest_pulse_pulseaudio.sh, which uses its own runtime dir, HOME and D-Bus, loads only the native protocol module, has no audio output, and skips with exit 77 when nopulseaudiobinary is installed. Second ctest entry,test_pulse_default_follow_pipewire: the same binary throughtest_pulse_monitor_device.sh. The test uses null sinks, a pacat "desktop" at +0.25 and a pipe-source microphone at -0.5, and pactl reports the source that the capture records from.default_output_switch: still onobs_test_a.monitor, records silence.default_output_unplugged: recordsobs_test_mic, the microphone.new_default_output: still onobs_test_a.monitor, records silence.reapplying_default_keeps_stream: the stream restarts (source output 5 → 6).named_output_staysand the controldefault_input_followspass.reapplying_default_keeps_streamfails.linux-pulseaudio: Follow the default device.test_pulse_reconnectgets a case for thePULSE_SERVER_CHANGEDdecision.OBS_LIBOBS_BACKEND=C) and hybrid (HYBRID,OBS_BUILD_C_REFERENCE=ON):ctest -R pulsepassed 17/17 on each, with 0 skipped. That coverstest_pulse_default_follow(PulseAudio 17.0) 6/6 andtest_pulse_default_follow_pipewire6/6. It also coverstest_pulse_stream_restart,test_pulse_two_sources,test_pulse_monitor_*,test_pulse_reconnect,test_pulse_timingandtest_pulse_default_id.ci/local_gate.py --test-diff origin/masterpassed (Rust workspace 3854 passed, 6 skipped), and--lane lintpassed.--lane crosspassed. After the rebase,--lane lintpassed again on 22a0b64.Default output device changed from 'obs_test_a.monitor' to 'obs_test_b.monitor', thenStarted recording from 'obs_test_b.monitor' (default). After the default output was unplugged:Stream from 'obs_test_a.monitor' failed, restarting it, thenStarted recording from 'obs_test_b.monitor' (default).Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable)