Skip to content

bug: linux-pulseaudio: input stutters when packets arrive in bursts (upstream #12835, #10808) #190

Closed

Description

@rdoupe

Upstream OBS bugs, reported by pollux78 in obsproject/obs-studio#12835 and guilhem in obsproject/obs-studio#10808 (replicated there by a maintainer). Code unchanged in this fork.

Location

plugins/linux-pulseaudio/pulse-input.c:172-175, used at line 214

static inline uint64_t get_sample_time(size_t frames, uint_fast32_t rate)
{
	return os_gettime_ns() - samples_to_ns(frames, rate);
}

Class

Logic error: wrong timestamps, audible audio loss.

Cause

Each packet is stamped by when it arrived, as if it ended at the moment of the callback. When several packets arrive together they all get nearly the same timestamp. Once a burst spans more than libobs' TS_SMOOTHING_THRESHOLD (70 ms, libobs/obs-source.c:1489, :1636), libobs stops smoothing and places audio by the raw timestamps: one packet lands ~75 ms early (overwriting audio), the next ~75 ms late (a gap). That is the "stutter/cutting" and the exceeded TS_SMOOTHING_THRESHOLD, diff=7xxxxxxx lines in the reporters' logs.

How it is reached

Any of:

  • a PipeWire graph quantum larger than the 25 ms fragment (4096 → occasional, 8192 → 239 of 580 packets break)
  • the capture thread stalling 100–150 ms (OBS under encoding load; one reporter fixed it by lowering recording quality)
  • two Audio Input Capture sources on the same device: both streams share the one pa_context in pulse-wrapper.c, and pipewire-pulse delivers the second stream's packets in bursts of up to 6 (Audio issue with multiple inputs on the same source (OBS 30.1.2, Flatpak, PipeWire) obsproject/obs-studio#10808). Separate contexts don't burst.

Reproduced with a private PipeWire 1.6.8 + pipewire-pulse and the real linux-pulseaudio.so in headless libobs, against a sample-counter ramp: no samples are lost, only their timestamps are wrong.

Proposed fix and failing test

Fix: move the timestamp into a small pulse-timing.c and keep a sample-counted timeline (base + frames so far). base follows the earliest plausible start seen, so bursts and late packets can't move it and nothing is stamped in the future; it is raised periodically so device clock drift doesn't build up lag, and it resyncs on real loss (>~1 s) and on stream reset.

RED test (cmocka, test_pulse_timing), replaying libobs' smoothing rule:

  • burst delivery (quantum 8192) stays contiguous: fails, 160 of 389 packets break
  • a 100 ms capture-thread stall is seamless: fails
  • a recorded trace of 120 real packet arrivals from the second stream on a shared device: fails, 23 breaks
  • guards that pass today: steady delivery, ±1000 ppm drift over 600 s with no future timestamps, real 2 s loss follows the clock, reset starts a new timeline

A prototype passes all of them and takes the live harness to 0 breaks on both sources.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_pulse_timing, timestamp moved into pulse-timing.[ch] with no behaviour change.
    2. GREEN: sample-counted timeline.
    3. Check on real hardware, as with plugins: Reconnect Linux capture after PipeWire restarts #109, on three machines (Ryzen laptop with Radeon 860M + RTX, Ryzen mini PC with Radeon 680M, i7 desktop with RTX 2070): PipeWire, two inputs on one mic, large quantum.
      Giving each source its own pa_context would also remove the Audio issue with multiple inputs on the same source (OBS 30.1.2, Flatpak, PipeWire) obsproject/obs-studio#10808 bursts, but it conflicts with the single-context reconnect logic from plugins: Reconnect Linux capture after PipeWire restarts #109, so it is out of scope here.
      First PR within two days.
  2. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    For everyone who reported or hit this in obsproject/obs-studio#12835 / obsproject/obs-studio#10808, a heads-up: it's fixed here in obs-rust by #194.

    Cause: the PulseAudio/PipeWire mic capture stamps each audio packet with the time it arrived. When packets arrive in a burst, they all get nearly the same timestamp, and once a burst spans more than 70 ms OBS overlaps or drops ~75 ms of audio. That's the stutter, and the exceeded TS_SMOOTHING_THRESHOLD, diff=7xxxxxxx lines in the log. Bursts come from a large PipeWire quantum, OBS being briefly stalled under encoding load, or two Audio Input Capture sources on the same mic.

    Workarounds on stock OBS: keep PipeWire's quantum at 1024 or below (no clock.force-quantum / large default.clock.quantum), lighten the encoder load if the stutter comes with heavy recording settings, and capture each mic only once (duplicate the source as a reference instead of adding a second Audio Input Capture).

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

    If you get a chance to try it, a short reply here on whether it fixes it for you would really help, especially if it does not. Your distro, OBS version and how you capture (device, number of sources, PipeWire quantum) are the useful details.

  3. ogmkp commented on Oct 11, 2026

    @ogmkp

    I already fixed only internally. AI undermines the efforts of people who have spent years studying and making major sacrifices to deliver quality community software and it weakens the free software economy which allows many of them to put food on the table, so I understand why they reject it for the official project.

  4. JuxGD commented on Oct 11, 2026

    @JuxGD

    well this is a first. getting an ai project directly promoted to me

    nope!

    (edit) wait lmao this is like vibe coded

    ok i'm not gonna shame you for it because it's not the right place but sorry i actually do wanna know, did you like check my repos or something before @-ing me? bc skimming over them it should be clear i wouldn't wanna use this like at all

  5. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    @ogmkp in this fork we care about bug fixes and if they work or not, and if they are in the hands of the user. a private artisinal file helps no one. please share and we can compare notes on this.

    @JuxGD if you or your agent read the post it explains exactly why you were tagged.

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