Sunshine master
Self-hosted game stream host for Moonlight.
config.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <bitset>
9#include <chrono>
10#include <optional>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15// local includes
16#include "nvenc/nvenc_config.h"
17
18namespace config {
19 // Valid range for the packetsize limit
20 constexpr int PACKETSIZE_MIN = 200;
21 constexpr int PACKETSIZE_MAX = 65535;
22 constexpr int PACKETSIZE_SMALL = 500;
23 constexpr int PACKETSIZE_LARGE = 1456;
24
25 // track modified config options
26 inline std::unordered_map<std::string, std::string> modified_config_settings;
27
28 // sensitive values that should be redacted from logging
29 inline constexpr std::array redacted_config = {
30 "csrf_allowed_origins"
31 };
32
33 void log_config_settings(const std::unordered_map<std::string, std::string> &vars, bool save);
34
35 struct video_t {
36 // ffmpeg params
37 int qp; // higher == more compression and less quality
38
39 int hevc_mode;
40 int av1_mode;
41
42 int min_threads; // Minimum number of threads/slices for CPU encoding
43
44 struct {
45 std::string sw_preset;
46 std::string sw_tune;
47 std::optional<int> svtav1_preset;
48 } sw;
49
51 bool nv_realtime_hags;
52 bool nv_opengl_vulkan_on_dxgi;
53 bool nv_sunshine_high_power_mode;
54
55 struct {
56 int preset;
57 int multipass;
58 int h264_coder;
59 int aq;
60 int vbv_percentage_increase;
61 } nv_legacy;
62
63 struct {
64 std::optional<int> qsv_preset;
65 std::optional<int> qsv_cavlc;
66 bool qsv_slow_hevc;
67 } qsv;
68
69 struct {
70 std::optional<int> amd_usage_h264;
71 std::optional<int> amd_usage_hevc;
72 std::optional<int> amd_usage_av1;
73 std::optional<int> amd_rc_h264;
74 std::optional<int> amd_rc_hevc;
75 std::optional<int> amd_rc_av1;
76 std::optional<int> amd_enforce_hrd;
77 std::optional<int> amd_quality_h264;
78 std::optional<int> amd_quality_hevc;
79 std::optional<int> amd_quality_av1;
80 std::optional<int> amd_preanalysis;
81 std::optional<int> amd_vbaq;
82 int amd_coder;
83 } amd;
84
85 struct {
86 int vt_allow_sw;
87 int vt_require_sw;
88 int vt_realtime;
89 int vt_coder;
90 } vt;
91
92 struct {
93 bool strict_rc_buffer;
94 } vaapi;
95
96 struct {
97 int tune; // 0=default, 1=hq, 2=ll, 3=ull, 4=lossless
98 int rc_mode; // 0=driver, 1=cqp, 2=cbr, 4=vbr
99 } vk;
100
101 std::string capture;
102 std::string encoder;
103 std::string adapter_name;
104 std::string output_name;
105
106 struct dd_t {
108 std::chrono::milliseconds hdr_toggle_delay;
109 };
110
118
120 disabled,
121 automatic,
122 manual
123 };
124
126 disabled,
127 automatic,
128 manual
129 };
130
131 enum class hdr_option_e {
132 disabled,
133 automatic
134 };
135
137 std::string requested_resolution;
138 std::string requested_fps;
139 std::string final_resolution;
140 std::string final_refresh_rate;
141 };
142
144 std::vector<mode_remapping_entry_t> mixed;
145 std::vector<mode_remapping_entry_t> resolution_only;
146 std::vector<mode_remapping_entry_t> refresh_rate_only;
147 };
148
149 config_option_e configuration_option;
150 resolution_option_e resolution_option;
151 std::string manual_resolution;
152 refresh_rate_option_e refresh_rate_option;
154 hdr_option_e hdr_option;
155 std::chrono::milliseconds config_revert_delay;
157 mode_remapping_t mode_remapping;
158 workarounds_t wa;
159 } dd;
160
161 int max_bitrate; // Maximum bitrate, sets ceiling in kbps for bitrate requested from client
163 };
164
165 struct audio_t {
166 std::string sink;
167 std::string virtual_sink;
168 bool stream;
170 };
171
172 constexpr int ENCRYPTION_MODE_NEVER = 0; // Never use video encryption, even if the client supports it
173 constexpr int ENCRYPTION_MODE_OPPORTUNISTIC = 1; // Use video encryption if available, but stream without it if not supported
174 constexpr int ENCRYPTION_MODE_MANDATORY = 2; // Always use video encryption and refuse clients that can't encrypt
175
176 struct stream_t {
177 std::chrono::milliseconds ping_timeout;
178
179 std::string file_apps;
180
181 int fec_percentage;
182
183 // Video encryption settings for LAN and WAN streams
184 int lan_encryption_mode;
185 int wan_encryption_mode;
186
187 // Limit the packetsize to avoid fragmentation on a low MTU link
188 int packetsize;
189 };
190
191 struct nvhttp_t {
192 // Could be any of the following values:
193 // pc|lan|wan
194 std::string origin_web_ui_allowed;
195
196 std::string pkey;
197 std::string cert;
198
199 std::string sunshine_name;
200
201 std::string file_state;
202
203 std::string external_ip;
204 };
205
206 struct input_t {
207 std::unordered_map<int, int> keybindings;
208
209 std::chrono::milliseconds back_button_timeout;
210 std::chrono::milliseconds key_repeat_delay;
211 std::chrono::duration<double> key_repeat_period;
212
213 std::string gamepad;
214 bool ds4_back_as_touchpad_click;
215 bool motion_as_ds4;
216 bool touchpad_as_ds4;
217 bool ds5_inputtino_randomize_mac;
218
219 bool keyboard;
220 bool mouse;
221 bool controller;
222
223 bool always_send_scancodes;
224
225 bool high_resolution_scrolling;
226 bool native_pen_touch;
227 };
228
229 namespace flag {
238 } // namespace flag
239
240 struct prep_cmd_t {
241 prep_cmd_t(std::string &&do_cmd, std::string &&undo_cmd, bool &&elevated):
242 do_cmd(std::move(do_cmd)),
243 undo_cmd(std::move(undo_cmd)),
244 elevated(std::move(elevated)) {
245 }
246
247 explicit prep_cmd_t(std::string &&do_cmd, bool &&elevated):
248 do_cmd(std::move(do_cmd)),
249 elevated(std::move(elevated)) {
250 }
251
252 std::string do_cmd;
253 std::string undo_cmd;
254 bool elevated;
255 };
256
257 struct sunshine_t {
258 std::string locale;
259 int min_log_level;
260 std::bitset<flag::FLAG_SIZE> flags;
261 std::string credentials_file;
262
263 std::string username;
264 std::string password;
265 std::string salt;
266
267 std::string config_file;
268
269 struct cmd_t {
270 std::string name;
271 int argc;
272 char **argv;
273 } cmd;
274
275 std::uint16_t port;
276 std::string address_family;
277 std::string bind_address;
278
279 std::string log_file;
280 bool notify_pre_releases;
281 bool system_tray;
282 std::vector<prep_cmd_t> prep_cmds;
283
284 // List of allowed origins for CSRF protection (e.g., "https://example.com,https://app.example.com")
285 // Comma-separated list of additional origins. Default includes localhost variants and web UI port.
286 std::vector<std::string> csrf_allowed_origins;
287 };
288
289 extern video_t video;
290 extern audio_t audio;
291 extern stream_t stream;
292 extern nvhttp_t nvhttp;
293 extern input_t input;
294 extern sunshine_t sunshine;
295
296 int parse(int argc, char *argv[]);
297 std::unordered_map<std::string, std::string> parse_config(const std::string_view &file_content);
298} // namespace config
flag_e
Definition config.h:230
@ UPNP
Try Universal Plug 'n Play.
Definition config.h:234
@ FRESH_STATE
Do not load or save state.
Definition config.h:232
@ FLAG_SIZE
Number of flags.
Definition config.h:236
@ PIN_STDIN
Read PIN from stdin instead of http.
Definition config.h:231
@ FORCE_VIDEO_HEADER_REPLACE
force replacing headers inside video data
Definition config.h:233
@ CONST_PIN
Use "universal" pin.
Definition config.h:235
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:41
Handles the system tray icon and notification system.
Definition system_tray.cpp:55
Declarations for NVENC encoder configuration.
Definition config.h:165
bool stream
Enable audio streaming to clients.
Definition config.h:168
bool install_steam_drivers
Install Steam audio drivers for enhanced compatibility.
Definition config.h:169
std::string sink
Audio output device/sink to use for audio capture.
Definition config.h:166
std::string virtual_sink
Virtual audio sink for audio routing.
Definition config.h:167
Definition config.h:206
Definition config.h:191
Definition config.h:240
Definition config.h:176
Definition config.h:269
Definition config.h:257
Definition config.h:136
std::vector< mode_remapping_entry_t > refresh_rate_only
To be use when only refresh_rate_option is set to automatic.
Definition config.h:146
std::vector< mode_remapping_entry_t > mixed
To be used when resolution_option and refresh_rate_option is set to automatic.
Definition config.h:144
std::vector< mode_remapping_entry_t > resolution_only
To be use when only resolution_option is set to automatic.
Definition config.h:145
std::chrono::milliseconds hdr_toggle_delay
Specify whether to apply HDR high-contrast color workaround and what delay to use.
Definition config.h:108
Definition config.h:106
std::string manual_resolution
Manual resolution in case resolution_option == resolution_option_e::manual.
Definition config.h:151
refresh_rate_option_e
Definition config.h:125
hdr_option_e
Definition config.h:131
bool config_revert_on_disconnect
Specify whether to revert display configuration on client disconnect.
Definition config.h:156
std::chrono::milliseconds config_revert_delay
Time to wait until settings are reverted (after stream ends/app exists).
Definition config.h:155
std::string manual_refresh_rate
Manual refresh rate in case refresh_rate_option == refresh_rate_option_e::manual.
Definition config.h:153
config_option_e
Definition config.h:111
@ disabled
Disable the configuration for the device.
resolution_option_e
Definition config.h:119
@ automatic
Change resolution and use the one received from Moonlight.
@ manual
Change resolution and use the manually provided one.
Definition config.h:35
double minimum_fps_target
Lowest framerate that will be used when streaming. Range 0-1000, 0 = half of client's requested frame...
Definition config.h:162
NVENC encoder configuration.
Definition nvenc_config.h:24