Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <array>
9#include <atomic>
10#include <cstddef>
11#include <cstdint>
12#include <string>
13
14// local includes
15#include "crypto.h"
16#include "thread_safe.h"
17
18namespace rtsp_stream {
19 constexpr auto RTSP_SETUP_PORT = 21;
20
21#pragma pack(push, 1)
22
27 // We set the MSB in encrypted RTSP messages to allow format-agnostic
28 // parsing code to be able to tell encrypted from plaintext messages.
29 static constexpr std::uint32_t ENCRYPTED_MESSAGE_TYPE_BIT = 0x80000000;
30
36 uint8_t *payload() {
37 return (uint8_t *) (this + 1);
38 }
39
48
57
58 // This field is the length of the payload + ENCRYPTED_MESSAGE_TYPE_BIT in big-endian
59 std::uint32_t typeAndLength;
60
61 // This field is the number used to initialize the bottom 4 bytes of the AES IV in big-endian
62 std::uint32_t sequenceNumber;
63
64 // This field is the AES GCM authentication tag
65 std::array<std::uint8_t, 16> tag;
66 };
67
68#pragma pack(pop)
69
70 static_assert(sizeof(encrypted_rtsp_header_t) == 24);
71 static_assert(offsetof(encrypted_rtsp_header_t, tag) == 8);
72
82 std::string codec_offered;
83 };
84
85 uint32_t id;
86
89
90 std::string av_ping_payload;
92
94 std::string unique_id;
95 int width;
96 int height;
97 int fps;
98 int gcmap;
99 int appid;
101 std::string surround_params;
105 std::string client_name;
106
107 std::optional<crypto::cipher::gcm_t> rtsp_cipher;
108 std::string rtsp_url_scheme;
110 std::string client_cert;
111 };
112
118 void launch_session_raise(std::shared_ptr<launch_session_t> launch_session);
119
124 void launch_session_clear(uint32_t launch_session_id);
125
130 int session_count();
131
135 void terminate_sessions();
141 void terminate_sessions_by_cert(std::string_view cert);
142
146 void start();
147} // namespace rtsp_stream
Declarations for cryptography functions.
std::vector< std::uint8_t > aes_t
Byte buffer containing AES key material.
Definition crypto.h:43
void terminate_sessions()
Terminates all running streaming sessions.
Definition rtsp.cpp:711
void launch_session_clear(uint32_t launch_session_id)
Clear state for the specified launch session.
Definition rtsp.cpp:700
int session_count()
Get the number of active sessions.
Definition rtsp.cpp:704
void terminate_sessions_by_cert(std::string_view cert)
Terminate active sessions associated with a client certificate.
Definition rtsp.cpp:719
void launch_session_raise(std::shared_ptr< launch_session_t > launch_session)
Queue a launch session until the RTSP client connects.
Definition rtsp.cpp:696
void start()
Runs the RTSP server loop.
Definition rtsp.cpp:1402
constexpr auto RTSP_SETUP_PORT
GameStream base-port offset used for the RTSP setup listener.
Definition rtsp.h:19
Encrypted RTSP message header used by GameStream.
Definition rtsp.h:26
bool is_encrypted() const
Inspect the encrypted-message flag without modifying the wire header.
Definition rtsp.h:54
uint8_t * payload()
Return a pointer to the protocol payload following the packet header.
Definition rtsp.h:36
std::uint32_t payload_length() const
Decode the RTSP interleaved-frame payload length.
Definition rtsp.h:45
static constexpr std::uint32_t ENCRYPTED_MESSAGE_TYPE_BIT
Protocol or platform constant for encrypted message type bit.
Definition rtsp.h:29
std::uint32_t sequenceNumber
Sequence number.
Definition rtsp.h:62
std::array< std::uint8_t, 16 > tag
Authentication tag appended to the encrypted payload.
Definition rtsp.h:65
std::uint32_t typeAndLength
Type and length.
Definition rtsp.h:59
Audio-related capabilities and codec choice exchanged during RTSP setup.
Definition rtsp.h:80
bool continuous_audio
Whether audio packets continue during silence.
Definition rtsp.h:81
std::string codec_offered
Dolby codec offered to the client, or empty when using Opus.
Definition rtsp.h:82
RTSP launch session state shared with stream setup.
Definition rtsp.h:76
bool host_audio
Whether host audio should be played locally.
Definition rtsp.h:93
std::string av_ping_payload
AV ping payload.
Definition rtsp.h:90
int gcmap
Game controller mapping requested by the client.
Definition rtsp.h:98
crypto::aes_t gcm_key
AES-GCM key negotiated for encrypted RTSP messages.
Definition rtsp.h:87
std::string client_name
Friendly client name from initial pairing.
Definition rtsp.h:105
int appid
Application ID requested for launch or resume.
Definition rtsp.h:99
bool enable_hdr
Whether HDR streaming is requested.
Definition rtsp.h:103
std::string unique_id
Moonlight client unique identifier for this launch request.
Definition rtsp.h:94
int fps
Requested video frame rate.
Definition rtsp.h:97
std::optional< crypto::cipher::gcm_t > rtsp_cipher
AES-GCM cipher used once encrypted RTSP is negotiated.
Definition rtsp.h:107
int height
Frame or display height in pixels.
Definition rtsp.h:96
uint32_t rtsp_iv_counter
Counter value mixed into encrypted RTSP IVs.
Definition rtsp.h:109
std::string client_cert
PEM certificate for the paired Moonlight client.
Definition rtsp.h:110
std::string surround_params
Client-provided surround-sound layout parameters.
Definition rtsp.h:101
uint32_t control_connect_data
Client-provided token used when connecting the control channel.
Definition rtsp.h:91
std::string rtsp_url_scheme
URL scheme selected by the RTSP SETUP flow.
Definition rtsp.h:108
int width
Frame or display width in pixels.
Definition rtsp.h:95
int surround_info
Encoded GameStream surround-sound capability flags.
Definition rtsp.h:100
uint32_t id
RTSP launch-session identifier assigned before stream startup.
Definition rtsp.h:85
audio_negotiation_t audio_negotiation
Audio stream negotiation state.
Definition rtsp.h:102
bool enable_sops
Whether sequence output protection is requested.
Definition rtsp.h:104
crypto::aes_t iv
Initial RTSP AES-GCM IV supplied by the client.
Definition rtsp.h:88
Declarations for thread-safe data structures.
auto big(T x)
Convert a value to or from big-endian byte order.
Definition utility.h:1810