feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

feat(linux): pace capture at exact fractional NTSC framerates - #5282

Merged
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing
Jun 30, 2026
Merged

feat(linux): pace capture at exact fractional NTSC framerates#5282
ReenigneArcher merged 4 commits into
LizardByte:masterfrom
djadjka:feat/linux-fractional-pacing

Conversation

@djadjka

Copy link
Copy Markdown
Contributor

Description

#4019 added support for the x-nv-video[0].clientRefreshRateX100 RTSP parameter, but
implemented the capture-side handling only for the Windows backend
(platform/windows/display_base.cpp); on Linux only the encoder time base got the exact
rational. The Linux capture loops still pace at the integer maxFPS, so for a client that
requests e.g. 11988 (Xbox, whose display pipeline runs at 120/1.001 Hz) the host delivers
120.00 fps while the client drains 119.88 fps. The 0.1% surplus accumulates one extra frame
every ~8 s, which the client-side pacer keeps correcting — visible as a periodic frame-queue
oscillation / micro-judder that no client setting can remove.

This PR mirrors the Windows handling in the four Linux capture pacers (kmsgrab, wlgrab,
x11grab, CUDA): when framerateX100 is present, the frame interval is derived from the
exact rational returned by video::framerateX100_to_rational().

Tested on an AMD RDNA4 + KDE Wayland host (KMS capture, Vulkan encoder) against a
moonlight-xbox client at 4K 119.88 Hz: the standing frame-queue oscillation on
the client disappears (queue settles flat instead of breathing by one frame every ~8 s).

Issues Fixed or Closed

Completes the Linux side of #4019.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas

AI Usage

  • Heavy: AI generated most or all of the code changes

@neatnoise

neatnoise commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

@djadjka

Copy link
Copy Markdown
ContributorAuthor

Would be possible to implement it to the new pipewire based capture (xdg portal, kwin grab) too? Or is it enough there that the compositor sets the max fps?

Double-checked: both PipeWire paths (xdg-portal portal_t and KWin grab kwin_t) share
pipewire::pipewire_display_t, whose init() already derives the pacing interval from
framerateX100_to_rational() — so they handle fractional rates exactly.

Compositor pacing isn't involved there: the format is deliberately negotiated as
variable rate (SPA_FORMAT_VIDEO_framerate = 0/1, "bypassing compositor pacing"), and
Sunshine paces itself. This PR just brings the legacy paths to parity with that.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a reusable function instead of copying the same code to so many different places.

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment threadsrc/platform/linux/pipewire.cpp Outdated
Comment threadsrc/platform/linux/pipewire.cpp Outdated
@andygrundman

Copy link
Copy Markdown
Contributor

Thanks, I am glad someone besides me cares about NTSC. :)

@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 99f06f4 to dd923f4CompareJune 16, 2026 15:51
@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecovBot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.53%. Comparing base (9cb3589) to head (eabb2f2).
✅ All tests successful. No failed tests found.

