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

Definitions for the configuration of Sunshine. More...

#include <algorithm>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iostream>
#include <thread>
#include <unordered_map>
#include <utility>
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include "config.h"
#include "entry_handler.h"
#include "file_handler.h"
#include "logging.h"
#include "nvhttp.h"
#include "platform/common.h"
#include "rtsp.h"
#include "utility.h"
#include <shellapi.h>
Include dependency graph for config.cpp:

Macros

#define _CONVERT_(x)
 
#define _CONVERT_(x)
 
#define _CONVERT_(x)
 
#define _CONVERT_(x)
 
#define _CONVERT_(x)
 
#define _CONVERT_(x)   _CONVERT_2_ARG_(x, x)
 
#define _CONVERT_(x)   _CONVERT_2_ARG_(x, x)
 
#define _CONVERT_(x)   _CONVERT_2_ARG_(x, x)
 
#define _CONVERT_(x, y)
 
#define _CONVERT_2_ARG_(str, val)
 
#define _CONVERT_2_ARG_(str, val)
 
#define _CONVERT_2_ARG_(str, val)
 
#define AMF_VIDEO_ENCODER_AV1_QUALITY_PRESET_BALANCED   70
 
#define AMF_VIDEO_ENCODER_AV1_QUALITY_PRESET_QUALITY   30
 
#define AMF_VIDEO_ENCODER_AV1_QUALITY_PRESET_SPEED   100
 
#define AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_CBR   3
 
#define AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_CONSTANT_QP   0
 
#define AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR   1
 
#define AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR   2
 
#define AMF_VIDEO_ENCODER_AV1_USAGE_LOW_LATENCY   1
 
#define AMF_VIDEO_ENCODER_AV1_USAGE_LOW_LATENCY_HIGH_QUALITY   5
 
#define AMF_VIDEO_ENCODER_AV1_USAGE_TRANSCODING   0
 
#define AMF_VIDEO_ENCODER_AV1_USAGE_ULTRA_LOW_LATENCY   2
 
#define AMF_VIDEO_ENCODER_AV1_USAGE_WEBCAM   3
 
#define AMF_VIDEO_ENCODER_CABAC   1
 
#define AMF_VIDEO_ENCODER_CALV   2
 
#define AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_BALANCED   5
 
#define AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_QUALITY   0
 
#define AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_SPEED   10
 
#define AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR   3
 
#define AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP   0
 
#define AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR   1
 
#define AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR   2
 
#define AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY   2
 
#define AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY_HIGH_QUALITY   5
 
#define AMF_VIDEO_ENCODER_HEVC_USAGE_TRANSCODING   0
 
#define AMF_VIDEO_ENCODER_HEVC_USAGE_ULTRA_LOW_LATENCY   1
 
#define AMF_VIDEO_ENCODER_HEVC_USAGE_WEBCAM   3
 
#define AMF_VIDEO_ENCODER_QUALITY_PRESET_BALANCED   0
 
#define AMF_VIDEO_ENCODER_QUALITY_PRESET_QUALITY   2
 
#define AMF_VIDEO_ENCODER_QUALITY_PRESET_SPEED   1
 
#define AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_CBR   1
 
#define AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_CONSTANT_QP   0
 
#define AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR   3
 
#define AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR   2
 
#define AMF_VIDEO_ENCODER_UNDEFINED   0
 
#define AMF_VIDEO_ENCODER_USAGE_LOW_LATENCY   2
 
#define AMF_VIDEO_ENCODER_USAGE_LOW_LATENCY_HIGH_QUALITY   5
 
#define AMF_VIDEO_ENCODER_USAGE_TRANSCODING   0
 
#define AMF_VIDEO_ENCODER_USAGE_ULTRA_LOW_LATENCY   1
 
#define AMF_VIDEO_ENCODER_USAGE_WEBCAM   3
 
#define APPS_JSON_PATH   platf::appdata().string() + "/apps.json"
 
#define CA_DIR   "credentials"
 
#define CERTIFICATE_FILE   CA_DIR "/cacert.pem"
 
#define PRIVATE_KEY_FILE   CA_DIR "/cakey.pem"
 

Enumerations

enum  config::qsv::cavlc_e : int { config::qsv::_auto = false , config::qsv::enabled = true , config::qsv::disabled = false }
 
enum  config::amd::coder_e : int { config::amd::_auto = 0 , config::amd::cabac = 1 , config::amd::cavlc = 2 }
 
enum  config::vt::coder_e : int { config::vt::_auto = 0 , config::vt::cabac , config::vt::cavlc }
 
enum  config::qsv::preset_e : int {
  config::qsv::veryslow = 1 , config::qsv::slower = 2 , config::qsv::slow = 3 , config::qsv::medium = 4 ,
  config::qsv::fast = 5 , config::qsv::faster = 6 , config::qsv::veryfast = 7
}
 
enum class  config::amd::quality_av1_e : int { speed = 100 , quality = 30 , balanced = 70 }
 
enum class  config::amd::quality_h264_e : int { speed = 1 , quality = 2 , balanced = 0 }
 
enum class  config::amd::quality_hevc_e : int { speed = 10 , quality = 0 , balanced = 5 }
 
enum class  config::amd::rc_av1_e : int { cbr = 3 , cqp = 0 , vbr_latency = 1 , vbr_peak = 2 }
 
enum class  config::amd::rc_h264_e : int { cbr = 1 , cqp = 0 , vbr_latency = 3 , vbr_peak = 2 }
 
enum class  config::amd::rc_hevc_e : int { cbr = 3 , cqp = 0 , vbr_latency = 1 , vbr_peak = 2 }
 
enum class  config::amd::usage_av1_e : int {
  transcoding = 0 , webcam = 3 , lowlatency_high_quality = 5 , lowlatency = 1 ,
  ultralowlatency = 2
}
 
enum class  config::amd::usage_h264_e : int {
  transcoding = 0 , webcam = 3 , lowlatency_high_quality = 5 , lowlatency = 2 ,
  ultralowlatency = 1
}
 
enum class  config::amd::usage_hevc_e : int {
  transcoding = 0 , webcam = 3 , lowlatency_high_quality = 5 , lowlatency = 2 ,
  ultralowlatency = 1
}
 

Functions

int config::vt::allow_software_from_view (const std::string_view &software)
 
void config::apply_config (std::unordered_map< std::string, std::string > &&vars)
 
int config::apply_flags (const char *line)
 
void config::bool_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, bool &input)
 
int config::amd::coder_from_view (const std::string_view &coder)
 
std::optional< int > config::qsv::coder_from_view (const std::string_view &coder)
 
int config::vt::coder_from_view (const std::string_view &coder)
 
video_t::dd_t::config_option_e config::dd::config_option_from_view (const std::string_view value)
 
void config::double_between_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, double &input, const std::pair< double, double > &range)
 
void config::double_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, double &input)
 
bool config::endline (char ch)
 
int config::vt::force_software_from_view (const std::string_view &software)
 
template<typename T , typename F >
void config::generic_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, T &input, F &&f)
 
std::vector< std::string_view > & config::get_supported_gamepad_options ()
 
video_t::dd_t::hdr_option_e config::dd::hdr_option_from_view (const std::string_view value)
 
void config::int_between_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, int &input, const std::pair< int, int > &range)
 
void config::int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, int &input)
 
template<class F >
void config::int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, int &input, F &&f)
 
void config::int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::optional< int > &input)
 
template<class F >
void config::int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::optional< int > &input, F &&f)
 
void config::list_int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< int > &input)
 
void config::list_prep_cmd_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< prep_cmd_t > &input)
 
void config::list_string_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< std::string > &input)
 
void config::map_int_int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::unordered_map< int, int > &input)
 
video_t::dd_t::mode_remapping_t config::dd::mode_remapping_from_view (const std::string_view value)
 
int config::parse (int argc, char *argv[])
 
std::unordered_map< std::string, std::string > config::parse_config (const std::string_view &file_content)
 
std::pair< std::string_view::const_iterator, std::optional< std::pair< std::string, std::string > > > config::parse_option (std::string_view::const_iterator begin, std::string_view::const_iterator end)
 
void config::path_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, fs::path &input)
 
void config::path_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::string &input)
 
std::optional< int > config::qsv::preset_from_view (const std::string_view &preset)
 
template<class T >
std::optional< int > config::amd::quality_from_view (const std::string_view &quality_type, const std::optional< int >(&original))
 
template<class T >
std::optional< int > config::amd::rc_from_view (const std::string_view &rc, const std::optional< int >(&original))
 
video_t::dd_t::refresh_rate_option_e config::dd::refresh_rate_option_from_view (const std::string_view value)
 
video_t::dd_t::resolution_option_e config::dd::resolution_option_from_view (const std::string_view value)
 
int config::vt::rt_from_view (const std::string_view &rt)
 
template<class It >
It config::skip_list (It skipper, It end)
 
bool config::space_tab (char ch)
 
void config::string_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::string &input)
 
void config::string_restricted_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::string &input, const std::vector< std::string_view > &allowed_vals)
 
int config::sw::svtav1_preset_from_view (const std::string_view &preset)
 
bool config::to_bool (std::string &boolean)
 
std::string config::to_string (const char *begin, const char *end)
 
nvenc::nvenc_two_pass config::nv::twopass_from_view (const std::string_view &preset)
 
template<class T >
std::optional< int > config::amd::usage_from_view (const std::string_view &usage, const std::optional< int >(&original))
 
bool config::whitespace (char ch)
 

Variables

audio_t config::audio
 
input_t config::input
 
nvhttp_t config::nvhttp
 
stream_t config::stream
 
sunshine_t config::sunshine
 
video_t config::video
 

Detailed Description

Definitions for the configuration of Sunshine.

Macro Definition Documentation

◆ _CONVERT_ [1/6]

