Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
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 "video.h"
#include "utility.h"
#include <ffnvcodec/nvEncodeAPI.h>
Include dependency graph for config.cpp:

Go to the source code of this file.

Macros

#define CA_DIR   "credentials"
#define PRIVATE_KEY_FILE   CA_DIR "/cakey.pem"
#define CERTIFICATE_FILE   CA_DIR "/cacert.pem"
#define APPS_JSON_PATH   platf::appdata().string() + "/apps.json"
#define _CONVERT_(x, y)
#define _CONVERT_(x)
#define _CONVERT_2_ARG_(str, val)
#define _CONVERT_(x)
#define _CONVERT_2_ARG_(str, val)
#define _CONVERT_(x)
#define _CONVERT_2_ARG_(str, val)
#define _CONVERT_(x)

Functions

nvenc::nvenc_two_pass config::nv::twopass_from_view (const ::std::string_view &preset)
int config::sw::svtav1_preset_from_view (const ::std::string_view &preset)
video_t::dd_t::config_option_e config::dd::config_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)
video_t::dd_t::refresh_rate_option_e config::dd::refresh_rate_option_from_view (const ::std::string_view value)
video_t::dd_t::hdr_option_e config::dd::hdr_option_from_view (const ::std::string_view value)
video_t::dd_t::mode_remapping_t config::dd::mode_remapping_from_view (const ::std::string_view value)
bool config::endline (char ch)
bool config::space_tab (char ch)
bool config::whitespace (char ch)
std::string config::to_string (const char *begin, const char *end)
template<class It>
It config::skip_list (It skipper, It end)
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)
const std::set< std::string > & config::server_computed_keys ()
 Keys the Web UI's config response carries but that are never configuration: server-computed status, platform and version fields.
std::unordered_map< std::string, std::string > config::parse_config (const ::std::string_view &file_content)
void config::string_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::string &input)
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)
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)
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)
void config::int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, int &input)
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, int &input, F &&f)
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::int_between_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, int &input, const std::pair< int, int > &range)
bool config::to_bool (std::string &boolean)
void config::bool_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, bool &input)
void config::double_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, double &input)
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::list_string_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< std::string > &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_server_cmd_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< server_cmd_t > &input)
void config::list_int_f (std::unordered_map< std::string, std::string > &vars, const std::string &name, std::vector< int > &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)
int config::apply_flags (const char *line)
std::vector<::std::string_view > & config::get_supported_gamepad_options ()
void config::apply_config (std::unordered_map< std::string, std::string > &&vars)
int config::parse (int argc, char *argv[])

Variables

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

Detailed Description

Definitions for the configuration of Sunshine.

Definition in file config.cpp.

Macro Definition Documentation

◆ _CONVERT_ [1/5]

#define _CONVERT_ ( x)
Value:
_CONVERT_2_ARG_(x, x)

◆ _CONVERT_ [2/5]

#define _CONVERT_ ( x)
Value:
_CONVERT_2_ARG_(x, x)

◆ _CONVERT_ [3/5]

#define _CONVERT_ ( x)
Value:
_CONVERT_2_ARG_(x, x)

◆ _CONVERT_ [4/5]

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

◆ _CONVERT_ [5/5]

#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::hdr_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::resolution_option_e::val

◆ APPS_JSON_PATH

#define APPS_JSON_PATH   platf::appdata().string() + "/apps.json"

Definition at line 43 of file config.cpp.

◆ CA_DIR

#define CA_DIR   "credentials"

Definition at line 39 of file config.cpp.

◆ CERTIFICATE_FILE

#define CERTIFICATE_FILE   CA_DIR "/cacert.pem"

Definition at line 41 of file config.cpp.

◆ PRIVATE_KEY_FILE

#define PRIVATE_KEY_FILE   CA_DIR "/cakey.pem"

Definition at line 40 of file config.cpp.

Function Documentation

◆ apply_config()

void config::apply_config ( std::unordered_map< std::string, std::string > && vars)

Definition at line 857 of file config.cpp.

◆ apply_flags()

int config::apply_flags ( const char * line)

Definition at line 820 of file config.cpp.

◆ bool_f()

void config::bool_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
bool & input )

Definition at line 637 of file config.cpp.

◆ config_option_from_view()

video_t::dd_t::config_option_e config::dd::config_option_from_view ( const ::std::string_view value)

Definition at line 85 of file config.cpp.

◆ double_between_f()

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 )

Definition at line 666 of file config.cpp.

◆ double_f()

void config::double_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
double & input )

Definition at line 648 of file config.cpp.

◆ endline()

bool config::endline ( char ch)

Definition at line 322 of file config.cpp.

◆ generic_f()

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 )

Definition at line 477 of file config.cpp.

◆ get_supported_gamepad_options()

std::vector<::std::string_view > & config::get_supported_gamepad_options ( )

Definition at line 847 of file config.cpp.

◆ hdr_option_from_view()

video_t::dd_t::hdr_option_e config::dd::hdr_option_from_view ( const ::std::string_view value)

Definition at line 124 of file config.cpp.

◆ int_between_f()

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 )

