Sunshine master
Self-hosted game stream host for Moonlight.
rtsp.cpp File Reference

Definitions for RTSP streaming. More...

#include <moonlight-common-c/src/Limelight-internal.h>
#include <moonlight-common-c/src/Rtsp.h>
#include <array>
#include <cctype>
#include <format>
#include <set>
#include <unordered_map>
#include <utility>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include "config.h"
#include "globals.h"
#include "input.h"
#include "logging.h"
#include "network.h"
#include "rtsp.h"
#include "stream.h"
#include "sync.h"
#include "video.h"
Include dependency graph for rtsp.cpp:

Classes

struct  rtsp_stream::encrypted_rtsp_header_t
 Encrypted RTSP message header used by GameStream. More...
 
class  rtsp_stream::rtsp_server_t
 RTSP listener that matches incoming clients to pending launch sessions. More...
 
class  rtsp_stream::socket_t
 RTSP client socket state and receive buffer parser. More...
 

Typedefs

using rtsp_stream::cmd_func_t = std::function<void(rtsp_server_t *server, tcp::socket &, launch_session_t &, msg_t &&)>
 RTSP command handler signature used by the server dispatch table.
 
using rtsp_stream::msg_t = util::safe_ptr<RTSP_MESSAGE, free_msg>
 Owning pointer for an RTSP message allocated by moonlight-common-c.
 

Functions

void rtsp_stream::cmd_announce (rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req)
 Handle RTSP ANNOUNCE requests from the client.
 
void rtsp_stream::cmd_describe (rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req)
 Handle RTSP DESCRIBE requests.
 
void rtsp_stream::cmd_not_found (tcp::socket &sock, launch_session_t &, msg_t &&req)
 Send the RTSP response used for unsupported commands.
 
void rtsp_stream::cmd_option (rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req)
 Handle RTSP OPTIONS requests.
 
void rtsp_stream::cmd_play (rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req)
 Handle RTSP PLAY requests and start streaming.
 
void rtsp_stream::cmd_setup (rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req)
 Handle RTSP SETUP requests and prepare transport state.
 
void rtsp_stream::free_msg (PRTSP_MESSAGE msg)
 Release msg resources.
 
void rtsp_stream::launch_session_clear (uint32_t launch_session_id)
 Clear state for the specified launch session.
 
void rtsp_stream::launch_session_raise (std::shared_ptr< launch_session_t > launch_session)
 Queue a launch session until the RTSP client connects.
 
void rtsp_stream::print_msg (PRTSP_MESSAGE msg)
 Write msg details to the log.
 
void rtsp_stream::respond (tcp::socket &sock, launch_session_t &session, msg_t &resp)
 Send the protocol response for the current request.
 
void rtsp_stream::respond (tcp::socket &sock, launch_session_t &session, POPTION_ITEM options, int statuscode, const char *status_msg, int seqn, const std::string_view &payload)
 Send the protocol response for the current request.
 
int rtsp_stream::send (tcp::socket &sock, const std::string_view &sv)
 Send the serialized response over the active socket.
 
int rtsp_stream::session_count ()
 Get the number of active sessions.
 
void rtsp_stream::start ()
 Runs the RTSP server loop.
 
void rtsp_stream::terminate_sessions ()
 Terminates all running streaming sessions.
 
void rtsp_stream::terminate_sessions_by_cert (std::string_view cert)
 Terminate active sessions associated with a client certificate.
 

Variables

rtsp_server_t rtsp_stream::server {}
 Singleton RTSP server used by GameStream launch sessions.
 

Detailed Description

Definitions for RTSP streaming.

Function Documentation

◆ cmd_announce()

void rtsp_stream::cmd_announce ( rtsp_server_t * server,
tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Handle RTSP ANNOUNCE requests from the client.

Parameters
serverRTSP server instance handling the request.
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
reqParsed RTSP request being handled.

◆ cmd_describe()

void rtsp_stream::cmd_describe ( rtsp_server_t * server,
tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Handle RTSP DESCRIBE requests.

Parameters
serverRTSP server instance.
sockClient socket.
sessionLaunch session.
reqRTSP request message.

GFE advertises incorrect mapping for normal quality configurations, as a result, Moonlight rotates all channels from index '3' to the right To work around this, rotate channels to the left from index '3'

◆ cmd_not_found()

void rtsp_stream::cmd_not_found ( tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Send the RTSP response used for unsupported commands.

Handle an unsupported RTSP command.

Parameters
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
reqParsed RTSP request being handled.

◆ cmd_option()

void rtsp_stream::cmd_option ( rtsp_server_t * server,
tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Handle RTSP OPTIONS requests.

Parameters
serverRTSP server instance handling the request.
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
reqParsed RTSP request being handled.

◆ cmd_play()

void rtsp_stream::cmd_play ( rtsp_server_t * server,
tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Handle RTSP PLAY requests and start streaming.

Parameters
serverRTSP server instance handling the request.
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
reqParsed RTSP request being handled.

◆ cmd_setup()

void rtsp_stream::cmd_setup ( rtsp_server_t * server,
tcp::socket & sock,
launch_session_t & session,
msg_t && req )

Handle RTSP SETUP requests and prepare transport state.

Parameters
serverRTSP server instance handling the request.
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
reqParsed RTSP request being handled.

◆ free_msg()

void rtsp_stream::free_msg ( PRTSP_MESSAGE msg)

Release msg resources.

Parameters
msgRaw RTSP message buffer being parsed or encrypted.

◆ launch_session_clear()

void rtsp_stream::launch_session_clear ( uint32_t launch_session_id)

Clear state for the specified launch session.

Parameters
launch_session_idThe ID of the session to clear.

◆ launch_session_raise()

void rtsp_stream::launch_session_raise ( std::shared_ptr< launch_session_t > launch_session)

Queue a launch session until the RTSP client connects.

Parameters
launch_sessionSession state prepared by the GameStream launch handler.

◆ print_msg()

void rtsp_stream::print_msg ( PRTSP_MESSAGE msg)

Write msg details to the log.

Parameters
msgRaw RTSP message buffer being parsed or encrypted.

◆ respond() [1/2]

void rtsp_stream::respond ( tcp::socket & sock,
launch_session_t & session,
msg_t & resp )

Send the protocol response for the current request.

Parameters
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
respRTSP response string to send to the client.

◆ respond() [2/2]

void rtsp_stream::respond ( tcp::socket & sock,
launch_session_t & session,
POPTION_ITEM options,
int statuscode,
const char * status_msg,
int seqn,
const std::string_view & payload )

Send the protocol response for the current request.

Parameters
sockSocket used to read or write the protocol message.
sessionActive streaming or pairing session for the request.
optionsRequest options or socket options to apply.
statuscodeRTSP status code to send in the response.
status_msgStatus msg.
seqnRTSP CSeq value associated with the request.
payloadOptional payload body to include in the response.

◆ send()

int rtsp_stream::send ( tcp::socket & sock,
const std::string_view & sv )

Send the serialized response over the active socket.

Parameters
sockSocket used to read or write the protocol message.
svString view containing the text to inspect.
Returns
Network operation status.

◆ session_count()

int rtsp_stream::session_count ( )

Get the number of active sessions.

Returns
Count of active sessions.

◆ terminate_sessions_by_cert()

void rtsp_stream::terminate_sessions_by_cert ( std::string_view cert)

Terminate active sessions associated with a client certificate.

Parameters
certCertificate data or object used by the operation.