Sunshine master
Self-hosted game stream host for Moonlight.
common.h File Reference

Declarations for common platform specific utilities. More...

#include <bitset>
#include <filesystem>
#include <functional>
#include <mutex>
#include <string>
#include <boost/core/noncopyable.hpp>
#include "src/config.h"
#include "src/logging.h"
#include "src/thread_safe.h"
#include "src/utility.h"
#include "src/video_colorspace.h"
#include <moonlight-common-c/src/Limelight.h>
Include dependency graph for common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  platf::audio_control_t
 Platform audio controller that manages sinks and microphone capture. More...
 
struct  platf::avcodec_encode_device_t
 AVCodec-backed encode device and frame state. More...
 
struct  platf::batched_send_info_t
 Buffers and native metadata for one batched send operation. More...
 
struct  platf::buffer_descriptor_t
 Platform buffer pointer and size for batched socket sends. More...
 
class  platf::deinit_t
 RAII helper that runs shutdown cleanup when destroyed. More...
 
class  platf::display_t
 Abstract display capture backend used by the streaming pipeline. More...
 
struct  platf::encode_device_t
 Base interface for hardware or software frame conversion. More...
 
struct  platf::gamepad_arrival_t
 Capabilities reported when a controller is connected. More...
 
struct  platf::gamepad_battery_t
 Battery state reported by a virtual gamepad. More...
 
struct  platf::gamepad_feedback_msg_t
 Feedback command sent from Sunshine to a virtual gamepad. More...
 
struct  platf::gamepad_id_t
 Global and client-relative identifiers for a virtual gamepad. More...
 
struct  platf::gamepad_motion_t
 Accelerometer or gyroscope sample from a controller. More...
 
struct  platf::gamepad_state_t
 Button and axis state received for a virtual gamepad. More...
 
struct  platf::gamepad_touch_t
 Touchpad contact data reported by a controller. More...
 
struct  platf::high_precision_timer
 Platform timer object used for precise frame pacing. More...
 
struct  platf::img_t
 Captured frame buffer shared between capture and encode stages. More...
 
class  platf::mic_t
 Audio capture source used by the streaming pipeline. More...
 
struct  platf::sink_t::null_t
 Optional virtual sink names for each supported channel layout. More...
 
struct  platf::nvenc_encode_device_t
 NVENC-backed encode device state. More...
 
struct  platf::pen_input_t
 Pen tablet event data from the client. More...
 
struct  platf::send_info_t
 Destination address and payload data for one UDP send. More...
 
struct  platf::sink_t
 Host and virtual audio sink names for audio routing. More...
 
struct  platf::supported_gamepad_t
 Gamepad type exposed to clients and why it may be disabled. More...
 
struct  platf::touch_input_t
 Absolute touchscreen event data from the client. More...
 
struct  platf::touch_port_t
 Touchscreen coordinate bounds used to scale absolute input. More...
 

Namespaces

namespace  nvenc
 Standalone NVENC encoder.
 

Typedefs

typedef uint32_t platf::platform_caps::caps_t
 Bitset containing platform capability flags.
 
typedef deinit_t platf::client_input_t
 Per-client input context allocated by a platform backend.
 
typedef basic_environment< char > boost::process::v1::environment
 Map of environment variable names to values.
 
using platf::feedback_queue_t = safe::mail_raw_t::queue_t<gamepad_feedback_msg_t>
 Queue used to deliver controller feedback commands to the platform backend.
 
using platf::input_t = util::safe_ptr<void, freeInput>
 Owning pointer for a platform input backend.
 

Enumerations

enum class  platf::capture_e : int {
  ok , reinit , timeout , interrupted ,
  error
}
 Enumerates supported capture options. More...
 
enum class  platf::gamepad_feedback_e {
  rumble , rumble_triggers , set_motion_event_state , set_rgb_led ,
  set_adaptive_triggers
}
 Enumerates supported gamepad feedback options. More...
 
enum class  platf::mem_type_e {
  system , vaapi , dxgi , cuda ,
  videotoolbox , vulkan , unknown
}
 Enumerates supported mem type options. More...
 
enum class  platf::pix_fmt_e {
  yuv420p , yuv420p10 , nv12 , p010 ,
  ayuv , yuv444p16 , yuv444p , y410 ,
  unknown
}
 Enumerates supported pix fmt options. More...
 
enum class  platf::qos_data_type_e : int { audio , video }
 Identifies traffic classes used for socket QoS tagging. More...
 
enum  platf::speaker::speaker_e {
  platf::speaker::FRONT_LEFT , platf::speaker::FRONT_RIGHT , platf::speaker::FRONT_CENTER , platf::speaker::LOW_FREQUENCY ,
  platf::speaker::BACK_LEFT , platf::speaker::BACK_RIGHT , platf::speaker::SIDE_LEFT , platf::speaker::SIDE_RIGHT ,
  platf::speaker::MAX_SPEAKERS
}
 Enumerates supported speaker options. More...
 
enum class  platf::thread_priority_e : int { low , normal , high , critical }
 Enumerates supported thread priority options. More...
 

Functions

void platf::abs_mouse (input_t &input, const touch_port_t &touch_port, float x, float y)
 Move the pointer to an absolute client-provided touch coordinate.
 
void platf::adjust_thread_priority (thread_priority_e priority)
 Apply the requested scheduling priority to the current thread.
 
int platf::alloc_gamepad (input_t &input, const gamepad_id_t &id, const gamepad_arrival_t &metadata, feedback_queue_t feedback_queue)
 Create a new virtual gamepad.
 
std::unique_ptr< client_input_tplatf::allocate_client_input_context (input_t &input)
 Allocate a context to store per-client input data.
 
std::filesystem::path platf::appdata ()
 Performs migration if necessary, then returns the appdata directory.
 
std::unique_ptr< audio_control_tplatf::audio_control ()
 Create the platform audio controller.
 
void platf::button_mouse (input_t &input, int button, bool release)
 Press or release a virtual mouse button.
 
std::unique_ptr< high_precision_timerplatf::create_high_precision_timer ()
 Create platform-specific timer capable of high-precision sleep.
 
