Commit Graph
108 Commits
Author SHA1 Message Date
Cameron Gutman 274ec03d85 Don't rewrite constant fields of enqueued controller packets
Even though it's writing the same values, it's still a data race.
2026-11-11 14:09:46 -06:00
Cameron Gutman edb4e9e05f Use atomics for initialized variable in input functions 2026-11-10 23:59:52 -06:00
Cameron Gutman 4853e70489 Add jumbo control stream messages for larger than 16-bit payloads 2026-11-01 15:07:12 -06:00
Cameron Gutman c7dff22963 Add replay detection to RTSP and control streams
Replays can do very little harm in these contexts, but let's detect and prevent them anyways.

Fixes #165
Closes #170
2026-11-01 14:07:45 -06:00
Cameron Gutman 421bd74e01 End mouse motion batches on mouse button events 2026-10-22 21:26:18 -05:00
Cameron Gutman f1cca2dd6b Fix a couple pen event batching issues 2026-10-22 21:16:11 -05:00
Cameron Gutman 970b0729c5 Fix use after free of queued controller packets
We could attempt to use a freed controller packet if
- The connection terminated with one still queued
- We hit the maximum input queue size limit

In either of those cases we could both fail to send
the desired input and cause memory corruption.
2026-10-22 20:44:37 -05:00
Cameron Gutman 448b2c6868 Latch mouse deltas before sending to prevent starvation
It's possible a client sending rapid relative mouse motion
could completely monopolize the input thread and prevent it
from exiting the loop.
2026-10-22 20:38:22 -05:00
Cameron Gutman 04053843c9 Pack NV_UNICODE_PACKET densely for Sunshine
This reduces overhead up to 32x for large text blocks and avoids
flooding the ENet connection with packets all at once.
2026-10-19 22:51:41 -05:00
Cameron Gutman 4a95eb35b2 Send UTF-8 events on the keyboard channel
This avoids racing with regular keyboard events that could affect the input.
2026-10-19 01:25:18 -05:00
Cameron Gutman f900dd4767 Add MODIFIER_EXTENDED flag to indicate extended keys 2026-09-26 14:50:13 -05:00
Cameron Gutman 2600beaf13 Add support for controllers with dual touchpads 2026-05-14 22:13:45 -05:00
Cameron Gutman b126e481a1 Improve locking for batched mouse and gamepad sensor events
By unlocking the mutex before we enqueue the new entry, we can avoid the input thread immediately contending on the mutex after the new item wakes it up.
2025-11-25 17:30:01 -06:00
Cameron Gutman e59a5f5b53 Rewrite gamepad input batching to batch on the enqueue-side
- Allows successful batching of interleaved input from multiple controllers
- Avoids enqueue/dequeue overhead and memory allocation when batching
2025-11-09 15:47:12 -06:00
Andy Grundman 82ee2d6590 Improve support for high-resolution stats
* This patch adds a new microsecond-resolution function call, LiGetMicroseconds(), to complement
the existing LiGetMillis(). Many variables used by stats have been updated to work at this
higher resolution and now provide better results when displaying e.g. sub-millisecond frametime stats.
To try and avoid confusion, variables that now contain microseconds have been renamed with a suffix
of 'Us', and those ending in 'Ms' contain milliseconds. I originally experimented with nanoseconds but it
felt like overkill for our needs.

Public API in Limelight.h:
uint64_t LiGetMicroseconds(void);
uint64_t LiGetMillis(void);
const RTP_AUDIO_STATS* LiGetRTPAudioStats(void);  // provides access to RTP data for the overlay stats
const RTP_VIDEO_STATS* LiGetRTPVideoStats(void);

Note: Users of this library may need to make changes. If using LiGetMillis() to track the duration of
something that is shown to the user, consider switching to LiGetMicroseconds(). Remember to divide by
1000 at time of display to show in milliseconds.
2025-11-06 20:27:01 -06:00
Cameron Gutman 9686f6942f Consolidate PltCloseThread() and PltJoinThread() 2024-02-17 18:14:03 -06:00
Cameron Gutman 05c3f9c754 Bind our UDP sockets to the same local address used by RTSP handshake
This means we can ensure a consistent local address for our outgoing PING
traffic to keep the UDP flows alive without having to call connect() which breaks
with multi-homed hosts on GFE and Sunshine v0.20 and earlier.
2023-10-26 01:09:26 -05:00
Cameron Gutman c86f49ee7f Remove batch delay for gamepad motion events
The batch delay will basically always trigger for motion reports that contain both accel and gyro
data (like PS4/PS5 controllers) because we will report accel and gyro data within 1 ms every time.
This gets even worse when multiple controllers are connected and reporting motion data.

