Repository navigation
input: rate-limit gamepad state sends and remove SDL timers from the input path - #2061
Closed
robinmaomao wants to merge 3 commits into
Closed
robinmaomao wants to merge 3 commits into
robinmaomao wants to merge 3 commits into
Conversation
Cap how often gamepad state packets are sent to the host. Controllers that poll much faster than the stream frame rate (such as handheld built-ins that report at ~1000 Hz) currently generate roughly one LiSendMultiControllerEvent() per millisecond. Sunshine processes every packet as a synchronous ViGEm IOCTL on its single input thread, which surfaces as periodic frame-pacing hitches while the stick is moving. Axis and trigger updates are now coalesced into a configurable window (default 8 ms = 125 Hz). Button edges are still sent immediately, and a one-shot SDL timer pushes a user event so the trailing state is always delivered - dropping it would leave the host with a stale stick position. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The gamepad send throttle used 1-8 ms SDL timers. With sdl2-compat, SDL_RemoveTimer() destroys the timer's properties before cancelling the timer, so a callback racing with removal dereferences freed memory and crashes inside SDL3's SRW lock helpers (observed at SDL3.dll+0x1B8444). Replace every input-path SDL timer with main-loop deadlines: - gamepad send throttle and mouse-emulation polling - touch long-press, drag, and tap-release timers Pending state and deadlines are serviced from the SDL event loop, and SDL_WaitEventTimeout() is capped by the nearest deadline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
I think this should be handled on the host side, not the client. If the host's input driver can't handle 1000 Hz input, that should be its problem to handle batching, not Moonlight's. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Controllers that poll much faster than the stream frame rate can cause periodic stutter and frame-pacing hitches on the host.
With a joystick present, Moonlight batches axis events but does not limit how often they are sent. A 1000 Hz controller can therefore produce roughly 1000
LiSendMultiControllerEvent()calls per second, andSDL_WaitEventTimeout()degrades to a 1 ms poll on the thread that also presents video frames. On the host, Sunshine handles the Xbox 360 virtual pad path with one synchronous ViGEm IOCTL per packet (unlike the DS4 path), so this packet rate turns into frame-pacing spikes (see #1156).Reported against the built-in controller of Windows handhelds such as the ROG Xbox Ally X.
Changes
SDL2.dllas sdl2-compat overSDL3.dll, whereSDL_RemoveTimer()destroys the timer's properties before cancelling it. A callback racing with removal dereferences freed memory and crashes in SDL3's SRW lock helpers (observed atSDL3.dll+0x1B8444,SDL_UnlockRWLock_srw). Pending state and deadlines are now serviced from the SDL event loop, andSDL_WaitEventTimeout()is capped by the nearest deadline. This also migrates the touch long-press / drag / tap-release timers and the gamepad mouse-emulation tick off SDL timers.Testing
LNK4291fromQt6EntryPoint.lib.Notes / limitations
Unlimitedrestores the previous upstream behavior exactly, which is useful for A/B testing.