Skip to content

linux-pulseaudio: Give each capture stream a connection of its own - #532

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-two-sources-large-quantum
Oct 13, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pulse-two-sources-large-quantum

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Two Audio Input Capture sources on the same device now both record cleanly when the PipeWire graph runs at a large quantum. Before, at a quantum of 2048 or more the second source was mostly silent in recordings (44 % to 80 % of a 30 s recording on the release).

  • pulse_stream_new() (plugins/linux-pulseaudio/pulse-wrapper.c) created every source's record stream on the plugin's one shared pa_context, so all captures shared one connection to the sound server.

  • pipewire-pulse delivers the second record stream of a connection unevenly at such quanta: nothing for seconds at a time, then everything it held at once. OBS can buffer at most about a second of audio, so most of what follows a hold is too late. The audio itself arrives (pulse-input: Got N packets counts nearly every frame); it's just late.

  • The same two streams on two connections are delivered evenly. Measured outside OBS with a small libpulse client that reads like pulse-input (25 ms fragments, PA_STREAM_ADJUST_LATENCY, one peek per callback), 20 s per run:

    Quantum one connection, two streams: second stream two connections
    2048 5 holds over 0.3 s, longest 5.4 s, 12 % of the audio still missing at the end 0 holds, longest gap 50 ms
    4096 9 holds, longest 3.9 s 0 holds (parec twice)
    8192 9 holds, longest 3.9 s 0 holds, longest gap 170 ms (one quantum)

    A larger fragment size (50 to 200 ms) only helped at some quanta.

The fix gives each stream a connection of its own:

  • pulse_stream_new() connects a new pa_context on the shared threaded mainloop, waits until it's ready, and creates the stream on it.
  • The new pulse_stream_free() disconnects and frees the stream and its connection together; pulse_stop_recording() uses it. The wrapper keeps a list of each stream's context, because a stream that failed no longer reports its context (test_pulse_stream_restart aborted in pa_context_set_state_callback() without the list).
  • The shared connection still serves device lists, server info, device events and reconnects. A failed stream and a server reconnect take the same paths as before (linux-pulseaudio: Restart an input whose stream dies while connected #378 restarts a stream that dies while the server stays up).
  1. test/cmocka: Add a failing test for two captures on one device: test_pulse_two_sources runs the linux-pulseaudio capture code against a private PipeWire + WirePlumber + pipewire-pulse stack (test_pulse_monitor_device.sh, no hardware), with libobs's source calls stubbed (--wrap) like test_pulse_stream_restart. Two captures record the monitor of a null sink:

    • captures_use_separate_connections: the two record streams belong to different clients (pactl list source-outputs);
    • second_capture_is_not_held_back: at quantum 2048 (pw-metadata), for 10 s, neither capture goes 500 ms without a packet.

    Both fail today: the captures share one client, and the second capture waits 2.1 to 4.4 s for packets (5 of 5 runs) while the first never waits more than 47 ms.

  2. linux-pulseaudio: Give each capture stream a connection of its own: 2 of 2 pass. The two captures are separate clients, and both wait at most 44 ms, which is one 2048-frame cycle.

Motivation and Context

Fixes #531.

This is a follow-up of our #194 (#190; upstream obsproject/obs-studio#10808 and #12835). #194 fixed how packets that come in bursts are timed. That covers two sources on one device at the default quantum, the case obsproject/obs-studio#10808 reported. Our release check then found this residual at quantum 2048 and above, where the timing can't help because the audio arrives seconds late.

Why this one: it's our own fix left incomplete, and "two sources on one device sound choppy" is one of the reports behind the most-discussed Linux audio issue upstream. Apps that raise the graph quantum (players and games that ask for a large latency) are common.

How Has This Been Tested?

Reproduced in the current release AppImage (OBS 33.0.0-beta6-799-gd711a972c, Rust libobs), headless: private PipeWire 1.6.8 + WirePlumber + pipewire-pulse, a null sink dev, a 48 kHz sample-counter ramp played into it, two Audio Input Capture sources on dev.monitor on tracks 1 and 2, a 30 s recording, and both tracks checked for silence and breaks in the ramp:

Build Quantum Track 2 silent Track 2 breaks TS_SMOOTHING_THRESHOLD lines
release 2048 80 %, 69 %, 44 % 41, 30, 26 76, 94, 63
release + this PR's linux-pulseaudio.so 2048 0.1 %, 0 %, 0.1 % 2, 0, 2 0, 0, 0
release + this PR's linux-pulseaudio.so 4096 / 8192 0 % / 0 % 0 / 0 0 / 0
same plugin code from master, rebuilt here 4096 / 8192 6 % / 35 % 11 / 30 17 / 78
either 1024 0 % 0 0

Track 1 was clean in every run. The few breaks with the fix fell in both tracks at the same moment, under heavy machine load, so they come from the load and not from this bug. The plugin was built from this branch and loaded with the AppImage's own libobs and libpulse.

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), on current master:

  • test_pulse_two_sources: both cases fail at the RED commit and pass at GREEN, in each lane. ctest -V shows both cases run, none skipped. 5 more runs at GREEN all pass: the longest wait was 43 to 55 ms for both captures.
  • The other PulseAudio tests (test_pulse_stream_restart, test_pulse_monitor_device, test_pulse_reconnect, test_pulse_timing, ...) pass at GREEN.
  • Without PipeWire the test exits 77 (skipped), like the other PulseAudio end-to-end tests. If pw-metadata can't force the quantum, only the second case skips.
  • Full ctest at GREEN: 152 of 152 in each lane, under a private Xvfb with software GL and the system libobs-opengl masked.
  • clang-format and gersemi are clean.

