Skip to content

bug: linux-pulseaudio: an audio input never restarts once its own stream dies while the server stays up (upstream #10072) #377

Closed

Description

@rdoupe

Upstream OBS bug, reported by foresto in obsproject/obs-studio#10072 (Debian Bookworm, PipeWire with pipewire-pulse, OBS 29.0.2). They record an audio device through an Audio Input Capture and switch to another virtual console with Ctrl+Alt+F3. That takes the device away from the desktop session. When they switch back the device returns, but OBS never records from it again. Choosing another device and then the original one again, or restarting OBS, brings the audio back. The same thing happens when a USB microphone is unplugged and plugged back in, or when the sound server kills OBS's record stream. The issue has no replies or labels. The code has not changed in this fork.

Location

  • plugins/linux-pulseaudio/pulse-input.c lines 346-362: the record stream gets only a read callback (line 347). It has no state callback, and a chosen device is connected with PA_STREAM_DONT_MOVE (lines 357-359). Nothing tells the source when its stream fails or when its device goes away and comes back.
  • plugins/linux-pulseaudio/pulse-wrapper.c lines 92-98, with pulse_reconnected in pulse-input.c line 452: the restart added by plugins: Reconnect Linux capture after PipeWire restarts #109 runs only when the whole server connection is lost and comes back. The context does not subscribe to device events.
  • pulse-input.c lines 316-323: if the device is missing when the stream starts (for example a microphone that is plugged in after OBS starts), the start fails once and is never retried.

Class

Lost audio. The source goes silent with no error in the UI and stays silent until its settings are changed or OBS restarts.

How it is reached

Add an Audio Input Capture (or an Audio Output Capture) for a specific device, not "Default".

  • The device goes away and comes back under the same name: switching virtual consoles (the reporter's case), unplugging and replugging a USB device, or a driver or profile reload. With pipewire-pulse the stream is left unlinked and gets no more data, but it reports no error. With PulseAudio it is killed.
  • The server kills the record stream (for example a PipeWire tool destroys its node). The stream fails with "Entity killed" and nothing restarts it.
  • The device is not there when the source is created. The source never starts once it appears.

Reproduced headlessly against a private PipeWire 1.6.8 with pipewire-pulse and WirePlumber 0.5.17 (own runtime directory and D-Bus, no hardware), with virtual sources:

  • After the source's device is unloaded and loaded again under the same name, the stream stays READY with source index 4294967295 and 0 bytes for as long as it was watched (16 s).
  • After its node is destroyed, the stream is FAILED and gets 0 bytes.

Upstream work

None. No upstream PR. obsproject/obs-studio#8699 (desktop audio lost after a display mode change, KenSharp) may be the same mechanism if the audio device goes away with the display. That was not checked; one other user could not reproduce it.

Proposed fix and failing test

Fix (in plugins/linux-pulseaudio, no libobs change):

  • A stream state callback restarts the stream once when it fails while the server connection is still up. When the whole connection is lost, the plugins: Reconnect Linux capture after PipeWire restarts #109 path handles it as before.
  • The wrapper subscribes to source events on every ready connection and passes new and removed devices to the inputs.
  • When the device a stream records from is removed, the source stops that stream and waits. When a device appears, any input without a running stream tries to start once, so the source resumes when its device returns. This also starts a source whose device was missing when it was created.
  • Each event causes at most one start attempt, so a device that is gone for good is not polled. A stream on the default device is left to the server, which moves it.
  • The decision is a pure function in pulse-reconnect.c with unit tests that need no sound server.

RED test (cmocka, test_pulse_stream_restart, Linux, no display): runs the plugin's capture code against a private PipeWire, WirePlumber and pipewire-pulse (the test_pulse_monitor_device.sh harness) and counts the frames each source hands to OBS. Four cases:

  • the device is unloaded and loaded again under the same name. A second microphone on the same server must keep its stream and audio;
  • the server destroys the stream's node;
  • the device is loaded only after the source was created;
  • the device is deleted for good (control). There must be no retry loop, no audio and no crash, also while other devices come and go.

3 of 4 fail today. The test exits 77 (skip) without PipeWire, WirePlumber or pipewire-pulse.

Activity

  1. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_pulse_stream_restart (3 of 4 failing) on a private PipeWire server: the real pulse input must capture again after its device is removed and re-added, after its stream is killed, and when its device appears after the source was created; a device deleted for good must not be polled. Plus unit cases for the decision in pulse-reconnect.c.
    2. GREEN: a stream state callback and a source subscription that restart the input when its stream fails or its device comes back.
      PR today.
  2. added a commit that references this issue on Oct 12, 2026
    761d041
  3. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    @foresto you reported this in obsproject/obs-studio#10072, so a heads-up: it's fixed here in obs-rust by #378, merged today with a regression test.

    Cause: OBS's PulseAudio input only restarted its capture when the whole connection to the sound server came back. When just its own stream died while the server stayed up, as when switching virtual consoles takes the device away and gives it back, nothing noticed: on PipeWire the stream stayed "ready" but unlinked from any device and delivered no audio, until you reselected the device or restarted OBS. Now the input watches its stream's state and the server's device events, and restarts when its stream fails or its chosen device comes back. A device that's gone for good isn't polled, and an input whose device was missing when OBS started now starts when the device appears. The test runs the real input against a private PipeWire server, removes its device and adds it back, and kills its stream: before, no audio came back; now it resumes within a moment.

    Not covered: your exact virtual console switch and a real USB replug were emulated by removing and re-adding the device; plain PulseAudio (not PipeWire) wasn't tested. A device that comes back under a different name still needs reselecting.

    Workaround on stock OBS: reselect the device in the source's properties after it comes back.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you try it, a short reply here on whether your input keeps recording after switching consoles would really help.

  4. foresto commented on Oct 12, 2026

    @foresto

    Thanks for the ping, and especially for pinging the upstream issue. I've been hoping that a solution might make its way into PipeWire, so this issue wouldn't have to be worked around in every sound application, but having a strategy for clients is valuable nevertheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions