963 Commits

Author SHA1 Message Date
Cameron Gutman
15b55a441b Add LiGetExtraLaunchArgs()
The string returned from this function should be appended to the end of the /resume and /launch query parameters.
2024-01-14 11:48:59 -06:00
Cameron Gutman
723cac034b Discard unencrypted packets on encrypted control stream 2024-01-14 11:41:01 -06:00
Cameron Gutman
6e9ed871bc Add support for X-SS-Connect-Data in RTSP SETUP for control stream
This allows the host to provide a 32-bit integer that will be sent
in the data of the ENet connect event, similar to X-SS-Ping-Payload
for video and audio.

The host can use this data to uniquely identify a client when IP
addresses are not stable across the various separate connections,
such as when the client is behind a Carrier-Grade NAT.
2023-12-28 16:56:06 -06:00
Cameron Gutman
50d8dcb072 Update ENet submodule with Apple dual stack socket fix 2023-12-28 16:10:55 -06:00
Cameron Gutman
3aae4cdc59 Improve ENet socket error propagation for better debuggability 2023-12-22 13:45:50 -06:00
Cameron Gutman
3ed3ba6253 Remove separate codec, HDR, and remote bitrate adjustments
We currently scale bitrate based on both remote vs local, SDR vs HDR, and H.264 vs
HEVC vs AV1. This has led to a lot of user confusion wondering why the bitrate
doesn't seem to match their selection in some configurations.

In H.264 local streams, we will currently overshoot the selected bitrate by about
20% due to FEC, while remote streams will be right around the selected bitrate due
to remote-specific FEC bitrate adjustments.

HEVC and AV1 streams (as configured by most clients) basically behave similarly
between local and remote, since the codec bitrate adjustment factor of 75% is nearly
the same as the FEC bitrate adjustment factor of 80%. However, this adjustment was
only performed for SDR streams so local HDR streams would overshoot like H.264.

This change cleans up all this mess by using a single non-codec-specific video
bitrate adjustment for FEC in all cases. It also allows Sunshine to perform the FEC
adjustment on its end if the default FEC value of 20% has been overridden by the
user or if we implement dynamic FEC support in the future.

The net result is HEVC and AV1 SDR streams will only see a tiny bitrate increase,
but HDR and H.264 may see noticable 20% bitrate reductions that may require the
user to adjust their bitrate setting to reach the effective value they got before.
However, the new behavior should be more intuitive for users going forward since
changing codecs, using a VPN, or enabling HDR won't cause significant changes to the
video bitrate.
2023-12-03 20:09:34 -06:00
Cameron Gutman
5de4a5b85a Bind the control stream socket to the local address used for other UDP traffic 2023-10-26 01:27:31 -05:00
Cameron Gutman
bbf15af837 Revert "Use connected datagram sockets for audio and video"
This causes problems on multi-homed GFE and Sunshine (prior to v0.21) hosts
because audio and video data can be sent back from an address different than
the one we used as our original destination address.

