Bug 484819

Summary: Stuttering stream output while screen sharing
Product: [Plasma] xdg-desktop-portal-kde Reporter: Sahand H. <sahandh8282>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: CONFIRMED ---    
Severity: minor CC: aleixpol, jgrulich, kiwifruit, nate, phantomshift
Priority: NOR    
Version: git-master   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Recording of the observed result
Reproduction of the bug in Minecraft

Description Sahand H. 2024-03-31 14:23:52 UTC
Created attachment 167985 [details]
Recording of the observed result

***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***

SUMMARY
Hello there! I am a newbie in this forum and is is my first time making this bug report, any feedback would be appreciated!

In summary, when screensharing under Wayland on applications that support them, it causes stuttering and rubber-banding on the stream output.

STEPS TO REPRODUCE
1. Log onto Plasma using the Wayland session
2. Open up any application that supports Wayland screensharing without the use of xwaylandvideobridge (Firefox in this example)
3. Stream the entire screen in the communication application

OBSERVED RESULT
The stream seems to be choppy and stuttering, also shows a shadow mouse that sometimes has a different action icon.

EXPECTED RESULT
The stream to look smooth without the stuttering and choppiness

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.0.3
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2

ADDITIONAL INFORMATION
Comment 1 kiwifruit 2024-06-09 15:00:30 UTC
I have the exact same issue. I can easily reproduce the bug on plasma 6.0.5, and even 6.1.80. It seems to stutter only (or at least a lot more) when the mouse cursor moves.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: OpenSUSE Tumbleweed
KDE Plasma Version: 6.1.80 (git)
KDE Frameworks Version: 6.4.0
Qt Version: 6.7.1
Kernel: 6.9.3
Graphics Platform: Wayland
Comment 2 kiwifruit 2024-06-09 15:01:34 UTC
(In reply to kiwifruit from comment #1)
> I have the exact same issue. I can easily reproduce the bug on plasma 6.0.5,
> and even 6.1.80. It seems to stutter only (or at least a lot more) when the
> mouse cursor moves.
> 
> SOFTWARE/OS VERSIONS
> Linux/KDE Plasma: OpenSUSE Tumbleweed
> KDE Plasma Version: 6.1.80 (git)
> KDE Frameworks Version: 6.4.0
> Qt Version: 6.7.1
> Kernel: 6.9.3
> Graphics Platform: Wayland

Forgot to add that I'm on AMD (GPU & CPU), and gnome doesn't have this stutter issue, with the same applications.
Comment 3 kiwifruit 2024-06-09 15:38:36 UTC
Created attachment 170296 [details]
Reproduction of the bug in Minecraft

Notice how the game menu repeats frames in the screen sharing output. The pig in the background also shakes back and forth, suggesting repeated frames.

Also, shaking the cursor seems to improve the output frame rate, which is unexpected.

Higher res / bitrate video on YouTube: https://www.youtube.com/watch?v=QeKLOD0NPNs
Comment 4 phantomshift 2024-06-25 04:54:44 UTC
I believe the initial report is related to an older bug report which is still in fact waiting to be resolved upstream in Firefox's 128 release, where mouse movement causes the screen share to stutter due to cursor metadata being processed.
https://bugs.kde.org/show_bug.cgi?id=486081
(Until Firefox/Chromium release the relevant version in which the fix is implemented in WebRTC, I'm currently using a very lightly patched version of kwin gets around the issue which is why I don't comment on it in the second half of this comment).
The second report, on the other hand, brings to light a new issue specific to kwin (as noted here and in this comment https://github.com/Vencord/Vesktop/issues/629#issuecomment-2186671650) which I have reproduced myself through base chromium as well as the app they used.
The observed behavior is that if there is no cursor movement over the region that is being casted, the screen share will have a very low framerate, whereas if there IS cursor movement, the screen share will be completely smooth. As noted, "shaking the cursor" also seems to cause the issue, although this is because as of 6.1 shaking the cursor causes it to expand to make it easier to find, but this has the side effect of hiding the cursor from being captured (for example, it cannot be captured by spectacle), which is in effect making the cursor not move. The same effect is observed in the gameplay since as a first-person game the cursor itself never moves.

I add the additional detail that this problem only seems to occur on Chromium, as Firefox is capturing things just fine regardless of mouse movement.