There shouldn't be any real need to batch these because they're unreliable sequenced packets,
so we can just remove the delay.
2023-10-16 22:08:02 -05:00
Cameron Gutman c9e5660b8c Track the last sent controller packet by controller index
This avoids stacking batch delay when multiple controller are connected
2023-10-16 22:02:55 -05:00
Cameron Gutman 615b5e2bba Rewrite input batching for mouse and gamepad sensors
The old method was too inflexible (depending on consecutive events to batch) that it couldn't
really handle stressful cases like high polling rate mice combined with multiple gamepads
reporting motion sensor events.
2023-10-16 21:43:05 -05:00
Cameron Gutman 8d30079033 Prevent flooding the queue with motion events 2023-10-16 18:05:42 -05:00
Cameron Gutman 47fa51034a Revert change to send mouse position and gamepad events as unreliable
This can lead to poor behavior on lossy networks
2023-10-16 18:02:57 -05:00
Cameron Gutman 836bc6611f Batch split UTF-8 packets at the ENet layer 2023-10-11 01:18:12 -05:00
Cameron Gutman 8d73a9f8b7 Allow the UTF-8 splitting loop to be interrupted 2023-10-11 01:10:34 -05:00
Cameron Gutman d828868bc8 Fix uninitialized channel and packet flags in split UTF-8 packets 2023-10-11 00:56:54 -05:00
Cameron Gutman da7967632a Add a workaround for clients still using a short to represent button flags 2023-10-10 18:07:32 -05:00
Cameron Gutman 426745fa24 Extend to 32-bit button flags for the older LiSendControllerEvent() API 2023-10-10 18:07:08 -05:00
Cameron Gutman d055599608 Map Misc button to Guide for GFE hosts 2023-10-05 20:29:18 -05:00
Cameron Gutman 78e06eb613 Batch control stream messages 2023-08-19 11:27:16 -05:00
Cameron Gutman 325518b47a Add LiGetHostFeatureFlags() API 2023-08-03 22:09:30 -05:00
Cameron Gutman 70a2e305bc Extend pen/touch APIs with contact area and orientation 2023-07-22 15:01:03 -05:00
Cameron Gutman d8b2b04bb2 Reuse pressure field in touch/pen events to provide hover distance 2023-07-22 12:33:19 -05:00
Cameron Gutman 2d0badde9a Send zero state gyro events as reliable traffic 2023-07-12 01:05:23 -05:00
Cameron Gutman 377d37503f Split controller motion events onto their own channels 2023-07-04 16:18:52 -05:00
Cameron Gutman 53c29f11ba Send mouse deltas reliably for now 2023-07-04 15:48:08 -05:00
Cameron Gutman 0095141e08 Split control data into multiple channels and optimize packet flags based on type of data
This can significantly performance on lossy networks by avoiding HOL blocking.
2023-07-04 14:49:21 -05:00
Cameron Gutman 7d59c6e14e Fix motionType value in motion packets 2023-07-04 14:18:27 -05:00
Cameron Gutman 54e1556c40 Constrain the reported controller number by the max gamepad count 2023-07-04 14:16:53 -05:00
Cameron Gutman a0f8c060c0 Introduce new protocol extensions for controller RGB LEDs and battery state 2023-07-02 14:38:54 -05:00
Cameron Gutman 28d63b11dd Fix float values in pen events 2023-06-25 20:06:43 -05:00
Cameron Gutman 8c447137d6 Fix controller arrival packet to actually contain the controller that arrived 2023-06-25 14:27:43 -05:00
Cameron Gutman 44c8b95400 Pen tilt is 0..90 not -90..90 2023-06-25 00:24:55 -05:00
Cameron Gutman de0efa861a Several fixes for touch and pen APIs 2023-06-24 21:25:48 -05:00
Cameron Gutman 5cbb6f210d Fix signness of pen tilt parameters 2023-06-24 15:14:17 -05:00
Cameron Gutman 812ec0e2b7 Allow exceeding 4 controllers for Sunshine hosts 2023-06-18 16:36:34 -05:00
Cameron Gutman 689450954c Add pen and motion batching 2023-06-18 14:30:16 -05:00
Cameron Gutman 372eb94ed0 Expand button flags to support additional buttons with Sunshine 2023-06-18 14:03:29 -05:00
Cameron Gutman 7eea7a7971 Fix endianness issues for BE systems 2023-06-18 13:50:39 -05:00
Cameron Gutman 329c55d52f Send pointer IDs instead of touch indices 2023-06-18 13:48:55 -05:00
Cameron Gutman 4a48024dc8 Introduce new input extension functions for touch, pen, motion, and controller arrival 2023-06-11 19:38:22 -05:00