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

Miscellaneous definitions for Linux. More...

#include <fstream>
#include <iostream>
#include <arpa/inet.h>
#include <dlfcn.h>
#include <ifaddrs.h>
#include <netinet/udp.h>
#include <pwd.h>
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/host_name.hpp>
#include <boost/process/v1.hpp>
#include <fcntl.h>
#include <unistd.h>
#include "graphics.h"
#include "misc.h"
#include "src/config.h"
#include "src/entry_handler.h"
#include "src/logging.h"
#include "src/platform/common.h"
#include "vaapi.h"
Include dependency graph for misc.cpp:

Classes

class  platf::linux_high_precision_timer
 
class  platf::qos_t
 

Macros

#define _GNU_SOURCE   1
 
#define SUNSHINE_GNUC_EXTENSION
 

Typedefs

using platf::ifaddr_t = util::safe_ptr<ifaddrs, freeifaddrs>
 

Enumerations

enum  platf::source::source_e : std::size_t { platf::source::WAYLAND , platf::source::MAX_FLAGS }
 

Functions

void platf::adjust_thread_priority (thread_priority_e priority)
 
std::filesystem::path platf::appdata ()
 Performs migration if necessary, then returns the appdata directory.
 
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)
 
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.
 
std::string platf::from_sockaddr (const sockaddr *const)
 
std::pair< std::uint16_t, std::string > platf::from_sockaddr_ex (const sockaddr *const)
 
std::string platf::get_host_name ()
 Returns the current computer name in UTF-8.
 
ifaddr_t platf::get_ifaddrs ()
 
std::string platf::get_mac_address (const std::string_view &address)
 
void * dyn::handle (const std::vector< const char * > &libs)
 
std::unique_ptr< deinit_tplatf::init ()
 
int dyn::load (void *handle, const std::vector< std::tuple< apiproc *, const char * > > &funcs, bool strict)
 
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.
 
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.
 
void platf::restart ()
 
void platf::restart_on_exit ()
 
bp::child platf::run_command (bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group)
 Run a command on the users profile.
 
bool platf::send (send_info_t &send_info)
 
bool platf::send_batch (batched_send_info_t &send_info)
 
int platf::set_env (const std::string &name, const std::string &value)
 Set an environment variable.
 
void platf::streaming_will_start ()
 
void platf::streaming_will_stop ()
 
struct sockaddr_in platf::to_sockaddr (boost::asio::ip::address_v4 address, uint16_t port)
 
struct sockaddr_in6 platf::to_sockaddr (boost::asio::ip::address_v6 address, uint16_t port)
 
int platf::unset_env (const std::string &name)
 Unset an environment variable.
 
bool platf::verify_wl ()
 
std::shared_ptr< display_tplatf::wl_display (mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
 
std::vector< std::string > platf::wl_display_names ()
 

Variables

window_system_e window_system
 

Detailed Description

Miscellaneous definitions for Linux.

Enumeration Type Documentation

◆ source_e

enum platf::source::source_e : std::size_t
Enumerator
WAYLAND 

Wayland.

MAX_FLAGS 

The maximum number of flags.

Function Documentation

◆ 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.

◆ 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

◆ 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.

◆ 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.

◆ needs_encoder_reenumeration()

bool platf::needs_encoder_reenumeration ( )

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

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

Returns
true if a change has occurred or if it is unknown whether a change occurred.

◆ open_url()

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

Open a url in the default web browser.

Parameters
urlThe url to open.

◆ 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.

◆ run_command()

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

Run a command on the users profile.

Launches a child process as the user, using the current user's environment and a specific working directory.

Parameters
elevatedSpecify whether to elevate the process.
interactiveSpecify whether this will run in a window or hidden.
cmdThe command to run.
working_dirThe working directory for the new process.
envThe environment variables to use for the new process.
fileA file object to redirect the child process's output to (may be nullptr).
ecAn error code, set to indicate any errors that occur during the launch process.
groupA pointer to a bp::group object to which the new process should belong (may be nullptr).
Returns
A bp::child object representing the new process, or an empty bp::child object if the launch fails.

◆ set_env()

int platf::set_env ( const std::string & name,
const std::string & value )

Set an environment variable.

Parameters
nameThe name of the environment variable.
valueThe value to set the environment variable to.
Returns
0 on success, non-zero on failure.

◆ unset_env()

int platf::unset_env ( const std::string & name)

Unset an environment variable.

Parameters
nameThe name of the environment variable.
Returns
0 on success, non-zero on failure.