Files with missing linesPatch %Lines
src/platform/linux/pipewire.cpp0.00%3 Missing and 2 partials ⚠️
src/platform/linux/wlgrab.cpp0.00%3 Missing and 2 partials ⚠️
src/nvenc/nvenc_base.cpp0.00%3 Missing ⚠️
src/platform/linux/cuda.cpp0.00%1 Missing ⚠️
src/platform/linux/kmsgrab.cpp0.00%1 Missing ⚠️
src/platform/windows/display_base.cpp0.00%0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@ Coverage Diff @@## master #5282 +/- ##
==========================================
- Coverage 27.51% 25.53% -1.99% 
==========================================
Files 113 112 -1 Lines 25593 25202 -391 Branches 11237 10922 -315 ==========================================
- Hits 7043 6435 -608 - Misses 15560 16043 +483 + Partials 2990 2724 -266 
FlagCoverage Δ
Archlinux0.00% <0.00%> (ø)
FreeBSD-amd6413.36% <38.46%> (+0.05%)⬆️
Homebrew-macos-14?
Homebrew-macos-15?
Homebrew-macos-2621.34% <76.92%> (+0.04%)⬆️
Homebrew-ubuntu-24.04?
Linux-AppImage?
Windows-AMD64?
Windows-ARM6413.35% <56.25%> (+0.06%)⬆️
macOS-arm6419.31% <60.00%> (+0.05%)⬆️
macOS-x86_64?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing linesCoverage Δ
src/platform/linux/x11grab.cpp33.26% <100.00%> (-7.39%)⬇️
src/video.cpp51.59% <100.00%> (-1.09%)⬇️
src/video.h58.06% <100.00%> (-0.91%)⬇️
src/platform/linux/cuda.cpp0.00% <0.00%> (-1.68%)⬇️
src/platform/linux/kmsgrab.cpp0.00% <0.00%> (-3.86%)⬇️
src/platform/windows/display_base.cpp27.14% <0.00%> (-9.89%)⬇️
src/nvenc/nvenc_base.cpp30.10% <0.00%> (-0.32%)⬇️
src/platform/linux/pipewire.cpp0.16% <0.00%> (+<0.01%)⬆️
src/platform/linux/wlgrab.cpp0.00% <0.00%> (ø)

... and 71 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9cb3589...eabb2f2. Read the comment docs.

@djadjka

Copy link
Copy Markdown
ContributorAuthor

@ReenigneArcher, should I add anything to get this PR merged ?
Thank you!

@djadjka
djadjkaforce-pushed the feat/linux-fractional-pacing branch from fe85434 to 00acec7CompareJune 28, 2026 08:34

@ReenigneArcherReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New requirements since you created the PR: need more complete code documentation. https://app.readthedocs.org/projects/sunshinestream/builds/33342103/ (search for error:)

@andygrundman could you review since you're the only contributor I know using the NTSC framerates?

@andygrundman

Copy link
Copy Markdown
Contributor

This looks pretty good to me!

djadjkaand others added 4 commits June 30, 2026 08:24
When a client requests a fractional refresh rate via
x-nv-video[0].clientRefreshRateX100 (e.g. 11988 for an Xbox whose display
pipeline runs at 120/1.001 Hz), the encoder time base is already set to the
exact rational since LizardByte#4019, but the Linux capture loops still paced at the
integer maxFPS. The resulting 0.1% delivery surplus accumulates one extra
frame every ~8 s, which the client pacer keeps correcting (periodic frame
queue oscillation / micro-judder).
Apply the same exact-rational handling to the kmsgrab, wlgrab, x11grab and
CUDA capture pacing, mirroring the Windows implementation from LizardByte#4019.
Tested on an AMD (RDNA4) + KDE Wayland host with KMS capture against a
moonlight-xbox client at 4K 119.88: the standing frame-queue oscillation on
the client disappears.
Extract video::capture_frame_interval() and use it in all Linux capture
pacers, including the PipeWire path which carried its own copy of the
same math.
Address review feedback: extract video::framerate_to_rational() as the
single place implementing the "exact rational when framerateX100 is set,
integer framerate otherwise" pattern, and rebuild capture_frame_interval()
on top of it. Migrate the call sites that re-implemented the pattern:
avcodec and NVENC encoder setup become branchless, the PipeWire and
wlroots capture pacers no longer re-derive the rational for logging, and
the Windows strict frame rate reuses the helper inside its sentinel
branch (the {0,0} sentinel must stay to keep the refresh-rate matching
heuristic). Add unit tests for the new helper and the capture frame
interval, including the integer fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Doxygen runs with WARN_NO_PARAMDOC + WARN_AS_ERROR in the Read the Docs
build, which failed because framerate_to_rational and capture_frame_interval
carried a @brief-only block without documenting their config parameter or
return value. Add @param/@return to match framerateX100_to_rational.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ReenigneArcher
ReenigneArcherforce-pushed the feat/linux-fractional-pacing branch from 7919ddd to eabb2f2CompareJune 30, 2026 12:24
@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher
ReenigneArcher merged commit bba6c6c into LizardByte:masterJun 30, 2026
71 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@djadjka@neatnoise@andygrundman@ReenigneArcher