Not tested:

  • A real PulseAudio server (not pipewire-pulse). It gets one connection per capture too; libpulse supports many contexts on one mainloop.
  • CI has no PipeWire, so the new test builds and skips there, like test_pulse_stream_restart.

Each capture now shows up as its own "OBS" client in pavucontrol and pactl list clients.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, the test, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner October 13, 2026 09:39
rdoupe and others added 2 commits October 13, 2026 02:55
With two Audio Input Capture sources on the same device and the
PipeWire graph quantum forced to 2048 or more (an app asking for a
large latency), the second source is mostly silent in recordings: 44 to
80 % of a 30 s recording on the release, with "exceeded
TS_SMOOTHING_THRESHOLD" lines. obs-rust#194 fixed how packets that come in
bursts are timed, but this was left.

The audio arrives late, not wrong: linux-pulseaudio creates every
source's record stream on its one shared connection, and pipewire-pulse
delivers the second record stream of a connection unevenly at such
quanta, nothing for seconds and then everything at once. OBS buffers at
most about a second of audio, so most of it comes too late. The same
two streams on two connections are delivered evenly (checked with a
small libpulse client and with parec).

test_pulse_two_sources runs the capture code against a private
PipeWire + WirePlumber + pipewire-pulse stack (test_pulse_monitor_device.sh),
with libobs's source calls stubbed like test_pulse_stream_restart. Two
captures record the monitor of a null sink:
- captures_use_separate_connections: the two record streams belong to
  different clients (pactl list source-outputs);
- second_capture_is_not_held_back: at quantum 2048, for 10 s, neither
  capture goes 500 ms without a packet.

RED: both fail. The captures share client 51; the second capture waits
2.1 to 4.4 s for packets (5 of 5 runs) while the first never waits more
than 47 ms.

Refs obs-rust#531.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every Audio Input Capture source created its record stream on the
plugin's one shared PulseAudio connection. pipewire-pulse delivers the
second record stream of a connection unevenly when the graph quantum is
2048 or more: nothing for seconds at a time, then everything at once.
OBS buffers at most about a second of audio, so with two sources on one
device the second one was mostly silent in recordings.

pulse_stream_new() now connects a context of its own on the shared
mainloop for each stream, and the new pulse_stream_free() ends the
stream and that connection together. The wrapper keeps track of each
stream's context, because a failed stream no longer reports it. The
shared connection still serves device lists, server info, events and
reconnects.

