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

Definitions for the streaming protocols. More...

#include <fstream>
#include <future>
#include <queue>
#include <boost/endian/arithmetic.hpp>
#include <openssl/err.h>
#include <moonlight-common-c/src/Limelight-internal.h>
#include "rswrapper.h"
#include "config.h"
#include "display_device.h"
#include "globals.h"
#include "input.h"
#include "logging.h"
#include "network.h"
#include "platform/common.h"
#include "process.h"
#include "stream.h"
#include "sync.h"
#include "system_tray.h"
#include "thread_safe.h"
#include "utility.h"
Include dependency graph for stream.cpp:

Classes

struct  stream::audio_fec_packet_t
 
struct  stream::audio_packet_t
 
struct  stream::broadcast_ctx_t
 
struct  stream::control_encrypted_t
 
struct  stream::control_hdr_mode_t
 
struct  stream::control_header_v2
 
struct  stream::control_rumble_t
 
struct  stream::control_rumble_triggers_t
 
class  stream::control_server_t
 
struct  stream::control_set_motion_event_t
 
struct  stream::control_set_rgb_led_t
 
struct  stream::control_terminate_t
 
struct  stream::fec::fec_t
 
struct  stream::session_t
 
struct  stream::video_packet_enc_prefix_t
 
struct  stream::video_packet_raw_t
 
struct  stream::video_short_frame_header_t
 

Macros

#define IDX_ENCRYPTED   10
 
#define IDX_HDR_MODE   11
 
#define IDX_INPUT_DATA   5
 
#define IDX_INVALIDATE_REF_FRAMES   2
 
#define IDX_LOSS_STATS   3
 
#define IDX_PERIODIC_PING   8
 
#define IDX_REQUEST_IDR_FRAME   9
 
#define IDX_RUMBLE_DATA   6
 
#define IDX_RUMBLE_TRIGGER_DATA   12
 
#define IDX_SET_MOTION_EVENT   13
 
#define IDX_SET_RGB_LED   14
 
#define IDX_START_A   0
 
#define IDX_START_B   1
 
#define IDX_TERMINATION   7
 

Typedefs

using stream::audio_aes_t = std::array<char, round_to_pkcs7_padded(MAX_AUDIO_PACKET_SIZE)>
 
using stream::av_session_id_t = std::variant<asio::ip::address, std::string>
 
typedef struct stream::control_encrypted_tstream::control_encrypted_p
 
using stream::message_queue_queue_t = std::shared_ptr<safe::queue_t<std::tuple<socket_e, av_session_id_t, message_queue_t>>>
 
using stream::message_queue_t = std::shared_ptr<safe::queue_t<std::pair<udp::endpoint, std::string>>>
 
using stream::fec::rs_t
 

Enumerations

enum class  stream::socket_e : int { video , audio }
 

Functions

std::shared_ptr< session_tstream::session::alloc (config_t &config, rtsp_stream::launch_session_t &launch_session)
 
void stream::audioBroadcastThread (udp::socket &sock)
 
void stream::audioThread (session_t *session)
 
std::vector< uint8_t > stream::concat_and_insert (uint64_t insert_size, uint64_t slice_size, const std::string_view &data1, const std::string_view &data2)
 Combines two buffers and inserts new buffers at each slice boundary of the result.
 
void stream::controlBroadcastThread (control_server_t *server)
 
void stream::end_broadcast (broadcast_ctx_t &ctx)
 
void stream::session::join (session_t &session)
 
int stream::recv_ping (session_t *session, decltype(broadcast)::ptr_t ref, socket_e type, std::string_view expected_payload, udp::endpoint &peer, std::chrono::milliseconds timeout)
 
void stream::recvThread (broadcast_ctx_t &ctx)
 
std::vector< uint8_t > stream::replace (const std::string_view &original, const std::string_view &old, const std::string_view &_new)
 
constexpr std::size_t stream::round_to_pkcs7_padded (std::size_t size)
 
int stream::send_feedback_msg (session_t *session, platf::gamepad_feedback_msg_t &msg)
 Pass gamepad feedback data back to the client.
 
int stream::send_hdr_mode (session_t *session, video::hdr_info_t hdr_info)
 
int stream::session::start (session_t &session, const std::string &addr_string)
 
int stream::start_broadcast (broadcast_ctx_t &ctx)
 
state_e stream::session::state (session_t &session)
 
void stream::session::stop (session_t &session)
 
void stream::videoBroadcastThread (udp::socket &sock)
 
void stream::videoThread (session_t *session)
 

Variables

constexpr std::size_t stream::MAX_AUDIO_PACKET_SIZE = 1400
 
std::atomic_uint stream::session::running_sessions
 

Detailed Description

Definitions for the streaming protocols.

Typedef Documentation

◆ rs_t

Initial value:
util::safe_ptr<reed_solomon, [](reed_solomon *rs) {
reed_solomon_release_fn (rs);
}>
Definition utility.h:530

Enumeration Type Documentation

◆ socket_e

enum class stream::socket_e : int
strong
Enumerator
video 

Video.

audio 

Audio.

Function Documentation

◆ concat_and_insert()

std::vector< uint8_t > stream::concat_and_insert ( uint64_t insert_size,
uint64_t slice_size,
const std::string_view & data1,
const std::string_view & data2 )

Combines two buffers and inserts new buffers at each slice boundary of the result.

Parameters
insert_sizeThe number of bytes to insert.
slice_sizeThe number of bytes between insertions.
data1The first data buffer.
data2The second data buffer.

◆ send_feedback_msg()

int stream::send_feedback_msg ( session_t * session,
platf::gamepad_feedback_msg_t & msg )

Pass gamepad feedback data back to the client.

Parameters
sessionThe session object.
msgThe message to pass.
Returns
0 on success.