Skip to content

linux-pipewire: Draw each screen capture frame on its own video tick - #612

Merged
zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-dup-skip
Oct 13, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-dup-skip

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Description

PipeWire screen capture now draws every frame it receives on its own video tick. Before, a recording of a 60 Hz screen at 60 fps repeated some frames and then skipped one, again and again.

  • process_video_sync() in plugins/linux-pipewire/pipewire.c replaced the capture's texture as soon as a frame arrived, and each video tick drew whatever arrived last. The compositor's frames (the display's vblank) and OBS's ticks run on separate clocks. Whenever the frames land close to a tick, a little delivery jitter makes one tick see two new frames (the first is never drawn) and the next tick none (the previous frame is drawn again).
  • Frames now wait in arrival order in a small obs_pw_frame_pacer (frame-pacing.c, no PipeWire or graphics calls, so it is tested on its own). video_render moves on by at most one frame per video tick, once per tick however often the source is drawn (preview, projectors). At most three frames are held; when a source runs faster than the output, the oldest waiting frame is dropped.
  • Waiting frames need textures of their own. Frames in memory were already uploaded into a new texture. DMA-BUF frames are now drawn into a texture of OBS's own as they arrive: after waiting for the explicit sync acquire point, and with the release point exported after the copy. Their buffers still go back to the compositor at once, as before; before, OBS kept drawing the imported buffer after returning it.
  • Crop and transform travel with each frame. The cursor still follows the newest metadata.
  • Trade-off: a frame that lands just after a tick is drawn on the next tick instead of being lost, so the capture can run up to one frame behind. A steady source between ticks is drawn exactly as before.
  1. test/cmocka: Screen capture draws some frames twice and skips others: test_pipewire_frame_pacing replays a compositor at a fixed rate with deterministic +-2 ms jitter against OBS's 60 fps ticks and counts what each tick draws. The pacer at this commit does what pipewire.c does today. 7 cases:

    • nothing is drawn before the first frame (guard);
    • steady frames between ticks are each drawn once (guard);
    • a jittery 60 Hz source at 34 phases: no skips, at most one repeat per run;
    • a source 1% faster than OBS (drifting clocks): only its surplus frames are lost;
    • a 120 Hz source keeps a bounded latency (guard);
    • a 30 Hz source is repeated, never reordered (guard);
    • every frame is released exactly once (guard).

    2 of 7 fail today: 8 bad phases with 901 duplicated and 905 skipped frames, and up to 27 duplicated and 33 skipped frames for the drifting source, where only 6 should go.

  2. linux-pipewire: Draw each screen capture frame on its own video tick: the fix. 7 of 7 pass: 1 duplicated and 0 skipped frames over all 34 phases, and 0 duplicated and 6 skipped for the drifting source.

Motivation and Context

Fixes #191 (upstream obsproject/obs-studio#13292, reported by debug686: recording a 60 Hz screen at 60 fps, on GNOME/Wayland with the Flatpak, shows some frames twice and then skips one). eclipise confirmed it on Fedora 44 with GNOME 50.1 and an NVIDIA card. They saw the same in GPU Screen Recorder, and OBS 32.0.4 shows it too once the newer GNOME is installed, which points to the compositor's delivery timing changing. Any capture that draws only the newest frame on its own clock turns that jitter into repeated and lost frames; OBS can absorb it.

Why this one: a recording that repeats and drops frames in the main Linux capture source, confirmed by a second user, open upstream with no fix.

How Has This Been Tested?

Reproduced in the current release AppImage (OBS 33.0.0-beta6-799-gd711a972c, Rust libobs), headless: a private Xvfb, a private D-Bus session with a fake ScreenCast portal, and a private PipeWire daemon. A producer sent 640x360 frames in memory, each showing its frame number as 16 black/white bars, on a fixed schedule. OBS recorded at 60 fps; the bars were decoded from every recorded frame (the first second left out), 3540 frames per 60 s run:

Producer Duplicated Skipped
60 Hz, steady 0 0
60 Hz, +-2 ms jitter 1 1 (this run's phase was away from the tick)
60.05 Hz (drifting clock), steady 19 21
60.05 Hz, +-2 ms jitter 150 153

A 60.05 Hz source has 3 more frames than OBS has ticks in 60 s, so 0 duplicated and 3 skipped is the best possible. The producer sends every frame once and in order; the repeats and gaps come from which frame each tick picks.

The same AppImage with linux-pipewire.so built from master, then from this branch (same harness):

Producer master this branch
60.05 Hz, steady 1 duplicated, 4 skipped 0 duplicated, 3 skipped
60.05 Hz, +-2 ms jitter 138 duplicated, 140 skipped 0 duplicated, 2 skipped

DMA-BUF, with a master build: a headless libobs on Wayland (a headless sway on the GPU's render node) running the real screen capture through the fake portal. The producer sent linear XRGB8888 GBM buffers with the same counters; the capture imported them (no fallback to memory). Each output frame was decoded through a raw video callback, 60 s per run:

Producer master this branch
60.05 Hz, steady 9 duplicated, 12 skipped 0 duplicated, 2 skipped
60.05 Hz, +-2 ms jitter 156 duplicated, 159 skipped 0 duplicated, 2 skipped

A real compositor: nested Hyprland 0.56.2 with xdg-desktop-portal-hyprland, capturing an mpv window that plays a 60 fps counter video on a 60 Hz output, 60 s: master 33 duplicated and 32 skipped, this branch 6 and 6 (mpv's own presentation is not perfectly regular either). The portal's DMA-BUF buffers could not be imported in this nested setup, so this ran on frames in memory.

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

  • test_pipewire_frame_pacing: 2 of 7 cases fail at the RED commit and 7 of 7 pass at GREEN. It needs no display, daemon or GPU, so it runs in CI.
  • The PipeWire end-to-end tests (test_pipewire_screencast_shm, test_pipewire_cursor_hdr, test_pipewire_screencast_resume, the camera tests) pass under a private Xvfb with every case run.
  • Full ctest at GREEN: 180 of 180 in each lane; the only skipped case is the expected open_crashes_without_obs_core.
  • clang-format is clean.

Not tested:

  • GNOME/Mutter, KDE and NVIDIA. The jitter in the tests and in the harness is chosen (+-2 ms), not measured on the reporter's system.
  • DMA-BUF with explicit sync (SPA_META_SyncTimeline): the test producer does not send sync objects. That path waits on the acquire point and exports the release point, as before, but around the copy instead of the draw.
  • HDR (10-bit) DMA-BUF screen capture: those frames are copied into a 10-bit texture.

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, 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 19:09
rdoupe and others added 2 commits October 13, 2026 12:17
test_pipewire_frame_pacing replays a compositor sending frames at a fixed
rate with +-2 ms of delivery jitter against OBS's 60 fps video ticks, and
counts which frames each tick draws. The decision is kept in a small
obs_pw_frame_pacer (frame-pacing.c) that for now does what pipewire.c does
today: every frame replaces the previous one at once and a tick draws the
newest.

Fails today: a 60 Hz source over 34 phases has 8 bad phases, 901
duplicated and 905 skipped frames in 10 s each; a source 1% faster than
OBS (drifting clocks) has up to 27 duplicated and 33 skipped frames where
only its 6 surplus frames need to go. Guards that pass: nothing is drawn
before the first frame, steady frames between ticks are each drawn once,
a 120 Hz source keeps a bounded latency, a 30 Hz source is repeated and
never reordered, and every frame is released exactly once.

Refs obs-rust#191.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A screen capture replaced its texture as soon as a frame arrived and each
video tick drew the newest one. The compositor's frames and OBS's ticks
run on separate clocks, so whenever frames land close to a tick, a little
delivery jitter makes one tick see two new frames (the first is never
drawn) and the next none (the previous one is drawn again): the recording
repeats a frame, then skips one.

Frames now wait in arrival order in obs_pw_frame_pacer, which moves on by
at most one frame per video tick (in video_render, once per tick however
often the source is drawn) and holds at most three frames, dropping the
oldest waiting one when a source runs faster than the output. A frame
that lands just after a tick is drawn one tick later instead of being
lost, so the capture may run up to one frame behind; a steady source
between ticks is drawn as before.

Waiting frames need textures of their own. Frames in memory were already
uploaded into a new texture; DMA-BUF frames are now drawn into a texture
of ours as they arrive (after waiting for the explicit sync acquire point
and exporting the release point after the copy), so their buffers still
go back to the compositor at once. Crop and transform travel with each
frame; the cursor still follows the newest metadata.

Fixes obs-rust#191.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b secs=349 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1791919376,"gate":"rust/all/fmt","host":"linux-x86_64","key":"0908a3cc7b905eec94aa94ddd1f403085ebf6154540e54c8223141b8d074a399","lane":"lint","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":25,"stamp":"0356762f6b925f2bca6614c854987cd4","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"0908a3cc7b905eec94aa94ddd1f403085ebf6154540e54c8223141b8d074a399","lane":"lint","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":25,"stamp":"49db61750d9dad98ab9250075cca9092","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"6a01d683a39a8095ec2f4b36606325cfec51c2fd03cac20b14c1721af7748ba4","lane":"rust-test","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":115,"stamp":"1610461617fde06538a8fbd7687b20fc","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"65b4b4a933109b853048e5f39246fe2a","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"54a75d2b98beb23f1a87db861b1be4d7","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"aaae464b796f288e649e6d8c1dbf4145","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"5b09ec2d1a7bb89c475432f6e4f3a6fc","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"313921e27496837e92d3f75269da6afa","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"469bb1beec08d0c3b561b8940158c81d5a28cc705405c92e958c27d15e1095d9","lane":"cross","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":89,"stamp":"3342443b5ff61ca411149d7f6634bef0","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791919376,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"62ca862125b6f6738ed188230e26cc06a99f3d0c0b97e94a614faa1c5a0e48ca","lane":"tier2-linux","parents":["1107015475c00a6ad1b45b73d5ab83f0deb4f18f"],"secs":121,"stamp":"0d2316bc5e62bef6c485562d5922fc8f","tree":"b9921fa7e202f1eb3af0959c477f5a2e27c6dd8b","v":1,"via":"run"}
@zackees
zackees force-pushed the fix/pipewire-dup-skip branch from 43f088e to efb69d8 Compare October 13, 2026 19:22
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally (Tier 2 OFF and ON):

  • RED eab1365: test_pipewire_frame_pacing fails jittery_frames_are_each_drawn_once_at_any_phase and drifting_source_loses_only_its_surplus_frames
  • GREEN 43f088e: 185/185
  • The pacing decisions are tested directly; the larger pipewire.c rework is covered by the existing PipeWire tests, which need a PipeWire daemon and skip in plain CI.
  • Rebased on master, local gate passed; pushed as efb69d8.

@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Follow-up: since the pipewire.c rework isn't covered by plain CI, I also ran every PipeWire test against efb69d8 with a private PipeWire daemon, WirePlumber and D-Bus under xvfb-run. 11/11 pass: screencast_resume, screencast_shm, camera_nv12, camera_unplug, camera_unload, cursor_hdr, context_fail, frame_layout, frame_pacing, reconnect, wrapper.

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-pipewire: screen capture duplicates then skips frames (upstream #13292)

2 participants