GREEN: test_pulse_two_sources 2 of 2 (separate clients; the second
capture's longest wait 44 ms in 10 s, like the first). The other
PulseAudio tests pass, including test_pulse_stream_restart.

Fixes obs-rust#531.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=2a677a94be708a4814021756d5dd1195513a7911 secs=359 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791885703,"gate":"rust/all/fmt","host":"linux-x86_64","key":"03efbcd9393845fb1d417cb449fc9b1bfa8d188e36cfc35db9e56f46c2c8e263","lane":"lint","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":31,"stamp":"7da3a7aad5abf93cea8b3cf372ee3bed","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"03efbcd9393845fb1d417cb449fc9b1bfa8d188e36cfc35db9e56f46c2c8e263","lane":"lint","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":31,"stamp":"88255a486176dd79ca4429640a884a13","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"3ad68e9af81fa7637dd323dcf81ff16d52b2559ed355c942acf92d0766d0fcc6","lane":"rust-test","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":123,"stamp":"073da15bfb03431401cf57ce754c2504","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"d1dc08d75d065bad4933900719b7468f","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"c74502b6c0249a0391857370ce67289c","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"2dc8efc2420944aeba15bc5445eeddba","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"66e314a5ed1f66051d93ba552ce1b2a8","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"ea9209739b430b4b810798ef608a2e5c","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"7387b9d78b1ca610414dabfb93c4efb4195c1d962c6d58cd5351f87d7b9dd142","lane":"cross","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":105,"stamp":"8afb438edc063052a161e6ee5fb51dfd","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
Ci-Attestation: {"at":1791885703,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"57d9e6ba898a2b6eed47fc5bf3cbae9654ff4d0e40b6d943d1be34d9679d7feb","lane":"tier2-linux","parents":["979995da81e03ac83f8d82d979ed767657c1ac0e"],"secs":100,"stamp":"013062f3bf42ea24cb97723fb8a65141","tree":"2a677a94be708a4814021756d5dd1195513a7911","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally (Tier 2 image + pipewire, pipewire-pulse, wireplumber, dbus):

  • RED f5f132d: test_pulse_two_sources fails captures_use_separate_connections
  • GREEN 2f989b1: 2/2. It needs a sound server, so plain CI skips it.
  • Rebased on master, local gate passed; pushed as 5ae6773.

@zackees
zackees force-pushed the fix/pulse-two-sources-large-quantum branch from 2f989b1 to 5ae6773 Compare October 13, 2026 10:01
@zackees
zackees merged commit 96f66f6 into obs-rust:master Oct 13, 2026
19 checks passed
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]>
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]>
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 16, 2026
…bs-rust#1057)

* test/cmocka: A dropped stream connection leaves its Pulse source silent (RED)

Fails, every run, in both lanes (10 of 10 each):
dropped_connection_restarts ("after the server dropped its stream's
connection: 'capture A' produced no audio within 3000 ms") and
repeated_connection_drops ("after its connection was dropped 1 times:
'capture A' produced no audio within 3000 ms").

Follow-up of obs-rust#532, which gives each capture stream a server connection
of its own. When the server drops only that connection, the stream
fails with its context, and pulse_stream_state_changed() takes the
failed context for the lost shared connection: it leaves the restart
to the reconnection, which never comes because the shared connection
is fine. The source stays silent for good, and nothing is logged.

test_pulse_stream_restart gains five cases:
- the server drops the connection of one source's stream (pw-cli
  destroy on its client): audio must return within 3 s, and the other
  source must not restart;
- the connection is dropped 5 times, then twice in a row before the
  new stream delivers audio: audio returns each time, the source never
  gives up, and no connection is leaked;
- controls, which pass today: a source destroyed while its restart
  after a drop is pending leaks nothing; only the shared connection is
  dropped, and the reconnection restarts each source once; pipewire-
  pulse restarts, and each source is restarted once.

Refs obs-rust#1056.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* linux-pulseaudio: Restart a stream whose own connection was dropped

Since obs-rust#532 each capture stream has a server connection of its own
besides the shared one. When the server dropped only a stream's
connection, the stream failed with its context, and
pulse_stream_state_changed() took the failed context for the lost
shared connection: it left the restart to the reconnection, which
never came because the shared connection was fine. The source stayed
silent for good, with nothing in the log.

Check the shared connection instead (pulse_connected()). A stream whose
own connection is gone is restarted like any failed stream, through
the retry, pause and limit of obs-rust#1031. A lost shared connection or a
server restart is still left to the reconnection. If a stream's
failure is seen before the shared connection's, its restart finds no
server and does nothing, and the reconnection replaces the stream as
before, so each source is still restarted once.

test_pulse_stream_restart: 12 of 12, 10 of 10 runs in each lane.

Fixes obs-rust#1056.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: linux-pulseaudio: second Audio Input Capture on the same device mostly silent at PipeWire quantum 2048+ (follow-up of #194)

2 participants