Skip to content

linux-pulseaudio: Follow the default device - #2271

Merged
rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-default-follow
Oct 25, 2026
Merged

rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-default-follow

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2260

What and why

An Audio Output Capture set to "Default" (pulse_output_capture, device default) 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):

  • The default output changes (headset plugged in, HDMI or dock selected, another output picked). The applications' playback moves to the new output, while OBS keeps recording the old monitor. Desktop Audio goes silent.
  • The default output is unplugged (Bluetooth headset off, USB DAC or dock removed). The stream was allowed to move. PulseAudio moves record streams by the default source, so it rescued the stream to the microphone, and from then on it followed every default-source change. Desktop Audio records the mic.

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):

  • The shared context also subscribes to PA_SUBSCRIPTION_MASK_SERVER. A server CHANGE reaches the sources as the new PULSE_SERVER_CHANGED event.
  • On that event, a source set to "default" asks the server for its default device again. That is the default sink's monitor for output capture and the default source for input capture. If the default is not the device the source records from, the stream is restarted there on the UI thread, through the existing restart path. The startup skip is not applied, as after a failed stream.
  • Every stream, "default" included, connects with 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 saved default with the device it had resolved to, so saving unchanged properties restarted the stream every time. It now compares default with default.

On pipewire-pulse, "default" already followed the default output, and it still does: the same test runs there and passes.

RED → GREEN

  • RED commit: 22af494 (088f07b before the rebase onto b7b28af), test: Default Desktop Audio follows the output. It adds test_pulse_default_follow, which uses the real libobs and the real linux-pulseaudio module. The test runs against a private PulseAudio daemon started by the new test_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 no pulseaudio binary is installed. Second ctest entry, test_pulse_default_follow_pipewire: the same binary through test_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.
    • On master (760f8e6) with PulseAudio 17.0, C and hybrid: 4 of 6 cases fail.
      • default_output_switch: still on obs_test_a.monitor, records silence.
      • default_output_unplugged: records obs_test_mic, the microphone.
      • new_default_output: still on obs_test_a.monitor, records silence.
      • reapplying_default_keeps_stream: the stream restarts (source output 5 → 6).
    • Also on master: named_output_stays and the control default_input_follows pass.
    • pipewire-pulse 1.6.9 on master: only reapplying_default_keeps_stream fails.
  • GREEN commit: 22a0b64 (eeef64659 before the rebase), linux-pulseaudio: Follow the default device. test_pulse_reconnect gets a case for the PULSE_SERVER_CHANGED decision.
    • On eeef64659, and again on 22a0b64 after the rebase, C (OBS_LIBOBS_BACKEND=C) and hybrid (HYBRID, OBS_BUILD_C_REFERENCE=ON): ctest -R pulse passed 17/17 on each, with 0 skipped. That covers test_pulse_default_follow (PulseAudio 17.0) 6/6 and test_pulse_default_follow_pipewire 6/6. It also covers test_pulse_stream_restart, test_pulse_two_sources, test_pulse_monitor_*, test_pulse_reconnect, test_pulse_timing and test_pulse_default_id.
    • Gates on eeef64659: ci/local_gate.py --test-diff origin/master passed (Rust workspace 3854 passed, 6 skipped), and --lane lint passed. --lane cross passed. After the rebase, --lane lint passed again on 22a0b64.
  • Real app: the plugin log under PulseAudio now shows the device changes, for example: Default output device changed from 'obs_test_a.monitor' to 'obs_test_b.monitor', then Started recording from 'obs_test_b.monitor' (default). After the default output was unplugged: Stream from 'obs_test_a.monitor' failed, restarting it, then Started recording from 'obs_test_b.monitor' (default).

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable)

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
rdoupe force-pushed the fix/pulse-default-follow branch from 088f07b to 22a0b64 Compare October 25, 2026 00:32
@rdoupe
rdoupe marked this pull request as ready for review October 25, 2026 00:32
@rdoupe
rdoupe requested a review from zackees as a code owner October 25, 2026 00:32
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress to In review in obs-rust Multiview Oct 25, 2026
@rdoupe
rdoupe added this pull request to the merge queue Oct 25, 2026
Merged via the queue into obs-rust:master with commit 183f004 Oct 25, 2026
35 checks passed
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant