Merge remote-tracking branch 'origin/master'

This commit is contained in:
Yukino Song
2025-02-06 09:14:18 +08:00
195 changed files with 9602 additions and 13677 deletions

View File

@@ -2,6 +2,7 @@
* @file src/config.cpp
* @brief Definitions for the configuration of Sunshine.
*/
// standard includes
#include <algorithm>
#include <filesystem>
#include <fstream>
@@ -11,22 +12,23 @@
#include <unordered_map>
#include <utility>
// lib includes
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
// local includes
#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 "platform/common.h"
#ifdef _WIN32
#include <shellapi.h>
#include "platform/windows/utils.h"
@@ -45,15 +47,21 @@ using namespace std::literals;
#define CERTIFICATE_FILE CA_DIR "/cacert.pem"
#define APPS_JSON_PATH platf::appdata().string() + "/apps.json"
namespace config {
namespace nv {
nvenc::nvenc_two_pass
twopass_from_view(const std::string_view &preset) {
if (preset == "disabled") return nvenc::nvenc_two_pass::disabled;
if (preset == "quarter_res") return nvenc::nvenc_two_pass::quarter_resolution;
if (preset == "full_res") return nvenc::nvenc_two_pass::full_resolution;
nvenc::nvenc_two_pass twopass_from_view(const std::string_view &preset) {
if (preset == "disabled") {
return nvenc::nvenc_two_pass::disabled;
}
if (preset == "quarter_res") {
return nvenc::nvenc_two_pass::quarter_resolution;
}
if (preset == "full_res") {
return nvenc::nvenc_two_pass::full_resolution;
}
BOOST_LOG(warning) << "config: unknown nvenc_twopass value: " << preset;
return nvenc::nvenc_two_pass::quarter_resolution;
}
@@ -180,11 +188,11 @@ namespace config {
cavlc = AMF_VIDEO_ENCODER_CALV ///< CAVLC
};
template <class T>
std::optional<int>
quality_from_view(const std::string_view &quality_type, const std::optional<int>(&original)) {
template<class T>
std::optional<int> quality_from_view(const std::string_view &quality_type, const std::optional<int>(&original)) {
#define _CONVERT_(x) \
if (quality_type == #x##sv) return (int) T::x
if (quality_type == #x##sv) \
return (int) T::x
_CONVERT_(balanced);
_CONVERT_(quality);
_CONVERT_(speed);
@@ -192,11 +200,11 @@ namespace config {
return original;
}
template <class T>
std::optional<int>
rc_from_view(const std::string_view &rc, const std::optional<int>(&original)) {
template<class T>
std::optional<int> rc_from_view(const std::string_view &rc, const std::optional<int>(&original)) {
#define _CONVERT_(x) \
if (rc == #x##sv) return (int) T::x
if (rc == #x##sv) \
return (int) T::x
_CONVERT_(cbr);
_CONVERT_(cqp);
_CONVERT_(vbr_latency);
@@ -205,11 +213,11 @@ namespace config {
return original;
}
template <class T>
std::optional<int>
usage_from_view(const std::string_view &usage, const std::optional<int>(&original)) {
template<class T>
std::optional<int> usage_from_view(const std::string_view &usage, const std::optional<int>(&original)) {
#define _CONVERT_(x) \
if (usage == #x##sv) return (int) T::x
if (usage == #x##sv) \
return (int) T::x
_CONVERT_(lowlatency);
_CONVERT_(lowlatency_high_quality);
_CONVERT_(transcoding);
@@ -219,11 +227,16 @@ namespace config {
return original;
}
int
coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) return _auto;
if (coder == "cabac"sv || coder == "ac"sv) return cabac;
if (coder == "cavlc"sv || coder == "vlc"sv) return cavlc;
int coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) {
return _auto;
}
if (coder == "cabac"sv || coder == "ac"sv) {
return cabac;
}
if (coder == "cavlc"sv || coder == "vlc"sv) {
return cavlc;
}
return _auto;
}
@@ -246,10 +259,10 @@ namespace config {
disabled = false ///< Disabled
};
std::optional<int>
preset_from_view(const std::string_view &preset) {
std::optional<int> preset_from_view(const std::string_view &preset) {
#define _CONVERT_(x) \
if (preset == #x##sv) return x
if (preset == #x##sv) \
return x
_CONVERT_(veryslow);
_CONVERT_(slower);
_CONVERT_(slow);
@@ -261,11 +274,16 @@ namespace config {
return std::nullopt;
}
std::optional<int>
coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) return _auto;
if (coder == "cabac"sv || coder == "ac"sv) return disabled;
if (coder == "cavlc"sv || coder == "vlc"sv) return enabled;
std::optional<int> coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) {
return _auto;
}
if (coder == "cabac"sv || coder == "ac"sv) {
return disabled;
}
if (coder == "cavlc"sv || coder == "vlc"sv) {
return enabled;
}
return std::nullopt;
}
@@ -279,32 +297,40 @@ namespace config {
cavlc ///< CAVLC
};
int
coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) return _auto;
if (coder == "cabac"sv || coder == "ac"sv) return cabac;
if (coder == "cavlc"sv || coder == "vlc"sv) return cavlc;
int coder_from_view(const std::string_view &coder) {
if (coder == "auto"sv) {
return _auto;
}
if (coder == "cabac"sv || coder == "ac"sv) {
return cabac;
}
if (coder == "cavlc"sv || coder == "vlc"sv) {
return cavlc;
}
return -1;
}
int
allow_software_from_view(const std::string_view &software) {
if (software == "allowed"sv || software == "forced") return 1;
int allow_software_from_view(const std::string_view &software) {
if (software == "allowed"sv || software == "forced") {
return 1;
}
return 0;
}
int
force_software_from_view(const std::string_view &software) {
if (software == "forced") return 1;
int force_software_from_view(const std::string_view &software) {
if (software == "forced") {
return 1;
}
return 0;
}
int
rt_from_view(const std::string_view &rt) {
if (rt == "disabled" || rt == "off" || rt == "0") return 0;
int rt_from_view(const std::string_view &rt) {
if (rt == "disabled" || rt == "off" || rt == "0") {
return 0;
}
return 1;
}
@@ -312,10 +338,10 @@ namespace config {
} // namespace vt
namespace sw {
int
svtav1_preset_from_view(const std::string_view &preset) {
int svtav1_preset_from_view(const std::string_view &preset) {
#define _CONVERT_(x, y) \
if (preset == #x##sv) return y
if (preset == #x##sv) \
return y
_CONVERT_(veryslow, 1);
_CONVERT_(slower, 2);
_CONVERT_(slow, 4);
@@ -331,10 +357,10 @@ namespace config {
} // namespace sw
namespace dd {
video_t::dd_t::config_option_e
config_option_from_view(const std::string_view value) {
video_t::dd_t::config_option_e config_option_from_view(const std::string_view value) {
#define _CONVERT_(x) \
if (value == #x##sv) return video_t::dd_t::config_option_e::x
if (value == #x##sv) \
return video_t::dd_t::config_option_e::x
_CONVERT_(disabled);
_CONVERT_(verify_only);
_CONVERT_(ensure_active);
@@ -344,10 +370,10 @@ namespace config {
return video_t::dd_t::config_option_e::disabled; // Default to this if value is invalid
}
video_t::dd_t::resolution_option_e
resolution_option_from_view(const std::string_view value) {
video_t::dd_t::resolution_option_e resolution_option_from_view(const std::string_view value) {
#define _CONVERT_2_ARG_(str, val) \
if (value == #str##sv) return video_t::dd_t::resolution_option_e::val
if (value == #str##sv) \
return video_t::dd_t::resolution_option_e::val
#define _CONVERT_(x) _CONVERT_2_ARG_(x, x)
_CONVERT_(disabled);
_CONVERT_2_ARG_(auto, automatic);
@@ -357,10 +383,10 @@ namespace config {
return video_t::dd_t::resolution_option_e::disabled; // Default to this if value is invalid
}
video_t::dd_t::refresh_rate_option_e
refresh_rate_option_from_view(const std::string_view value) {
video_t::dd_t::refresh_rate_option_e refresh_rate_option_from_view(const std::string_view value) {
#define _CONVERT_2_ARG_(str, val) \
if (value == #str##sv) return video_t::dd_t::refresh_rate_option_e::val
if (value == #str##sv) \
return video_t::dd_t::refresh_rate_option_e::val
#define _CONVERT_(x) _CONVERT_2_ARG_(x, x)
_CONVERT_(disabled);
_CONVERT_2_ARG_(auto, automatic);
@@ -370,10 +396,10 @@ namespace config {
return video_t::dd_t::refresh_rate_option_e::disabled; // Default to this if value is invalid
}
video_t::dd_t::hdr_option_e
hdr_option_from_view(const std::string_view value) {
video_t::dd_t::hdr_option_e hdr_option_from_view(const std::string_view value) {
#define _CONVERT_2_ARG_(str, val) \
if (value == #str##sv) return video_t::dd_t::hdr_option_e::val
if (value == #str##sv) \
return video_t::dd_t::hdr_option_e::val
#define _CONVERT_(x) _CONVERT_2_ARG_(x, x)
_CONVERT_(disabled);
_CONVERT_2_ARG_(auto, automatic);
@@ -382,9 +408,8 @@ namespace config {
return video_t::dd_t::hdr_option_e::disabled; // Default to this if value is invalid
}
video_t::dd_t::mode_remapping_t
mode_remapping_from_view(const std::string_view value) {
const auto parse_entry_list { [](const auto &entry_list, auto &output_field) {
video_t::dd_t::mode_remapping_t mode_remapping_from_view(const std::string_view value) {
const auto parse_entry_list {[](const auto &entry_list, auto &output_field) {
for (auto &[_, entry] : entry_list) {
auto requested_resolution = entry.template get_optional<std::string>("requested_resolution"s);
auto requested_fps = entry.template get_optional<std::string>("requested_fps"s);
@@ -395,9 +420,10 @@ namespace config {
requested_resolution.value_or(""),
requested_fps.value_or(""),
final_resolution.value_or(""),
final_refresh_rate.value_or("") });
final_refresh_rate.value_or("")
});
}
} };
}};
// We need to add a wrapping object to make it valid JSON, otherwise ptree cannot parse it.
std::stringstream json_stream;
@@ -483,6 +509,7 @@ namespace config {
{}, // manual_refresh_rate
video_t::dd_t::hdr_option_e::automatic, // hdr_option
3s, // config_revert_delay
{}, // config_revert_on_disconnect
{}, // mode_remapping
{} // wa
}, // display_device
@@ -522,13 +549,13 @@ namespace config {
input_t input {
{
{ 0x10, 0xA0 },
{ 0x11, 0xA2 },
{ 0x12, 0xA4 },
{0x10, 0xA0},
{0x11, 0xA2},
{0x12, 0xA4},
},
-1ms, // back_button_timeout
500ms, // key_repeat_delay
std::chrono::duration<double> { 1 / 24.9 }, // key_repeat_period
std::chrono::duration<double> {1 / 24.9}, // key_repeat_period
{
platf::supported_gamepads(nullptr).front().name.data(),
@@ -567,23 +594,19 @@ namespace config {
{}, // server commands
};
bool
endline(char ch) {
bool endline(char ch) {
return ch == '\r' || ch == '\n';
}
bool
space_tab(char ch) {
bool space_tab(char ch) {
return ch == ' ' || ch == '\t';
}
bool
whitespace(char ch) {
bool whitespace(char ch) {
return space_tab(ch) || endline(ch);
}
std::string
to_string(const char *begin, const char *end) {
std::string to_string(const char *begin, const char *end) {
std::string result;
KITTY_WHILE_LOOP(auto pos = begin, pos != end, {
@@ -598,9 +621,8 @@ namespace config {
return result;
}
template <class It>
It
skip_list(It skipper, It end) {
template<class It>
It skip_list(It skipper, It end) {
int stack = 1;
while (skipper != end && stack) {
if (*skipper == '[') {
@@ -619,7 +641,7 @@ namespace config {
std::pair<
std::string_view::const_iterator,
std::optional<std::pair<std::string, std::string>>>
parse_option(std::string_view::const_iterator begin, std::string_view::const_iterator end) {
parse_option(std::string_view::const_iterator begin, std::string_view::const_iterator end) {
begin = std::find_if_not(begin, end, whitespace);
auto endl = std::find_if(begin, end, endline);
auto endc = std::find(begin, endl, '#');
@@ -649,11 +671,11 @@ namespace config {
return std::make_pair(
endl,
std::make_pair(to_string(begin, end_name), to_string(begin_val, endl)));
std::make_pair(to_string(begin, end_name), to_string(begin_val, endl))
);
}
std::unordered_map<std::string, std::string>
parse_config(const std::string_view &file_content) {
std::unordered_map<std::string, std::string> parse_config(const std::string_view &file_content) {
std::unordered_map<std::string, std::string> vars;
auto pos = std::begin(file_content);
@@ -678,8 +700,7 @@ namespace config {
return vars;
}
void
string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
void string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
auto it = vars.find(name);
if (it == std::end(vars)) {
return;
@@ -690,9 +711,8 @@ namespace config {
vars.erase(it);
}
template <typename T, typename F>
void
generic_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, T &input, F &&f) {
template<typename T, typename F>
void generic_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, T &input, F &&f) {
std::string tmp;
string_f(vars, name, tmp);
if (!tmp.empty()) {
@@ -700,8 +720,7 @@ namespace config {
}
}
void
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 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) {
std::string temp;
string_f(vars, name, temp);
@@ -713,8 +732,7 @@ namespace config {
}
}
void
path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, fs::path &input) {
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, fs::path &input) {
// appdata needs to be retrieved once only
static auto appdata = platf::appdata();
@@ -738,8 +756,7 @@ namespace config {
}
}
void
path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
void path_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::string &input) {
fs::path temp = input;
path_f(vars, name, temp);
@@ -747,8 +764,7 @@ namespace config {
input = temp.string();
}
void
int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input) {
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input) {
auto it = vars.find(name);
if (it == std::end(vars)) {
@@ -765,16 +781,14 @@ namespace config {
// If that integer is in hexadecimal
if (val.size() >= 2 && val.substr(0, 2) == "0x"sv) {
input = util::from_hex<int>(val.substr(2));
}
else {
} else {
input = util::from_view(val);
}
vars.erase(it);
}
void
int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input) {
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input) {
auto it = vars.find(name);
if (it == std::end(vars)) {
@@ -791,17 +805,15 @@ namespace config {
// If that integer is in hexadecimal
if (val.size() >= 2 && val.substr(0, 2) == "0x"sv) {
input = util::from_hex<int>(val.substr(2));
}
else {
} else {
input = util::from_view(val);
}
vars.erase(it);
}
template <class F>
void
int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, F &&f) {
template<class F>
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, F &&f) {
std::string tmp;
string_f(vars, name, tmp);
if (!tmp.empty()) {
@@ -809,9 +821,8 @@ namespace config {
}
}
template <class F>
void
int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input, F &&f) {
template<class F>
void int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::optional<int> &input, F &&f) {
std::string tmp;
string_f(vars, name, tmp);
if (!tmp.empty()) {
@@ -819,8 +830,7 @@ namespace config {
}
}
void
int_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, const std::pair<int, int> &range) {
void int_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, int &input, const std::pair<int, int> &range) {
int temp = input;
int_f(vars, name, temp);
@@ -831,9 +841,10 @@ namespace config {
}
}
bool
to_bool(std::string &boolean) {
std::for_each(std::begin(boolean), std::end(boolean), [](char ch) { return (char) std::tolower(ch); });
bool to_bool(std::string &boolean) {
std::for_each(std::begin(boolean), std::end(boolean), [](char ch) {
return (char) std::tolower(ch);
});
return boolean == "true"sv ||
boolean == "yes"sv ||
@@ -843,8 +854,7 @@ namespace config {
(std::find(std::begin(boolean), std::end(boolean), '1') != std::end(boolean));
}
void
bool_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, bool &input) {
void bool_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, bool &input) {
std::string tmp;
string_f(vars, name, tmp);
@@ -855,8 +865,7 @@ namespace config {
input = to_bool(tmp);
}
void
double_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input) {
void double_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input) {
std::string tmp;
string_f(vars, name, tmp);
@@ -874,8 +883,7 @@ namespace config {
input = val;
}
void
double_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input, const std::pair<double, double> &range) {
void double_between_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, double &input, const std::pair<double, double> &range) {
double temp = input;
double_f(vars, name, temp);
@@ -886,8 +894,7 @@ namespace config {
}
}
void
list_string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<std::string> &input) {
void list_string_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<std::string> &input) {
std::string string;
string_f(vars, name, string);
@@ -911,15 +918,12 @@ namespace config {
while (pos < std::cend(string)) {
if (*pos == '[') {
pos = skip_list(pos + 1, std::cend(string)) + 1;
}
else if (*pos == ']') {
} else if (*pos == ']') {
break;
}
else if (*pos == ',') {
} else if (*pos == ',') {
input.emplace_back(begin, pos);
pos = begin = std::find_if_not(pos + 1, std::cend(string), whitespace);
}
else {
} else {
++pos;
}
}
@@ -929,8 +933,7 @@ namespace config {
}
}
void
list_prep_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<prep_cmd_t> &input) {
void list_prep_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<prep_cmd_t> &input) {
std::string string;
string_f(vars, name, string);
@@ -956,8 +959,7 @@ namespace config {
}
}
void
list_server_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<server_cmd_t> &input) {
void list_server_cmd_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<server_cmd_t> &input) {
std::string string;
string_f(vars, name, string);
@@ -983,8 +985,7 @@ namespace config {
}
}
void
list_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<int> &input) {
void list_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::vector<int> &input) {
std::vector<std::string> list;
list_string_f(vars, name, list);
@@ -1010,16 +1011,14 @@ namespace config {
// If the integer is a hexadecimal
if (val.size() >= 2 && val.substr(0, 2) == "0x"sv) {
tmp = util::from_hex<int>(val.substr(2));
}
else {
} else {
tmp = util::from_view(val);
}
input.emplace_back(tmp);
}
}
void
map_int_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::unordered_map<int, int> &input) {
void map_int_int_f(std::unordered_map<std::string, std::string> &vars, const std::string &name, std::unordered_map<int, int> &input) {
std::vector<int> list;
list_int_f(vars, name, list);
@@ -1038,8 +1037,7 @@ namespace config {
}
}
int
apply_flags(const char *line) {
int apply_flags(const char *line) {
int ret = 0;
while (*line != '\0') {
switch (*line) {
@@ -1066,8 +1064,7 @@ namespace config {
return ret;
}
std::vector<std::string_view> &
get_supported_gamepad_options() {
std::vector<std::string_view> &get_supported_gamepad_options() {
const auto options = platf::supported_gamepads(nullptr);
static std::vector<std::string_view> opts {};
opts.reserve(options.size());
@@ -1077,8 +1074,7 @@ namespace config {
return opts;
}
void
apply_config(std::unordered_map<std::string, std::string> &&vars) {
void apply_config(std::unordered_map<std::string, std::string> &&vars) {
if (!fs::exists(stream.file_apps.c_str())) {
fs::copy_file(SUNSHINE_ASSETS_DIR "/apps.json", stream.file_apps);
}
@@ -1095,8 +1091,8 @@ namespace config {
bool_f(vars, "limit_framerate", video.limit_framerate);
bool_f(vars, "double_refreshrate", video.double_refreshrate);
int_f(vars, "qp", video.qp);
int_between_f(vars, "hevc_mode", video.hevc_mode, { 0, 3 });
int_between_f(vars, "av1_mode", video.av1_mode, { 0, 3 });
int_between_f(vars, "hevc_mode", video.hevc_mode, {0, 3});
int_between_f(vars, "av1_mode", video.av1_mode, {0, 3});
int_f(vars, "min_threads", video.min_threads);
string_f(vars, "sw_preset", video.sw.sw_preset);
if (!video.sw.sw_preset.empty()) {
@@ -1104,8 +1100,8 @@ namespace config {
}
string_f(vars, "sw_tune", video.sw.sw_tune);
int_between_f(vars, "nvenc_preset", video.nv.quality_preset, { 1, 7 });
int_between_f(vars, "nvenc_vbv_increase", video.nv.vbv_percentage_increase, { 0, 400 });
int_between_f(vars, "nvenc_preset", video.nv.quality_preset, {1, 7});
int_between_f(vars, "nvenc_vbv_increase", video.nv.vbv_percentage_increase, {0, 400});
bool_f(vars, "nvenc_spatial_aq", video.nv.adaptive_quantization);
generic_f(vars, "nvenc_twopass", video.nv.two_pass, nv::twopass_from_view);
bool_f(vars, "nvenc_h264_cavlc", video.nv.h264_cavlc);
@@ -1177,15 +1173,16 @@ namespace config {
generic_f(vars, "dd_hdr_option", video.dd.hdr_option, dd::hdr_option_from_view);
{
int value = -1;
int_between_f(vars, "dd_config_revert_delay", value, { 0, std::numeric_limits<int>::max() });
int_between_f(vars, "dd_config_revert_delay", value, {0, std::numeric_limits<int>::max()});
if (value >= 0) {
video.dd.config_revert_delay = std::chrono::milliseconds { value };
video.dd.config_revert_delay = std::chrono::milliseconds {value};
}
}
bool_f(vars, "dd_config_revert_on_disconnect", video.dd.config_revert_on_disconnect);
generic_f(vars, "dd_mode_remapping", video.dd.mode_remapping, dd::mode_remapping_from_view);
bool_f(vars, "dd_wa_hdr_toggle", video.dd.wa.hdr_toggle);
int_between_f(vars, "min_fps_factor", video.min_fps_factor, { 1, 3 });
int_between_f(vars, "min_fps_factor", video.min_fps_factor, {1, 3});
string_f(vars, "fallback_mode", video.fallback_mode);
path_f(vars, "pkey", nvhttp.pkey);
@@ -1208,19 +1205,19 @@ namespace config {
bool_f(vars, "keep_sink_default", audio.keep_default);
bool_f(vars, "auto_capture_sink", audio.auto_capture);
string_restricted_f(vars, "origin_web_ui_allowed", nvhttp.origin_web_ui_allowed, { "pc"sv, "lan"sv, "wan"sv });
string_restricted_f(vars, "origin_web_ui_allowed", nvhttp.origin_web_ui_allowed, {"pc"sv, "lan"sv, "wan"sv});
int to = -1;
int_between_f(vars, "ping_timeout", to, { -1, std::numeric_limits<int>::max() });
int_between_f(vars, "ping_timeout", to, {-1, std::numeric_limits<int>::max()});
if (to != -1) {
stream.ping_timeout = std::chrono::milliseconds(to);
}
int_between_f(vars, "lan_encryption_mode", stream.lan_encryption_mode, { 0, 2 });
int_between_f(vars, "wan_encryption_mode", stream.wan_encryption_mode, { 0, 2 });
int_between_f(vars, "lan_encryption_mode", stream.lan_encryption_mode, {0, 2});
int_between_f(vars, "wan_encryption_mode", stream.wan_encryption_mode, {0, 2});
path_f(vars, "file_apps", stream.file_apps);
int_between_f(vars, "fec_percentage", stream.fec_percentage, { 1, 255 });
int_between_f(vars, "fec_percentage", stream.fec_percentage, {1, 255});
map_int_int_f(vars, "keybindings"s, input.keybindings);
@@ -1237,20 +1234,20 @@ namespace config {
int_f(vars, "back_button_timeout", to);
if (to > std::numeric_limits<int>::min()) {
input.back_button_timeout = std::chrono::milliseconds { to };
input.back_button_timeout = std::chrono::milliseconds {to};
}
double repeat_frequency { 0 };
double_between_f(vars, "key_repeat_frequency", repeat_frequency, { 0, std::numeric_limits<double>::max() });
double repeat_frequency {0};
double_between_f(vars, "key_repeat_frequency", repeat_frequency, {0, std::numeric_limits<double>::max()});
if (repeat_frequency > 0) {
config::input.key_repeat_period = std::chrono::duration<double> { 1 / repeat_frequency };
config::input.key_repeat_period = std::chrono::duration<double> {1 / repeat_frequency};
}
to = -1;
int_f(vars, "key_repeat_delay", to);
if (to >= 0) {
input.key_repeat_delay = std::chrono::milliseconds { to };
input.key_repeat_delay = std::chrono::milliseconds {to};
}
string_restricted_f(vars, "gamepad"s, input.gamepad, get_supported_gamepad_options());
@@ -1273,10 +1270,10 @@ namespace config {
bool_f(vars, "notify_pre_releases", sunshine.notify_pre_releases);
int port = sunshine.port;
int_between_f(vars, "port"s, port, { 1024 + nvhttp::PORT_HTTPS, 65535 - rtsp_stream::RTSP_SETUP_PORT });
int_between_f(vars, "port"s, port, {1024 + nvhttp::PORT_HTTPS, 65535 - rtsp_stream::RTSP_SETUP_PORT});
sunshine.port = (std::uint16_t) port;
string_restricted_f(vars, "address_family", sunshine.address_family, { "ipv4"sv, "both"sv });
string_restricted_f(vars, "address_family", sunshine.address_family, {"ipv4"sv, "both"sv});
bool upnp = false;
bool_f(vars, "upnp"s, upnp);
@@ -1312,26 +1309,19 @@ namespace config {
if (!log_level_string.empty()) {
if (log_level_string == "verbose"sv) {
sunshine.min_log_level = 0;
}
else if (log_level_string == "debug"sv) {
} else if (log_level_string == "debug"sv) {
sunshine.min_log_level = 1;
}
else if (log_level_string == "info"sv) {
} else if (log_level_string == "info"sv) {
sunshine.min_log_level = 2;
}
else if (log_level_string == "warning"sv) {
} else if (log_level_string == "warning"sv) {
sunshine.min_log_level = 3;
}
else if (log_level_string == "error"sv) {
} else if (log_level_string == "error"sv) {
sunshine.min_log_level = 4;
}
else if (log_level_string == "fatal"sv) {
} else if (log_level_string == "fatal"sv) {
sunshine.min_log_level = 5;
}
else if (log_level_string == "none"sv) {
} else if (log_level_string == "none"sv) {
sunshine.min_log_level = 6;
}
else {
} else {
// accept digit directly
auto val = log_level_string[0];
if (val >= '0' && val < '7') {
@@ -1357,8 +1347,7 @@ namespace config {
::video::active_av1_mode = video.av1_mode;
}
int
parse(int argc, char *argv[]) {
int parse(int argc, char *argv[]) {
std::unordered_map<std::string, std::string> cmd_vars;
#ifdef _WIN32
bool shortcut_launch = false;
@@ -1375,8 +1364,7 @@ namespace config {
#ifdef _WIN32
else if (line == "--shortcut"sv) {
shortcut_launch = true;
}
else if (line == "--shortcut-admin"sv) {
} else if (line == "--shortcut-admin"sv) {
service_admin_launch = true;
}
#endif
@@ -1392,15 +1380,13 @@ namespace config {
logging::print_help(*argv);
return -1;
}
}
else {
} else {
auto line_end = line + strlen(line);
auto pos = std::find(line, line_end, '=');
if (pos == line_end) {
sunshine.config_file = line;
}
else {
} else {
TUPLE_EL(var, 1, parse_option(line, line_end));
if (!var) {
logging::print_help(*argv);
@@ -1426,7 +1412,7 @@ namespace config {
// Create empty config file if it does not exist
if (!fs::exists(sunshine.config_file)) {
auto cfg_file = std::ofstream { sunshine.config_file };
auto cfg_file = std::ofstream {sunshine.config_file};
#ifdef _WIN32
cfg_file << "server_cmd = [{\"name\":\"Bubbles\",\"cmd\":\"bubbles.scr\",\"elevated\":false}]\n";
#endif
@@ -1444,11 +1430,9 @@ namespace config {
// the path is incorrect or inaccessible.
apply_config(std::move(vars));
config_loaded = true;
}
catch (const std::filesystem::filesystem_error &err) {
} catch (const std::filesystem::filesystem_error &err) {
BOOST_LOG(fatal) << "Failed to apply config: "sv << err.what();
}
catch (const boost::filesystem::filesystem_error &err) {
} catch (const boost::filesystem::filesystem_error &err) {
BOOST_LOG(fatal) << "Failed to apply config: "sv << err.what();
}
@@ -1478,7 +1462,7 @@ namespace config {
// Always return 1 to ensure Sunshine doesn't start normally
return 1;
}
else if (shortcut_launch) {
if (shortcut_launch) {
if (!service_ctrl::is_service_running()) {
// If the service isn't running, relaunch ourselves as admin to start it
WCHAR executable[MAX_PATH];