This reverts commit c13f4a323fc5d25bf9e1d18ac8166d6b5fad22b8.
2023-10-26 01:15:27 -05: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
f78f2135fa Don't strictly enforce picture data following the first PPS in debug mode 2023-10-13 23:23:27 -05:00
Cameron Gutman
5e844aad08 Fix UBSan warning for signed integer overflow 2023-10-11 20:09:48 -05:00
Cameron Gutman
620b4be477 Add separate LC_ASSERT_VT() for asserts that only apply for valid traffic 2023-10-11 20:01:39 -05:00
Cameron Gutman
574ad6e676 Reject video packets beyond our valid sequence number range for the FEC block 2023-10-11 17:32:39 -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
d457fbb487 Fix warning for fopen() in RecorderCallbacks.c 2023-10-06 23:17:25 -05:00
Cameron Gutman
7580f3f8e3 Remove _CRT_SECURE_NO_WARNINGS now that we use safe string functions everywhere 2023-10-06 22:42:25 -05:00
Cameron Gutman
1351f382aa Minor cleanups to RTSP URL parsing 2023-10-06 21:30:45 -05:00
Keane O'Kelley
24750d4b74 Fix buffer overflow in performRtspHandshake (CVE-2023-42800) 2023-10-06 21:14:30 -05:00
Keane O'Kelley
02b7742f4d Fix buffer overflow in parseUrlAddrFromRtspUrlString (CVE-2023-42799) 2023-10-06 21:14:30 -05:00
Cameron Gutman
116267a245 Fix parseSdpAttributeTo[U]Int() to avoid writing to the const input string 2023-10-06 18:12:08 -05:00
Cameron Gutman
b2497a3918 Rewrite extractVersionQuadFromString() to avoid copying the input string 2023-10-06 18:09:15 -05:00
Cameron Gutman
8b84d17c8d Replace additional unsafe string functions 2023-10-06 17:33:37 -05:00
Cameron Gutman
d055599608 Map Misc button to Guide for GFE hosts 2023-10-05 20:29:18 -05:00
Cameron Gutman
162c581754 Initialize strtokCtx to NULL for first call to strtok_r()
Apparently some strtok_r() implementations require this.
2023-09-27 01:27:12 -05:00
Cameron Gutman
1be56269a3 Fix handling of duplicate packets when OOS data was also received
It's possible for a sequence of packets seqnums like 2, 0, 1, 2 to end up hitting the fast path
again after filling in gap of OOS packets. The fast path assumes duplicate packets are caught
by the next contiguous sequence number check, but this is only true if that value is kept updated.

Since the slow path doesn't update the next contiguous sequence number, it's no longer safe to
use the fast path for the remaining packets in the frame because duplicate packets would be
mishandled.

Queuing duplicate packets violates all sorts of queue assumptions and can cause us to return
corrupt data to the decoder or attempt an FEC recovery without enough shards.
2023-09-23 12:08:16 -04:00
Cameron Gutman
7a6d12fc4e Update ENet submodule to add ENET_NO_INSTALL option 2023-09-20 20:52:28 -05:00
Cameron Gutman
c1744de069 Batch async control stream callbacks 2023-09-18 23:02:44 -05:00
Cameron Gutman
a258b7e12b Fix leak in unreachable codepath 2023-09-18 22:59:03 -05:00
Cameron Gutman
c3e9aea843 Fix non-standard forward declaration 2023-09-18 21:19:59 -05:00
Cameron Gutman
20130e210b Invoke control stream callbacks on a separate thread
Time spent processing client callbacks would contribute to increased control stream latency,
which means higher RTTs, more lengthy waits before retransmissions, and higher client-reported
network latency stats.
2023-09-17 14:49:06 -05:00
Cameron Gutman
b2528faa02 Disable GCC static analysis in CI until newer GCC is available in AppVeyor 2023-09-15 23:19:10 -05:00
Cameron Gutman
7f665babf9 Enable GCC static analysis in CI 2023-09-15 22:41:37 -05:00
Cameron Gutman
515bea6fb4 Fix GCC static analysis warnings 2023-09-15 22:03:27 -05:00
Cameron Gutman
c13f4a323f Use connected datagram sockets for audio and video
This ensures unwanted data from other sources is dropped and that our own source address doesn't change while streaming.
2023-09-12 23:29:05 -05:00
Cameron Gutman
ec6713fd80 Improve checks for runt video packets
Since we always allocate fixed size these aren't likely to be exploitable,
but we ought to fix them anyway. Worst case, we will just read some garbage
and generate corrupt video output.
2023-09-12 22:44:45 -05:00
Cameron Gutman
171858c2e7 Add CodeQL scanning 2023-09-12 21:46:46 -05:00
Cameron Gutman
315d0bbfa3 Use modern string parsing functions in SdpGenerator 2023-09-12 21:24:28 -05:00
Cameron Gutman
5a19e52921 Use modern string parsing functions in RtspParser 2023-09-12 21:20:44 -05:00
Cameron Gutman
91b4186b8a Use strtok_r()/strtok_s() instead of regular strtok() 2023-09-12 20:56:15 -05:00
Cameron Gutman
2bb026c763 Suppress connection warnings for the first sampling period 2023-08-23 21:03:40 -05:00
Cameron Gutman
dc62a6f88e Send periodic pings and FEC status messages more frequently 2023-08-19 11:39:55 -05:00