Sunshine icon indicating copy to clipboard operation
Sunshine copied to clipboard

New frame time limit does not work well with VRR

Open nissel opened this issue 1 year ago • 9 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is your issue described in the documentation?

  • [x] I have read the documentation

Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

I'm streaming at 4K 120hz, with releases prior to v2025.628.4510 the video stream FPS would match the hosts game/render FPS down to about 10 FPS, this allowed VRR clients to adjust suitably.

With the new version, presumably due to changes in "fix(video): base min frame time strictly on client framerate by @ReenigneArcher in https://github.com/LizardByte/Sunshine/pull/3844)" the video stream minimum FPS now only drops to about 90 when in game, at 80 FPS it appears to start doubling frames and actually stream at ~120FPS. Strangely on desktop with static content it will drop lower.

This results in juddery playback on a VRR supporting client, such as moonlight on windows.

I rolled back to the previous stable release with no other changes and this solves the issue.

Expected Behavior

Allow the video stream FPS to match the rendered FPS to support VRR clients correctly. Maybe some sort of setting/toggle.

Additional Context

No response

Host Operating System

Windows

Operating System Version

Windows 11 24H2

Architecture

amd64/x86_64

Sunshine commit or version

v2025.628.4510

Package

Windows - installer (recommended)

GPU Type

NVIDIA

GPU Model

RTX 4080

GPU Driver/Mesa Version

576.88

Capture Method

None

Config


Apps


Relevant log output

N/A

nissel avatar Jul 06 '25 18:07 nissel

Unexpected high stream FPS at 53 and 78 FPS Image Image

Correct at 91 and 119 FPS Image Image

nissel avatar Jul 06 '25 23:07 nissel

Related: I would just like to add that I think this new frame time logic is a problem as currently implemented since it prevents some client-specific workarounds for to fix frame pacing.

i.e. On a few of my Android clients I will set Moonlight to 120 FPS while leaving the host running at the actual client refresh rate (like 60 or 90). I need the incoming stream to be the exact host refresh rate, but now the stream is being forced to 120 FPS and bad frame pacing as a result.

At very least I think we need a way to turn this new logic off.

MoreOrLessSoftware avatar Jul 15 '25 14:07 MoreOrLessSoftware

I'll second this. I have been using the below workaround since this patch was introduced, with a hardcoded value of 50ms (1000/20). This is the same as the old min_fps_factor=2.

My lowest target framerate is 24fps (41.6ms), which I sometimes use for movie content. It has worked well for me and I would propose it as a reasonable solution to this issue. I'd also suggest we give the variable a new name, because it's not representing the minimum frame time, but rather the maximum time a static frame is allowed to persist.

--- a/src/video.cpp
+++ b/src/video.cpp
@@ -1891,7 +1891,7 @@ namespace video {
     });

     // set minimum frame time based on client-requested target framerate
-    std::chrono::duration<double, std::milli> minimum_frame_time {1000.0 / config.framerate};
+    std::chrono::duration<double, std::milli> minimum_frame_time {1000.0 / 20};
     BOOST_LOG(info) << "Minimum frame time set to "sv << minimum_frame_time.count() << "ms, based on client-requested target framerate "sv << config.framerate << "."sv;

     auto shutdown_event = mail->event<bool>(mail::shutdown);

andygrundman avatar Jul 23 '25 23:07 andygrundman

The new frame time logic is also causing some issues for me. A toggle for the old logic would be great. Or maybe restore the old "min_fps_factor" setting and have "0" be the new, default logic?

I play on a Steam Deck OLED where I mostly stream most games at 90FPS. Because of that, I always have the stream FPS set to 90 in Moonlight and haven't touched it in months. However, some games have 60FPS caps or run more consistently at a slightly lower frame rate (like 80). In those situations, I would quickly change the Steam Deck's refresh rate to match the game's capped frame rate. That way the stream stays smooth. Essentially, it's a manual "VRR". It only takes a few seconds to adjust on the Steam Deck and didn't interrupt the stream, so it wasn't a problem. However, now I have to do that and back out the Moonlight settings and adjust the stream FPS. If I don't, I get this:

Image

When this happens, the incoming frame rate jumps all over and the stream stutters.

I understand that this isn't a typical use-case for Sunshine/Moonlight, and I technically have a workaround (manually changing the Moonlight FPS setting depending on the game). But like OP mentioned, this is an issue for any kind of "VRR" setup.

EDIT: For comparison, here's what I get on v2025.122.141614 when the stream is set to 90FPS and the game is 60FPS:

Image I would just change the refresh rate to 60Hz in the Steam QAM it'd work smoothly.

xanderfrangos avatar Jul 23 '25 23:07 xanderfrangos

We probably could go back to the old logic once the WGC pull request is done #4066 because that captures at near constant rate even when idle

Nonary avatar Jul 23 '25 23:07 Nonary

I don't know that WGC is relevant, since WGC would not even get triggered in any of the mentioned use cases.

Also, if I understand the current architecture correctly, the DDC/WGC capture is a layer removed: they can capture the desktop at any rate, but the "image convert" layer, whatever it's called, detects static/duplicate frames and doesn't stream them. That's where this variable lives, so those WGC frames would be subject to the same issues.

Edit: That means this issue should exist on all platforms, right?

andygrundman avatar Jul 24 '25 00:07 andygrundman

I don't know that WGC is relevant, since WGC would not even get triggered in any of the mentioned use cases.

Also, if I understand the current architecture correctly, the DDC/WGC capture is a layer removed: they can capture the desktop at any rate, but the "image convert" layer, whatever it's called, detects static/duplicate frames and doesn't stream them. That's where this variable lives, so those WGC frames would be subject to the same issues.

I am saying that the whole point of adjusting minimum frame time is to prevent sunshine from dropping down to low FPS when there is static content on the screen.

This is not necessary when using WGC to capture instead, as it appears to be able to retain FPS even if there is static content on the screen.

But I am not sure if this issue is also present in Linux or not.

Nonary avatar Jul 24 '25 00:07 Nonary

I think I have experienced a related issue to this where the frame rate seems to go above requested fps when hovering around half requested fps, resulting in very high frame queue delay times.

From experimentation I found an area where host FPS would hover around 55-65fps, but sunshine was sending at 125-130 fps even though requested fps was 120. Average frame queue delay hovered around 8-16ms and the stream felt noticeable sluggish / laggy.

I reverted to previous stable version of sunshine, same experiment and sunshine again was sending at the exact same fps as the game was rendering - and average frame queue delay now hovers around 0.5ms.

So it might not only be VRR that is affected.

Odd why sunshine fps can go above requested fps when doubling frames. If that is what is going on. 🙈

micdah avatar Jul 29 '25 18:07 micdah

Just confirming the fix is good, new pre-release build is working well. I've set the new minimum fps target to 10 and it behaves correctly for me. Thanks all.

nissel avatar Jul 30 '25 12:07 nissel