Commit Graph

73 Commits

Author SHA1 Message Date
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
dff1690fe1 Validate channel count before parsing Opus param string 2024-10-15 23:00:16 -05:00
ns6089
0fa805d973 Guard against rtsp response with no content 2024-10-15 22:48:59 -05:00
ns6089
907110c4ec Support YUV 4:4:4 formats 2024-06-06 02:31:32 -05:00
Cameron Gutman
cbd0ec1b25 Fix signed/unsigned mismatch warnings 2024-02-03 15:20:56 -06:00
Cameron Gutman
7ab34e709a Improve encrypted RTSP message validation 2024-02-03 14:39:12 -06:00
Cameron Gutman
955f13a18d Implement RTSP encryption support 2024-02-02 22:55:53 -06:00
Cameron Gutman
b6bbb4fb26 Add new RTSP encryption flags 2024-01-14 12:08:37 -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
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
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
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
8b84d17c8d Replace additional unsafe string functions 2023-10-06 17:33:37 -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
91b4186b8a Use strtok_r()/strtok_s() instead of regular strtok() 2023-09-12 20:56:15 -05:00
Cameron Gutman
9ad56cdd8e Move serverCodecModeSupport into SERVER_INFORMATION struct 2023-07-02 23:54:04 -05:00
Cameron Gutman
59a506c15a Only select 10-bit format if also compatible with client 2023-07-02 23:32:04 -05:00
Cameron Gutman
1125dc3dba Replace enableHdr option with directly receiving ServerCodecModeSupport value from XML 2023-07-02 23:28:10 -05:00
Cameron Gutman
e36bde4acc Implement AV1 codec support
This has a breaking change to StreamConfiguration that requires client updates.
2023-07-02 22:16:20 -05:00
Cameron Gutman
9bf09d681e Plumb Sunshine feature flags SDP attribute for protocol extensions 2023-06-18 15:52:51 -05:00
Cameron Gutman
d3cb8131d1 Revert "Send TCP FIN after completion of our RTSP request"
Existing servers already know how to parse our messages without this,
so we just risk breaking things with middleboxes that don't do half-closed
connections properly. We'll handle this better with encrypted RTSP.

This reverts commit 95e3e26d12.
2023-02-20 16:58:21 -06:00
Cameron Gutman
95e3e26d12 Send TCP FIN after completion of our RTSP request
This allows servers to read until a FIN, just like we do on the client.
2023-02-13 21:47:22 -06:00
Cameron Gutman
dc186082a7 Add protocol extension for multi-client-compatible ping support 2023-02-12 01:23:25 -06:00
Cameron Gutman
50c0a51b10 Improve high quality audio support
High quality audio now works on IPv6 and remote connections
2022-11-04 21:44:07 -05:00
Cameron Gutman
e951302927 Disable RFI when streaming from a server that doesn't support it 2022-10-06 20:01:40 -05:00
Cameron Gutman
bc458b8848 Use 15 second timeout for RTSP replies
GFE has an internal 10 second timeout for bringing up the streamer,
so we can end up timing out right as GFE is trying to reply to us.
2022-02-06 20:59:18 -06:00
Cameron Gutman
3b9d8a3176 Assert that the port numbers are set prior to being used 2021-07-02 01:44:11 -05:00
Cameron Gutman
cdda221d64 Log the parsed ports 2021-07-02 01:30:33 -05:00
Cameron Gutman
0cd3fcf1be Fix off-by-one in port number validation 2021-07-02 01:16:20 -05:00
Cameron Gutman
46887c0447 Parse the ports from RTSP SETUP instead of RTSP DESCRIBE
RTSP SETUP is better because it can provide multiple IP+port candidates
2021-07-02 00:28:48 -05:00
Cameron Gutman
56ccd99cc7 Dynamically determine audio, video, and control ports from RTSP DESCRIBE response 2021-07-01 23:45:33 -05:00
Cameron Gutman
1b642fec73 Fix control flow bugs in poll() error paths 2021-07-01 22:20:09 -05:00
Cameron Gutman
c00f4e15ae Use poll() instead of SO_RCVTIMEO for RTSP timeout support
poll() is more portable than SO_RCVTIMEO
2021-07-01 22:10:46 -05:00
Cameron Gutman
8f371343cd Consolidate includes 2021-04-29 17:22:15 -05:00
Cameron Gutman
da68e64d9b Fix various MSVC warnings 2021-04-29 17:21:12 -05:00
Cameron Gutman
3ae03998a2 Add retry logic for RTSP handshake connection refused error
This can happen due to a race condition between GFE completing the launch request and starting to listen on TCP 48010
2021-04-28 17:08:27 -05:00
Cameron Gutman
068f7aa9d9 Allow connection interruption during the RTSP handshake 2021-04-28 17:06:04 -05:00
Cameron Gutman
db81f1e512 Add support for audio stream encryption
Clients must opt-in using the new encryptionFlags field
2021-04-22 00:20:17 -05:00
Cameron Gutman
cb11b76682 Fix GCC/Clang warning 2021-04-09 12:20:02 -05:00
Cameron Gutman
12f0f3d6d7 Add encrypted control stream support for GFE 3.22
Receive-side not yet fully working
2021-04-09 10:25:24 -05:00
Cameron Gutman
d0c3513504 Reorder audio initialization and RTSP handshake to avoid RTSP PLAY failure on GFE 3.22 2021-04-09 08:39:28 -05:00
Cameron Gutman
9b194cc700 Adjust RTSP requests to conform to GFE 3.22 changes 2021-04-09 07:46:14 -05:00
Cameron Gutman
5f9f7ce407 Code cleanup: use stdbool.h 2020-11-30 20:38:13 -06:00
Cameron Gutman
413ea9bc8e Minor RTSP code cleanup 2020-05-01 18:32:26 -07:00
Cameron Gutman
fcabfc37ad Dynamically allocate session ID string 2020-04-29 20:12:19 -07:00
Cameron Gutman
7d0458a16b Dynamically allocate the RTSP response buffer 2020-04-29 19:58:50 -07:00