Definition at line 613 of file config.cpp.

◆ int_f() [1/4]

void config::int_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
::std::optional< int > & input )

Definition at line 571 of file config.cpp.

◆ int_f() [2/4]

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 )

Definition at line 605 of file config.cpp.

◆ int_f() [3/4]

void config::int_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
int & input )

Definition at line 547 of file config.cpp.

◆ int_f() [4/4]

template<class F>
void config::int_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
int & input,
F && f )

Definition at line 596 of file config.cpp.

◆ list_int_f()

void config::list_int_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::vector< int > & input )

Definition at line 768 of file config.cpp.

◆ list_prep_cmd_f()

void config::list_prep_cmd_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::vector< prep_cmd_t > & input )

Definition at line 716 of file config.cpp.

◆ list_server_cmd_f()

void config::list_server_cmd_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::vector< server_cmd_t > & input )

Definition at line 742 of file config.cpp.

◆ list_string_f()

void config::list_string_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::vector< std::string > & input )

Definition at line 677 of file config.cpp.

◆ map_int_int_f()

void config::map_int_int_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::unordered_map< int, int > & input )

Definition at line 801 of file config.cpp.

◆ mode_remapping_from_view()

video_t::dd_t::mode_remapping_t config::dd::mode_remapping_from_view ( const ::std::string_view value)

Definition at line 136 of file config.cpp.

◆ parse()

int config::parse ( int argc,
char * argv[] )

Definition at line 1138 of file config.cpp.

◆ parse_config()

std::unordered_map< std::string, std::string > config::parse_config ( const ::std::string_view & file_content)

Definition at line 437 of file config.cpp.

◆ parse_option()

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 )

Definition at line 369 of file config.cpp.

◆ path_f() [1/2]

void config::path_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
fs::path & input )

Definition at line 515 of file config.cpp.

◆ path_f() [2/2]

void config::path_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::string & input )

Definition at line 539 of file config.cpp.

◆ refresh_rate_option_from_view()

video_t::dd_t::refresh_rate_option_e config::dd::refresh_rate_option_from_view ( const ::std::string_view value)

Definition at line 111 of file config.cpp.

◆ resolution_option_from_view()

video_t::dd_t::resolution_option_e config::dd::resolution_option_from_view ( const ::std::string_view value)

Definition at line 98 of file config.cpp.

◆ server_computed_keys()

const std::set< std::string > & config::server_computed_keys ( )

Keys the Web UI's config response carries but that are never configuration: server-computed status, platform and version fields.

They end up in a real hermes.conf, because saveConfig() persists whatever the Web UI posts and the config page posts the whole response back. Two places have to know about them and used to disagree: the parser, which would otherwise report each as an unrecognized option, and the config response, where a parsed value - always a string - replaced the structured field of the same name and left the home page calling an array method on "[]". One list, so the two cannot drift apart again.

Definition at line 407 of file config.cpp.

◆ skip_list()

template<class It>
It config::skip_list ( It skipper,
It end )

Definition at line 350 of file config.cpp.

◆ space_tab()

bool config::space_tab ( char ch)

Definition at line 326 of file config.cpp.

◆ string_f()

void config::string_f ( std::unordered_map< std::string, std::string > & vars,
const std::string & name,
std::string & input )

Definition at line 465 of file config.cpp.

◆ string_restricted_f()

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 )

Definition at line 485 of file config.cpp.

◆ svtav1_preset_from_view()

int config::sw::svtav1_preset_from_view ( const ::std::string_view & preset)

Definition at line 66 of file config.cpp.

◆ to_bool()

bool config::to_bool ( std::string & boolean)

Definition at line 624 of file config.cpp.

◆ to_string()

std::string config::to_string ( const char * begin,
const char * end )

Definition at line 334 of file config.cpp.

◆ twopass_from_view()

nvenc::nvenc_two_pass config::nv::twopass_from_view ( const ::std::string_view & preset)

Definition at line 49 of file config.cpp.

◆ whitespace()

bool config::whitespace ( char ch)

Definition at line 330 of file config.cpp.

Variable Documentation

◆ audio

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

Definition at line 224 of file config.cpp.

◆ input

input_t config::input

Definition at line 257 of file config.cpp.

◆ nvhttp

nvhttp_t config::nvhttp
Initial value:
{
"lan",
"credentials" "/cakey.pem",
"credentials" "/cacert.pem",
"hermes_state.json"s,
{},
}
std::string get_host_name()
Returns the current computer name in UTF-8.
Definition misc.cpp:1533

Definition at line 246 of file config.cpp.

◆ stream

stream_t config::stream
Initial value:
{
10s,
platf::appdata().string() + "/apps.json" ,
20,
true,
50,
ENCRYPTION_MODE_NEVER,
ENCRYPTION_MODE_OPPORTUNISTIC,
}
std::filesystem::path appdata()
Performs migration if necessary, then returns the appdata directory.
Definition misc.cpp:301

Definition at line 232 of file config.cpp.

◆ sunshine

sunshine_t config::sunshine

Definition at line 289 of file config.cpp.

◆ video

video_t config::video

Definition at line 164 of file config.cpp.