#define _CONVERT_ ( x)
Value:
if (quality_type == #x##sv) \
return (int) T::x

◆ _CONVERT_ [2/6]

#define _CONVERT_ ( x)
Value:
if (rc == #x##sv) \
return (int) T::x

◆ _CONVERT_ [3/6]

#define _CONVERT_ ( x)
Value:
if (usage == #x##sv) \
return (int) T::x

◆ _CONVERT_ [4/6]

#define _CONVERT_ ( x)
Value:
if (preset == #x##sv) \
return x

◆ _CONVERT_ [5/6]

#define _CONVERT_ ( x)
Value:
if (value == #x##sv) \
return video_t::dd_t::config_option_e::x

◆ _CONVERT_ [6/6]

#define _CONVERT_ ( x,
y )
Value:
if (preset == #x##sv) \
return y

◆ _CONVERT_2_ARG_ [1/3]

#define _CONVERT_2_ARG_ ( str,
val )
Value:
if (value == #str##sv) \
return video_t::dd_t::resolution_option_e::val

◆ _CONVERT_2_ARG_ [2/3]

#define _CONVERT_2_ARG_ ( str,
val )
Value:
if (value == #str##sv) \
return video_t::dd_t::refresh_rate_option_e::val

◆ _CONVERT_2_ARG_ [3/3]

#define _CONVERT_2_ARG_ ( str,
val )
Value:
if (value == #str##sv) \
return video_t::dd_t::hdr_option_e::val

Enumeration Type Documentation

◆ cavlc_e

Enumerator
_auto 

Auto.

enabled 

Enabled.

disabled 

Disabled.

◆ coder_e [1/2]

Enumerator
_auto 

Auto.

cabac 

CABAC.

cavlc 

CAVLC.

◆ coder_e [2/2]

enum config::vt::coder_e : int
Enumerator
_auto 

Auto.

cabac 

CABAC.

cavlc 

CAVLC.

◆ preset_e

Enumerator
veryslow 

veryslow preset

slower 

slower preset

slow 

slow preset

medium 

medium preset

fast 

fast preset

faster 

faster preset

veryfast 

veryfast preset

◆ quality_av1_e

enum class config::amd::quality_av1_e : int
strong
Enumerator
speed 

Speed preset.

quality 

Quality preset.

balanced 

Balanced preset.

◆ quality_h264_e

enum class config::amd::quality_h264_e : int
strong
Enumerator
speed 

Speed preset.

quality 

Quality preset.

balanced 

Balanced preset.

◆ quality_hevc_e

enum class config::amd::quality_hevc_e : int
strong
Enumerator
speed 

Speed preset.

quality 

Quality preset.

balanced 

Balanced preset.

◆ rc_av1_e

enum class config::amd::rc_av1_e : int
strong
Enumerator
cbr 

CBR.

cqp 

CQP.

vbr_latency 

VBR with latency constraints.

vbr_peak 

VBR with peak constraints.

◆ rc_h264_e

enum class config::amd::rc_h264_e : int
strong
Enumerator
cbr 

CBR.

cqp 

CQP.

vbr_latency 

VBR with latency constraints.

vbr_peak 

VBR with peak constraints.

◆ rc_hevc_e

enum class config::amd::rc_hevc_e : int
strong
Enumerator
cbr 

CBR.

cqp 

CQP.

vbr_latency 

VBR with latency constraints.

vbr_peak 

VBR with peak constraints.

◆ usage_av1_e

enum class config::amd::usage_av1_e : int
strong
Enumerator
transcoding 

Transcoding preset.

webcam 

Webcam preset.

lowlatency_high_quality 

Low latency high quality preset.

lowlatency 

Low latency preset.

ultralowlatency 

Ultra low latency preset.

◆ usage_h264_e

enum class config::amd::usage_h264_e : int
strong
Enumerator
transcoding 

Transcoding preset.

webcam 

Webcam preset.

lowlatency_high_quality 

Low latency high quality preset.

lowlatency 

Low latency preset.

ultralowlatency 

Ultra low latency preset.

◆ usage_hevc_e

enum class config::amd::usage_hevc_e : int
strong
Enumerator
transcoding 

Transcoding preset.

webcam 

Webcam preset.

lowlatency_high_quality 

Low latency high quality preset.

lowlatency 

Low latency preset.

ultralowlatency 

Ultra low latency preset.

Variable Documentation

◆ audio

audio_t config::audio
Initial value:
{
{},
{},
true,
}

◆ input

input_t config::input
Initial value:
{
{
{0x10, 0xA0},
{0x11, 0xA2},
{0x12, 0xA4},
},
-1ms,
500ms,
std::chrono::duration<double> {1 / 24.9},
{
platf::supported_gamepads(nullptr).front().name.data(),
platf::supported_gamepads(nullptr).front().name.size(),
},
true,
true,
true,
true,
true,
true,
true,
true,
true,
}
std::vector< supported_gamepad_t > & supported_gamepads(input_t *input)
Gets the supported gamepads for this platform backend.
Definition inputtino.cpp:130

◆ nvhttp

nvhttp_t config::nvhttp
Initial value:
{
"lan",
"credentials" "/cakey.pem" ,
"credentials" "/cacert.pem" ,
platf::get_host_name(),
"sunshine_state.json"s,
{},
}

◆ stream

stream_t config::stream
Initial value:
{
10s,
platf::appdata().string() + "/apps.json" ,
20,
ENCRYPTION_MODE_NEVER,
ENCRYPTION_MODE_OPPORTUNISTIC,
}

◆ sunshine

sunshine_t config::sunshine
Initial value:
{
"en",
2,
0,
{},
{},
{},
{},
platf::appdata().string() + "/sunshine.conf",
{},
47989,
"ipv4",
platf::appdata().string() + "/sunshine.log",
false,
{},
}
std::filesystem::path appdata()
Performs migration if necessary, then returns the appdata directory.
Definition misc.cpp:108