std::shared_ptr< display_tplatf::display (mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
 Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monitor that's compatible you can find If you require to use this parameter in a separate thread, make a copy of it.
 
std::vector< std::string > platf::display_names (mem_type_e hwdevice_type)
 List display names accepted by the selected capture backend.
 
void platf::drop_elevated_privileges (bool all_caps)
 Drop elevated privileges (e.g. system admin/nice etc.)
 
void platf::enable_mouse_keys ()
 Enable or disable X11 mouse keys for the current session.
 
std::unique_ptr< deinit_tplatf::enable_socket_qos (uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging)
 Enable QoS on the given socket for traffic to the specified destination.
 
void platf::free_gamepad (input_t &input, int nr)
 Release gamepad resources.
 
void platf::freeInput (void *)
 Release a platform input backend created by input().
 
std::string_view platf::from_pix_fmt (pix_fmt_e pix_fmt)
 Convert a Sunshine pixel format enum to its string name.
 
std::string platf::from_sockaddr (const sockaddr *const)
 Convert a socket address to a printable IP address.
 
std::pair< std::uint16_t, std::string > platf::from_sockaddr_ex (const sockaddr *const)
 Convert a socket address to a port and printable IP address.
 
void platf::gamepad_battery (input_t &input, const gamepad_battery_t &battery)
 Send a gamepad battery event to the OS.
 
void platf::gamepad_motion (input_t &input, const gamepad_motion_t &motion)
 Send a gamepad motion event to the OS.
 
void platf::gamepad_touch (input_t &input, const gamepad_touch_t &touch)
 Send a gamepad touch event to the OS.
 
void platf::gamepad_update (input_t &input, int nr, const gamepad_state_t &gamepad_state)
 Submit updated Sunshine gamepad state to the virtual device.
 
platform_caps::caps_t platf::get_capabilities ()
 Get the supported platform capabilities to advertise to the client.
 
std::string platf::get_host_name ()
 Returns the current computer name in UTF-8.
 
std::string platf::get_mac_address (const std::string_view &address)
 Return the hardware MAC address associated with a network address.
 
util::point_t platf::get_mouse_loc (input_t &input)
 Get the current mouse position on screen.
 
bool platf::has_elevated_privileges (bool all_caps)
 Check is the current process is running with elevated privileges (e.g. system admin/etc.)
 
void platf::hscroll (input_t &input, int distance)
 Apply a horizontal scroll event to the virtual mouse.
 
std::unique_ptr< deinit_tplatf::init ()
 Initialize the platform-specific high precision timer.
 
input_t platf::input ()
 Create the platform input backend for a stream.
 
void platf::keyboard_update (input_t &input, uint16_t modcode, bool release, uint8_t flags)
 Press or release a virtual keyboard key.
 
void platf::move_mouse (input_t &input, int deltaX, int deltaY)
 Move mouse using the backend coordinate system.
 
bool platf::needs_encoder_reenumeration ()
 Check if GPUs/drivers have changed since the last call to this function.
 
void platf::open_url (const std::string &url)
 Open a url in the default web browser.
 
void platf::pen_update (client_input_t *input, const touch_port_t &touch_port, const pen_input_t &pen)
 Send a pen event to the OS.
 
bool platf::process_group_running (std::uintptr_t native_handle)
 Check if a process group still has running children.
 
bool platf::request_process_group_exit (std::uintptr_t native_handle)
 Attempt to gracefully terminate a process group.
 
std::string platf::resolve_render_device ()
 Resolves the render device path to use for hardware encoding.
 
void platf::restart ()
 Restart the Sunshine process through the platform launcher.
 
boost::process::v1::child platf::run_command (bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const boost::process::v1::environment &env, FILE *file, std::error_code &ec, boost::process::v1::group *group)
 Launch a configured preparation or application command.
 
void platf::scroll (input_t &input, int distance)
 Apply a vertical scroll event to the virtual mouse.
 
bool platf::send (send_info_t &send_info)
 Send the serialized response over the active socket.
 
bool platf::send_batch (batched_send_info_t &send_info)
 Send multiple fixed-size UDP payload blocks using the platform backend.
 
void platf::set_thread_name (const std::string &name)
 Name the current thread for use with development tools.
 
std::unique_ptr< deinit_tplatf::publish::start ()
 Main entry point for publication of our service on macOS.
 
void platf::streaming_will_start ()
 Apply Linux platform state before streaming starts.
 
void platf::streaming_will_stop ()
 Restore Linux platform state after streaming stops.
 
std::vector< supported_gamepad_t > & platf::supported_gamepads (input_t *input)
 Gets the supported gamepads for this platform backend.
 
void platf::touch_update (client_input_t *input, const touch_port_t &touch_port, const touch_input_t &touch)
 Send a touch event to the OS.
 
void platf::unicode (input_t &input, char *utf8, int size)
 Submit UTF-8 text input to the keyboard backend.
 

Variables

constexpr std::uint32_t platf::A = 0x1000
 Moonlight gamepad button mask bit for A.
 
constexpr std::uint32_t platf::B = 0x2000
 Moonlight gamepad button mask bit for B.
 
constexpr std::uint32_t platf::BACK = 0x0020
 Moonlight gamepad button mask bit for Back.
 
constexpr caps_t platf::platform_caps::controller_touch = 0x02
 Capability bit indicating controller touchpad support.
 
constexpr std::uint32_t platf::DPAD_DOWN = 0x0002
 Moonlight gamepad button mask bit for D-pad down.
 
constexpr std::uint32_t platf::DPAD_LEFT = 0x0004
 Moonlight gamepad button mask bit for D-pad left.
 
constexpr std::uint32_t platf::DPAD_RIGHT = 0x0008
 Moonlight gamepad button mask bit for D-pad right.
 
constexpr std::uint32_t platf::DPAD_UP = 0x0001
 Moonlight gamepad button mask bit for D-pad up.
 
constexpr std::uint32_t platf::HOME = 0x0400
 Moonlight gamepad button mask bit for Home.
 
constexpr std::uint32_t platf::LEFT_BUTTON = 0x0100
 Moonlight gamepad button mask bit for left shoulder.
 
constexpr std::uint32_t platf::LEFT_STICK = 0x0040
 Moonlight gamepad button mask bit for left stick press.
 
constexpr std::uint8_t platf::speaker::map_stereo []
 Moonlight speaker order for stereo audio.
 
constexpr std::uint8_t platf::speaker::map_surround51 []
 Moonlight speaker order for 5.1 surround audio.
 
constexpr std::uint8_t platf::speaker::map_surround71 []
 Moonlight speaker order for 7.1 surround audio.
 
constexpr auto platf::MAX_GAMEPADS = 16
 Maximum number of simultaneously tracked gamepads.
 
constexpr std::uint32_t platf::MISC_BUTTON = 0x200000
 Moonlight gamepad button mask bit for the miscellaneous button.
 
constexpr std::uint32_t platf::PADDLE1 = 0x010000
 Moonlight gamepad button mask bit for paddle 1.
 
constexpr std::uint32_t platf::PADDLE2 = 0x020000
 Moonlight gamepad button mask bit for paddle 2.
 
constexpr std::uint32_t platf::PADDLE3 = 0x040000
 Moonlight gamepad button mask bit for paddle 3.
 
constexpr std::uint32_t platf::PADDLE4 = 0x080000
 Moonlight gamepad button mask bit for paddle 4.
 
constexpr caps_t platf::platform_caps::pen_touch = 0x01
 Capability bit indicating native pen and touch support.
 
constexpr std::uint32_t platf::RIGHT_BUTTON = 0x0200
 Moonlight gamepad button mask bit for right shoulder.
 
constexpr std::uint32_t platf::RIGHT_STICK = 0x0080
 Moonlight gamepad button mask bit for right stick press.
 
constexpr auto platf::SERVICE_NAME = "Sunshine"
 mDNS service instance name advertised for GameStream discovery.
 
constexpr auto platf::SERVICE_TYPE = "_nvstream._tcp"
 mDNS service type advertised for GameStream discovery.
 
constexpr std::uint32_t platf::START = 0x0010
 Moonlight gamepad button mask bit for Start.
 
constexpr std::uint32_t platf::TOUCHPAD_BUTTON = 0x100000
 Moonlight gamepad button mask bit for touchpad click.
 
constexpr std::uint32_t platf::X = 0x4000
 Moonlight gamepad button mask bit for X.
 
constexpr std::uint32_t platf::Y = 0x8000
 Moonlight gamepad button mask bit for Y.
 

Detailed Description

Declarations for common platform specific utilities.

Enumeration Type Documentation

◆ capture_e

enum class platf::capture_e : int
strong

Enumerates supported capture options.

Enumerator
ok 

Success.

reinit 

Need to reinitialize.

timeout 

Timeout.

interrupted 

Capture was interrupted.

error 

Error.

◆ gamepad_feedback_e

enum class platf::gamepad_feedback_e
strong

Enumerates supported gamepad feedback options.

Enumerator
rumble 

Rumble.

rumble_triggers 

Rumble triggers.

set_motion_event_state 

Set motion event state.

set_rgb_led 

Set RGB LED.

set_adaptive_triggers 

Set adaptive triggers.

◆ mem_type_e

enum class platf::mem_type_e
strong

Enumerates supported mem type options.

Enumerator
system 

System memory.

vaapi 

VAAPI.

dxgi 

DXGI.

cuda 

CUDA.

videotoolbox 

VideoToolbox.

vulkan 

Vulkan.

unknown 

Unknown.

◆ pix_fmt_e

enum class platf::pix_fmt_e
strong

Enumerates supported pix fmt options.

Enumerator
yuv420p 

YUV 4:2:0.

yuv420p10 

YUV 4:2:0 10-bit.

nv12 

NV12.

p010 

P010.

ayuv 

AYUV.

yuv444p16 

Planar 10-bit (shifted to 16-bit) YUV 4:4:4.

yuv444p 

Planar 8-bit YUV 4:4:4.

y410 

Y410.

unknown 

Unknown.

◆ qos_data_type_e

enum class platf::qos_data_type_e : int
strong

Identifies traffic classes used for socket QoS tagging.

Enumerator
audio 

Audio.

video 

Video.

◆ speaker_e

Enumerates supported speaker options.

Enumerator
FRONT_LEFT 

Front left.

FRONT_RIGHT 

Front right.

FRONT_CENTER 

Front center.

LOW_FREQUENCY 

Low frequency.

BACK_LEFT 

Back left.

BACK_RIGHT 

Back right.

SIDE_LEFT 

Side left.

SIDE_RIGHT 

Side right.

MAX_SPEAKERS 

Maximum number of speakers.

◆ thread_priority_e

enum class platf::thread_priority_e : int
strong

Enumerates supported thread priority options.

Enumerator
low 

Low priority.

normal 

Normal priority.

high 

High priority.

critical 

Critical priority.

Function Documentation

◆ abs_mouse()

void platf::abs_mouse ( input_t & input,
const touch_port_t & touch_port,
float x,
float y )

Move the pointer to an absolute client-provided touch coordinate.

Parameters
inputPlatform input backend that receives the event.
touch_portTouch coordinate bounds used for scaling.
xHorizontal absolute coordinate from the client.
yVertical absolute coordinate from the client.

◆ adjust_thread_priority()

void platf::adjust_thread_priority ( thread_priority_e priority)

Apply the requested scheduling priority to the current thread.

Parameters
priorityThread priority requested from the platform backend.

◆ alloc_gamepad()

int platf::alloc_gamepad ( input_t & input,
const gamepad_id_t & id,
const gamepad_arrival_t & metadata,
feedback_queue_t feedback_queue )

Create a new virtual gamepad.

Parameters
inputThe global input context.
idThe gamepad ID.
metadataController metadata from client (empty if none provided).
feedback_queueThe queue for posting messages back to the client.
Returns
0 on success.

◆ allocate_client_input_context()

std::unique_ptr< client_input_t > platf::allocate_client_input_context ( input_t & input)

Allocate a context to store per-client input data.

Allocates a context to store per-client input data.

Parameters
inputThe global input context.
Returns
A unique pointer to a per-client input data context.

◆ appdata()

std::filesystem::path platf::appdata ( )

Performs migration if necessary, then returns the appdata directory.

This is used for the log directory, so it cannot invoke Boost logging!

Returns
The path of the appdata directory that should be used.

◆ audio_control()

std::unique_ptr< audio_control_t > platf::audio_control ( )

Create the platform audio controller.

Returns
Platform audio controller, or nullptr when audio control is unavailable.

◆ button_mouse()

void platf::button_mouse ( input_t & input,
int button,
bool release )

Press or release a virtual mouse button.

Parameters
inputPlatform input backend that receives the event.
buttonMouse button identifier to press or release.
releaseWhether the key or button event is a release.

◆ create_high_precision_timer()

std::unique_ptr< high_precision_timer > platf::create_high_precision_timer ( )

Create platform-specific timer capable of high-precision sleep.

Returns
A unique pointer to timer

◆ display()

std::shared_ptr< display_t > platf::display ( platf::mem_type_e hwdevice_type,
const std::string & display_name,
const video::config_t & config )

Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monitor that's compatible you can find If you require to use this parameter in a separate thread, make a copy of it.

Parameters
display_nameThe name of the monitor that SHOULD be displayed
configStream configuration
Returns
The display_t instance based on hwdevice_type.

Pick a display adapter and capture method.

Parameters
hwdevice_typeenables possible use of hardware encoder

◆ display_names()

std::vector< std::string > platf::display_names ( mem_type_e hwdevice_type)

List display names accepted by the selected capture backend.

Parameters
hwdevice_typeHardware device type requested for capture or encode.
Returns
Display names accepted by the selected capture backend.

◆ drop_elevated_privileges()

void platf::drop_elevated_privileges ( bool all_caps)

Drop elevated privileges (e.g. system admin/nice etc.)

Parameters
all_capsBool that specifies whether to drop all caps or only CAP_SYS_ADMIN

◆ enable_socket_qos()

std::unique_ptr< deinit_t > platf::enable_socket_qos ( uintptr_t native_socket,
boost::asio::ip::address & address,
uint16_t port,
qos_data_type_e data_type,
bool dscp_tagging )

Enable QoS on the given socket for traffic to the specified destination.

Enables QoS on the given socket for traffic to the specified destination.

Parameters
native_socketThe native socket handle.
addressThe destination address for traffic sent on this socket.
portThe destination port for traffic sent on this socket.
data_typeThe type of traffic sent on this socket.
dscp_taggingSpecifies whether to enable DSCP tagging on outgoing traffic.
Returns
Cleanup handle that restores or releases QoS state when destroyed.

◆ free_gamepad()

void platf::free_gamepad ( input_t & input,
int nr )

Release gamepad resources.

Parameters
inputPlatform input backend that receives the event.
nrController index assigned by the client.

◆ freeInput()

void platf::freeInput ( void * p)

Release a platform input backend created by input().

Parameters
pPointer passed to the deleter or conversion helper.

◆ from_pix_fmt()

std::string_view platf::from_pix_fmt ( pix_fmt_e pix_fmt)
inline

Convert a Sunshine pixel format enum to its string name.

Parameters
pix_fmtSunshine pixel format to convert or allocate for.
Returns
Value converted from pix fmt.

◆ from_sockaddr()

std::string platf::from_sockaddr ( const sockaddr * const ip_addr)

Convert a socket address to a printable IP address.

Parameters
ip_addrSocket address to format.
Returns
Value converted from sockaddr.

◆ from_sockaddr_ex()

std::pair< std::uint16_t, std::string > platf::from_sockaddr_ex ( const sockaddr * const ip_addr)

Convert a socket address to a port and printable IP address.

Parameters
ip_addrSocket address to format.
Returns
Value converted from sockaddr ex.

◆ gamepad_battery()

void platf::gamepad_battery ( input_t & input,
const gamepad_battery_t & battery )

Send a gamepad battery event to the OS.

Sends a gamepad battery event to the OS.

Parameters
inputThe global input context.
batteryThe battery event.

◆ gamepad_motion()

void platf::gamepad_motion ( input_t & input,
const gamepad_motion_t & motion )

Send a gamepad motion event to the OS.

Sends a gamepad motion event to the OS.

Parameters
inputThe global input context.
motionThe motion event.

◆ gamepad_touch()

void platf::gamepad_touch ( input_t & input,
const gamepad_touch_t & touch )

Send a gamepad touch event to the OS.

Sends a gamepad touch event to the OS.

Parameters
inputThe global input context.
touchThe touch event.

◆ gamepad_update()

void platf::gamepad_update ( input_t & input,
int nr,
const gamepad_state_t & gamepad_state )

Submit updated Sunshine gamepad state to the virtual device.

Parameters
inputThe input context.
nrThe gamepad index to update.
gamepad_stateThe gamepad button/axis state sent from the client.

◆ get_capabilities()

platform_caps::caps_t platf::get_capabilities ( )

Get the supported platform capabilities to advertise to the client.

Returns the supported platform capabilities to advertise to the client.

Returns
Capability flags.

◆ get_host_name()

std::string platf::get_host_name ( )

Returns the current computer name in UTF-8.

Returns
Computer name or a placeholder upon failure.

◆ get_mac_address()

std::string platf::get_mac_address ( const std::string_view & address)

Return the hardware MAC address associated with a network address.

Parameters
addressNetwork address being parsed or filtered.
Returns
Hardware MAC address string, or an empty string when it cannot be resolved.

◆ get_mouse_loc()

util::point_t platf::get_mouse_loc ( input_t & input)

Get the current mouse position on screen.

Parameters
inputThe input_t instance to use.
Returns
Screen coordinates of the mouse.

*Examples**

auto [x, y] = get_mouse_loc(input);

◆ has_elevated_privileges()

bool platf::has_elevated_privileges ( bool all_caps)

Check is the current process is running with elevated privileges (e.g. system admin/etc.)

Parameters
all_capsBool that specifies whether to check all caps or only CAP_SYS_ADMIN
Returns
True if capabilities specified to be checked are present.

◆ hscroll()

void platf::hscroll ( input_t & input,
int distance )

Apply a horizontal scroll event to the virtual mouse.

Parameters
inputPlatform input backend that receives the event.
distanceHigh-resolution scroll distance reported by the client.

◆ init()

std::unique_ptr< deinit_t > platf::init ( )
nodiscard

Initialize the platform-specific high precision timer.

Initialize the Linux high-precision timer file descriptor.

Returns
Cleanup handle for initialized platform resources, or null if none are needed.

◆ input()

input_t platf::input ( )

Create the platform input backend for a stream.

Returns
Platform-specific input backend for the active stream.

◆ keyboard_update()

void platf::keyboard_update ( input_t & input,
uint16_t modcode,
bool release,
uint8_t flags )

Press or release a virtual keyboard key.

Parameters
inputPlatform input backend that receives the event.
modcodeModifier key code to update.
releaseWhether the key or button event is a release.
flagsBit flags that modify the requested operation.

◆ move_mouse()

void platf::move_mouse ( input_t & input,
int deltaX,
int deltaY )

Move mouse using the backend coordinate system.

Parameters
inputPlatform input backend that receives the event.
deltaXDelta x.
deltaYDelta y.

◆ needs_encoder_reenumeration()

bool platf::needs_encoder_reenumeration ( )

Check if GPUs/drivers have changed since the last call to this function.

Check whether DXGI reports that adapter or driver enumeration is stale.

Report whether encoder backends should be probed again before streaming.

Returns
true if a change has occurred or if it is unknown whether a change occurred.
Always true because Linux GPU changes are not tracked by this backend.
Always true because macOS GPU changes are not tracked by this backend.

◆ open_url()

void platf::open_url ( const std::string & url)

Open a url in the default web browser.

Parameters
urlThe url to open.

◆ pen_update()

void platf::pen_update ( client_input_t * input,
const touch_port_t & touch_port,
const pen_input_t & pen )

Send a pen event to the OS.

Sends a pen event to the OS.

Parameters
inputThe client-specific input context.
touch_portThe current viewport for translating to screen coordinates.
penThe pen event.

◆ process_group_running()

bool platf::process_group_running ( std::uintptr_t native_handle)

Check if a process group still has running children.

Parameters
native_handleThe native handle of the process group.
Returns
true if processes are still running.

◆ request_process_group_exit()

bool platf::request_process_group_exit ( std::uintptr_t native_handle)

Attempt to gracefully terminate a process group.

Parameters
native_handleThe native handle of the process group.
Returns
true if termination was successfully requested.

◆ resolve_render_device()

std::string platf::resolve_render_device ( )

Resolves the render device path to use for hardware encoding.

If config::video.adapter_name is set, returns that. Otherwise, auto-detects the GPU with a connected display via find_render_node_with_display(). Falls back to /dev/dri/renderD128 if detection fails.

Returns
Resolved render device path (may be empty on non-Linux platforms).

◆ run_command()

boost::process::v1::child platf::run_command ( bool elevated,
bool interactive,
const std::string & cmd,
boost::filesystem::path & working_dir,
const boost::process::v1::environment & env,
FILE * file,
std::error_code & ec,
boost::process::v1::group * group )

Launch a configured preparation or application command.

Parameters
elevatedWhether the command should run with elevated privileges.
interactiveWhether the command should run in an interactive session.
cmdCommand line to execute or inspect.
working_dirWorking directory for the child process.
envEnvironment variables for the child process.
fileOptional stdio file handle connected to the child process.
ecError code returned by the asynchronous operation.
groupProcess group used when launching the command.
Returns
Child process handle for the launched command.

◆ scroll()

void platf::scroll ( input_t & input,
int distance )

Apply a vertical scroll event to the virtual mouse.

Parameters
inputPlatform input backend that receives the event.
distanceHigh-resolution scroll distance reported by the client.

◆ send()

bool platf::send ( send_info_t & send_info)

Send the serialized response over the active socket.

Parameters
send_infoSocket addresses, buffers, and sizes for the send operation.
Returns
True when the packet is submitted to the socket.

◆ send_batch()

bool platf::send_batch ( batched_send_info_t & send_info)

Send multiple fixed-size UDP payload blocks using the platform backend.

Parameters
send_infoSocket addresses, buffers, and sizes for the send operation.
Returns
True when all requested packet blocks are submitted to the socket.

◆ set_thread_name()

void platf::set_thread_name ( const std::string & name)

Name the current thread for use with development tools.

Note
On Linux this will be truncated after 15 characters.
Parameters
nameHuman-readable name to assign.

◆ start()

std::unique_ptr<::platf::deinit_t > platf::publish::start ( )
nodiscard

Main entry point for publication of our service on macOS.

This function initiates a connection to the macOS mDNS service and requests to register our Sunshine service. Registration will occur asynchronously (unless it fails immediately, which is probably only possible if the host machine is misconfigured).

Returns
Either nullptr (if the registration fails immediately) or a uniqur_ptr<deinit_t>, which will manage polling for a response from the mDNS service, and then, when deconstructed, will deregister the service.

◆ supported_gamepads()

std::vector< supported_gamepad_t > & platf::supported_gamepads ( input_t * input)

Gets the supported gamepads for this platform backend.

This may be called prior to platf::input()!

Parameters
inputPointer to the platform's input_t or nullptr.
Returns
Vector of gamepad options and status.

◆ touch_update()

void platf::touch_update ( client_input_t * input,
const touch_port_t & touch_port,
const touch_input_t & touch )

Send a touch event to the OS.

Sends a touch event to the OS.

Parameters
inputThe client-specific input context.
touch_portThe current viewport for translating to screen coordinates.
touchThe touch event.

◆ unicode()

void platf::unicode ( input_t & input,
char * utf8,
int size )

Submit UTF-8 text input to the keyboard backend.

Parameters
inputPlatform input backend that receives the event.
utf8UTF-8 text submitted by the client.
sizeNumber of bytes or elements requested.

Variable Documentation

◆ map_stereo

std::uint8_t platf::speaker::map_stereo[]
constexpr
Initial value:
{
}
@ FRONT_LEFT
Front left.
Definition common.h:256
@ FRONT_RIGHT
Front right.
Definition common.h:257

Moonlight speaker order for stereo audio.

◆ map_surround51

std::uint8_t platf::speaker::map_surround51[]
constexpr
Initial value:
{
}
@ BACK_LEFT
Back left.
Definition common.h:260
@ LOW_FREQUENCY
Low frequency.
Definition common.h:259
@ FRONT_CENTER
Front center.
Definition common.h:258
@ BACK_RIGHT
Back right.
Definition common.h:261

Moonlight speaker order for 5.1 surround audio.

◆ map_surround71

std::uint8_t platf::speaker::map_surround71[]
constexpr
Initial value:
{
}
@ SIDE_RIGHT
Side right.
Definition common.h:263
@ SIDE_LEFT
Side left.
Definition common.h:262

Moonlight speaker order for 7.1 surround audio.