Repository navigation
linux-pulseaudio: Restart an input whose stream dies while connected - #378
Merged
Merged
Conversation
An Audio Input Capture on PulseAudio or PipeWire stays silent for good
once its own record stream dies while the connection to the server
stays up. Upstream, the reporter switched to another virtual console,
which takes the device away from the session; back on the desktop the
device returned under the same name, but OBS never recorded from it
again until the source's device was changed. Unplugging and replugging
a USB microphone, or the server killing the stream, end the same way.
pulse-input.c connects a chosen device with PA_STREAM_DONT_MOVE and
sets only a read callback: no stream state callback and no
subscription to source events. The restart added for a lost server
connection (pulse_reconnected) only runs when the whole context comes
back. On PipeWire 1.6.8 with pipewire-pulse and WirePlumber 0.5.17:
- device removed and re-added under the same name: the stream stays
READY but unlinked (source index 4294967295) and gets no data, with
no state, moved or suspended callback; PulseAudio kills it instead
- stream node destroyed: the stream goes FAILED ("Entity killed")
and nothing restarts it
- device missing when the source is created: the start fails once and
is never retried, so a microphone plugged in later stays silent
test_pulse_stream_restart builds the linux-pulseaudio capture code into
the test and runs it against a private PipeWire, WirePlumber and
pipewire-pulse (test_pulse_monitor_device.sh: own runtime dir, config
and D-Bus, no hardware) with virtual sources it loads itself. libobs's
source calls are stubbed with --wrap, so no display is needed: each
source counts the frames handed to obs_source_output_audio, and UI
tasks run on a thread of their own. On master:
replugged_source_resumes no audio within 3 s after the replug
killed_stream_restarts no audio within 3 s after the kill
late_source_starts no audio within 3 s after plugging in
deleted_source_stays_quiet passes (control)
3 of 4 cases fail. The controls (a second microphone that is not
touched keeps its stream and its audio; a device deleted for good
causes no retry loop, no audio and no crash) pass. Exits 77 (skip)
without PipeWire, WirePlumber, pipewire-pulse or pactl.
Reported upstream in obsproject/obs-studio#10072 by foresto.
Refs obs-rust#377.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An Audio Input Capture stays silent for good once its own record stream dies while the connection to the server stays up: the server kills the stream, or the device goes away and comes back under the same name (switching to another virtual console and back, replugging a USB microphone). The restart from obs-rust#109 only runs when the whole server connection comes back. Watch the stream and the server's devices: - a stream state callback queues a restart when the stream fails while the context is still ready (with the context lost, pulse_reconnected already restarts it) - the wrapper subscribes to source events on every ready context and passes new and removed sources to the inputs - a removed device stops the stream recording from it (pipewire-pulse leaves a stream that may not move unlinked and silent; PulseAudio kills it), and a new device starts any input that has no running stream, which also starts a source whose device was missing when it was created The decision lives in pulse_stream_on_event() (pulse-reconnect.c), without context or stream calls. Each event leads to at most one start attempt, so a device that is gone for good is not polled: its source only looks again when some device appears. A stream on the default device is left to the server, which moves it. test_pulse_stream_restart: 3 of 4 failing -> 4/4 against a private PipeWire 1.6.8, pipewire-pulse and WirePlumber 0.5.17 (10/10 repeated runs). test_pulse_reconnect gains three cases for the decision, which run without a sound server: 10/10. Fixes obs-rust#377. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=b92cfda608c4102ab19ee759b83e3b204db9d58d secs=146 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791816870,"gate":"rust/all/fmt","host":"linux-x86_64","key":"43d368cdc63ffbee96f8f424fb25ff18bca826236b64358a15264b317ff71cb2","lane":"lint","parents":["71acac7f7ae8f22917dcb634078dba6979daa11a"],"secs":52,"stamp":"a6df21afe9b4561baff31ae98399fb4d","tree":"b92cfda608c4102ab19ee759b83e3b204db9d58d","v":1,"via":"run"} Ci-Attestation: {"at":1791816870,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"43d368cdc63ffbee96f8f424fb25ff18bca826236b64358a15264b317ff71cb2","lane":"lint","parents":["71acac7f7ae8f22917dcb634078dba6979daa11a"],"secs":52,"stamp":"0781c02615b216aa99ce07842dd0d2f8","tree":"b92cfda608c4102ab19ee759b83e3b204db9d58d","v":1,"via":"run"} Ci-Attestation: {"at":1791816870,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"711aaf4d1c9da2312829d055fca4b93e1998e322b173ed0296b9a59a2ce7a175","lane":"rust-test","parents":["71acac7f7ae8f22917dcb634078dba6979daa11a"],"secs":40,"stamp":"e34cb2cc9233bd8acca50ed5b20d7e47","tree":"b92cfda608c4102ab19ee759b83e3b204db9d58d","v":1,"via":"run"} Ci-Attestation: {"at":1791816870,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"570801778dbea9a4b654ff807958d72ed42b6138b5a3f597049426543b6541e2","lane":"tier2-linux","parents":["71acac7f7ae8f22917dcb634078dba6979daa11a"],"secs":55,"stamp":"07ef830ec41989672618504fae491db0","tree":"b92cfda608c4102ab19ee759b83e3b204db9d58d","v":1,"via":"run"}
Member
|
Verified locally (Tier 2 image + pipewire, pipewire-pulse, wireplumber, dbus):
The Tier 2 image has no PipeWire, so plain CI skips the end-to-end test. Rebased on master, local gate passed; pushed as 761d041. |
zackees
force-pushed
the
fix/10072-pulse-stream-restart
branch
from
October 12, 2026 14:54
1c97a2c to
761d041
Compare
This was referenced Oct 12, 2026
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 16, 2026
…ed (RED)
Fails, every run, in both lanes: failed_restart_is_retried ("produced
no audio within 3000 ms") and failing_stream_is_paced_then_given_up
("restarted 52 times in 1 s, 18 ms apart at the least, expected
100 ms"; seen once under load, when the restarts came further apart:
"still restarting the failing stream after 16 s (227 attempts)").
Follow-up of obs-rust#377/obs-rust#378. When a source's own stream fails while the
server stays up, the input restarts it once. If that restart fails
synchronously (the stream cannot be created or connected) while the
device is there and the server is connected, nothing retries it: only
a device appearing would. If the restarted stream keeps failing, the
input restarts it at once every time, with no pause and no limit;
since obs-rust#532 every restart also opens a new server connection.
test_pulse_stream_restart wraps pa_stream_new_with_proplist and
pa_stream_connect_record to make restarts fail on demand, and gains
three cases:
- the stream is killed and creating it fails 3 times while the device
stays: audio must return within 3 s, with 4 creation attempts;
- every connected stream is ended right after it is ready: restarts at
least PULSE_RESTART_RETRY_USEC apart, a give-up after at most
PULSE_RESTART_MAX_ATTEMPTS, no restart after that, and audio again
once a device appears;
- a source is destroyed while its restart is pending (control; the
group teardown checks for leaked weak references).
The 4 cases from obs-rust#378 and the control pass.
Refs obs-rust#1029.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 16, 2026
A source restarts its stream when it fails while the server stays up (obs-rust#378), but: - if the restart fails synchronously (the stream cannot be created, connected or given a valid sample spec) while the device is there and the server is connected, nothing retries it until some device appears; - if the server keeps failing the restarted stream, the source restarts it at once every time, with no pause and no limit, each time on a new server connection (obs-rust#532). Route both through the restart counter the server reconnection already uses (pulse_restart_should_retry(), pulse_call_later()): - pulse_start_recording() now says why it failed: no server, no device, or anything else. A restart that fails while the device is there is retried every PULSE_RESTART_RETRY_USEC (100 ms). A missing device is still waited for (a new device event), so a device that is gone for good is not polled, and a lost server is still left to the reconnection, which retries missing devices as before. - A failed stream is restarted at once the first time and after PULSE_RESTART_RETRY_USEC after that. - Both count in the same restart_attempts. After PULSE_RESTART_MAX_ATTEMPTS (100) the source logs a warning, stops the stream and waits for a device to appear. - The counter is reset when the stream delivers audio, instead of when a start call returns, so a stream that starts and then fails right away keeps counting. The read callback runs with the mainloop locked, so the UI thread reads and writes the counter under pulse_lock(). - A pending per-stream retry does nothing if a device event restarted the stream meanwhile. The decisions are pulse_start_should_retry() and pulse_stream_failed_should_restart() in pulse-reconnect.c, which need no server; test_pulse_reconnect gains four cases for them (14 of 14). test_pulse_stream_restart: 7 of 7. Fixes obs-rust#1029. Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 16, 2026
…ed (RED)
Fails, every run, in both lanes: failed_restart_is_retried ("produced
no audio within 3000 ms") and failing_stream_is_paced_then_given_up
("restarted 52 times in 1 s, 18 ms apart at the least, expected
100 ms"; seen once under load, when the restarts came further apart:
"still restarting the failing stream after 16 s (227 attempts)").
Follow-up of obs-rust#377/obs-rust#378. When a source's own stream fails while the
server stays up, the input restarts it once. If that restart fails
synchronously (the stream cannot be created or connected) while the
device is there and the server is connected, nothing retries it: only
a device appearing would. If the restarted stream keeps failing, the
input restarts it at once every time, with no pause and no limit;
since obs-rust#532 every restart also opens a new server connection.
test_pulse_stream_restart wraps pa_stream_new_with_proplist and
pa_stream_connect_record to make restarts fail on demand, and gains
three cases:
- the stream is killed and creating it fails 3 times while the device
stays: audio must return within 3 s, with 4 creation attempts;
- every connected stream is ended right after it is ready: restarts at
least PULSE_RESTART_RETRY_USEC apart, a give-up after at most
PULSE_RESTART_MAX_ATTEMPTS, no restart after that, and audio again
once a device appears;
- a source is destroyed while its restart is pending (control; the
group teardown checks for leaked weak references).
The 4 cases from obs-rust#378 and the control pass.
Refs obs-rust#1029.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 16, 2026
A source restarts its stream when it fails while the server stays up (obs-rust#378), but: - if the restart fails synchronously (the stream cannot be created, connected or given a valid sample spec) while the device is there and the server is connected, nothing retries it until some device appears; - if the server keeps failing the restarted stream, the source restarts it at once every time, with no pause and no limit, each time on a new server connection (obs-rust#532). Route both through the restart counter the server reconnection already uses (pulse_restart_should_retry(), pulse_call_later()): - pulse_start_recording() now says why it failed: no server, no device, or anything else. A restart that fails while the device is there is retried every PULSE_RESTART_RETRY_USEC (100 ms). A missing device is still waited for (a new device event), so a device that is gone for good is not polled, and a lost server is still left to the reconnection, which retries missing devices as before. - A failed stream is restarted at once the first time and after PULSE_RESTART_RETRY_USEC after that. - Both count in the same restart_attempts. After PULSE_RESTART_MAX_ATTEMPTS (100) the source logs a warning, stops the stream and waits for a device to appear. - The counter is reset when the stream delivers audio, instead of when a start call returns, so a stream that starts and then fails right away keeps counting. The read callback runs with the mainloop locked, so the UI thread reads and writes the counter under pulse_lock(). - A pending per-stream retry does nothing if a device event restarted the stream meanwhile. The decisions are pulse_start_should_retry() and pulse_stream_failed_should_restart() in pulse-reconnect.c, which need no server; test_pulse_reconnect gains four cases for them (14 of 14). test_pulse_stream_restart: 7 of 7. Fixes obs-rust#1029. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 16, 2026
…it (obs-rust#1031) * test/cmocka: Pulse stream restarts that fail are not retried or limited (RED) Fails, every run, in both lanes: failed_restart_is_retried ("produced no audio within 3000 ms") and failing_stream_is_paced_then_given_up ("restarted 52 times in 1 s, 18 ms apart at the least, expected 100 ms"; seen once under load, when the restarts came further apart: "still restarting the failing stream after 16 s (227 attempts)"). Follow-up of obs-rust#377/obs-rust#378. When a source's own stream fails while the server stays up, the input restarts it once. If that restart fails synchronously (the stream cannot be created or connected) while the device is there and the server is connected, nothing retries it: only a device appearing would. If the restarted stream keeps failing, the input restarts it at once every time, with no pause and no limit; since obs-rust#532 every restart also opens a new server connection. test_pulse_stream_restart wraps pa_stream_new_with_proplist and pa_stream_connect_record to make restarts fail on demand, and gains three cases: - the stream is killed and creating it fails 3 times while the device stays: audio must return within 3 s, with 4 creation attempts; - every connected stream is ended right after it is ready: restarts at least PULSE_RESTART_RETRY_USEC apart, a give-up after at most PULSE_RESTART_MAX_ATTEMPTS, no restart after that, and audio again once a device appears; - a source is destroyed while its restart is pending (control; the group teardown checks for leaked weak references). The 4 cases from obs-rust#378 and the control pass. Refs obs-rust#1029. Co-Authored-By: Claude Opus 5.5 <[email protected]> * linux-pulseaudio: Retry failed stream restarts with a pause and a limit A source restarts its stream when it fails while the server stays up (obs-rust#378), but: - if the restart fails synchronously (the stream cannot be created, connected or given a valid sample spec) while the device is there and the server is connected, nothing retries it until some device appears; - if the server keeps failing the restarted stream, the source restarts it at once every time, with no pause and no limit, each time on a new server connection (obs-rust#532). Route both through the restart counter the server reconnection already uses (pulse_restart_should_retry(), pulse_call_later()): - pulse_start_recording() now says why it failed: no server, no device, or anything else. A restart that fails while the device is there is retried every PULSE_RESTART_RETRY_USEC (100 ms). A missing device is still waited for (a new device event), so a device that is gone for good is not polled, and a lost server is still left to the reconnection, which retries missing devices as before. - A failed stream is restarted at once the first time and after PULSE_RESTART_RETRY_USEC after that. - Both count in the same restart_attempts. After PULSE_RESTART_MAX_ATTEMPTS (100) the source logs a warning, stops the stream and waits for a device to appear. - The counter is reset when the stream delivers audio, instead of when a start call returns, so a stream that starts and then fails right away keeps counting. The read callback runs with the mainloop locked, so the UI thread reads and writes the counter under pulse_lock(). - A pending per-stream retry does nothing if a device event restarted the stream meanwhile. The decisions are pulse_start_should_retry() and pulse_stream_failed_should_restart() in pulse-reconnect.c, which need no server; test_pulse_reconnect gains four cases for them (14 of 14). test_pulse_stream_restart: 7 of 7. Fixes obs-rust#1029. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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
An Audio Input Capture (or Audio Output Capture) on PulseAudio or PipeWire now records again after its own stream dies while the connection to the sound server stays up. Before, it stayed silent until its settings were changed or OBS was restarted.
pulse-input.cline 347). A chosen device is connected withPA_STREAM_DONT_MOVE. The restart from plugins: Reconnect Linux capture after PipeWire restarts #109 (pulse_reconnected) runs only when the whole server connection is lost and comes back.The fix, all in
plugins/linux-pulseaudio:pulse_stream_on_event()(new, inpulse-reconnect.c, no context or stream calls) decides what to do:test/cmocka: Add failing test for a PulseAudio input whose stream dies:test_pulse_stream_restartbuilds the plugin's capture code into the test and runs it against a private PipeWire, WirePlumber and pipewire-pulse started bytest_pulse_monitor_device.sh(own runtime directory, config and D-Bus, no hardware), with virtual sources it loads itself. libobs's source calls are stubbed with--wrap, so it needs no display. Each source counts the frames handed toobs_source_output_audio, and UI tasks run on their own thread. Cases:pw-cli destroy);3 of 4 fail: no audio within 3 s after the replug, after the kill, or after the late plug-in. The deleted-device control passes.
linux-pulseaudio: Restart an input whose stream dies while connected: 4 of 4 pass.test_pulse_reconnectgains three cases forpulse_stream_on_event(), which need no sound server: 10 of 10.Motivation and Context
Fixes #377 (upstream obsproject/obs-studio#10072, reported by foresto).
Why this one: the audio stops with no error in the UI, so the problem often shows up only after a recording or stream has gone out without the microphone. The triggers are routine on Linux: switching consoles, replugging a USB microphone or headset, a driver reload. The only workarounds are reselecting the device or restarting OBS. #109 already covers the full server restart; this covers the per-stream cases it leaves out. No upstream PR exists.
How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON), on current master:test_pulse_stream_restart: 3 of 4 cases fail at the RED commit (same in both lanes) and 4 of 4 pass at GREEN.ctest -Vshows every case run against the private server (no SKIPPED lines; about 17 s at RED, 9 s at GREEN).DISPLAYorWAYLAND_DISPLAY.test_pulse_reconnect: 10 of 10, including the 3 new decision cases.test_pulse_monitor_device(libobs: Keep PulseAudio monitoring on the chosen device #275), which shares the harness, still passes.ci/test_registration.pyare clean.CI: the Tier 2 Linux image (
rust/tools/linux-validate/Dockerfile) haslibpulse-devbut no PipeWire, WirePlumber or pipewire-pulse. Sotest_pulse_stream_restartskips there (exit 77), astest_pulse_monitor_devicealready does. The three newtest_pulse_reconnectcases run in CI. Addingpipewire pipewire-pulse wireplumber pulseaudio-utils dbusto that image would let both end-to-end tests run; that is left for a separate change.Not tested / not fixed:
Types of changes
Checklist:
🤖 Generated with Claude Code