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
32 inline constexpr std::array redacted_config = {
33 "csrf_allowed_origins"
34 };
35
42 void log_config_settings(const std::unordered_map<std::string, std::string> &vars, bool save);
43
47 struct video_t {
48 // ffmpeg params
52 int qp; // higher == more compression and less quality
53
56
58
59 struct {
60 std::string sw_preset;
61 std::string sw_tune;
62 std::optional<int> svtav1_preset;
63 } sw;
64
69
70 struct {
71 int preset;
72 int multipass;
73 int h264_coder;
74 int aq;
75 int vbv_percentage_increase;
77
78 struct {
79 std::optional<int> qsv_preset;
80 std::optional<int> qsv_cavlc;
81 bool qsv_slow_hevc;
82 } qsv;
83
84 struct {
85 std::optional<int> amd_usage_h264;
86 std::optional<int> amd_usage_hevc;
87 std::optional<int> amd_usage_av1;
88 std::optional<int> amd_rc_h264;
89 std::optional<int> amd_rc_hevc;
90 std::optional<int> amd_rc_av1;
91 std::optional<int> amd_enforce_hrd;
92 std::optional<int> amd_quality_h264;
93 std::optional<int> amd_quality_hevc;
94 std::optional<int> amd_quality_av1;
95 std::optional<int> amd_preanalysis;
96 std::optional<int> amd_vbaq;
97 int amd_coder;
98 } amd;
99
100 struct {
101 int vt_allow_sw;
102 int vt_require_sw;
103 int vt_realtime;
104 int vt_coder;
105 } vt;
106
107 struct {
108 std::optional<int> blbrc;
109 std::optional<int> vaapi_quality;
110 std::optional<int> vaapi_rc;
111 std::string vaapi_rc_str;
112 bool strict_rc_buffer;
114
115 struct {
116 int tune; // 0=default, 1=hq, 2=ll, 3=ull, 4=lossless
117 int rc_mode; // 0=driver, 1=cqp, 2=cbr, 4=vbr
118 } vk;
119
120 std::string capture;
121 std::string encoder;
122 std::string adapter_name;
123 std::string output_name;
124
128 struct dd_t {
133 std::chrono::milliseconds hdr_toggle_delay;
134 };
135
146
151 disabled,
152 automatic,
153 manual
154 };
155
160 disabled,
161 automatic,
162 manual
163 };
164
168 enum class hdr_option_e {
169 disabled,
170 automatic
171 };
172
178 std::string requested_fps;
179 std::string final_resolution;
180 std::string final_refresh_rate;
181 };
182
187 std::vector<mode_remapping_entry_t> mixed;
188 std::vector<mode_remapping_entry_t> resolution_only;
189 std::vector<mode_remapping_entry_t> refresh_rate_only;
190 };
191
194 std::string manual_resolution;
198 std::chrono::milliseconds config_revert_delay;
202 } dd;
203
206 };
207
211 struct audio_t {
212 std::string sink;
213 std::string virtual_sink;
214 bool stream;
216 };
217
221 constexpr int ENCRYPTION_MODE_NEVER = 0; // Never use video encryption, even if the client supports it
225 constexpr int ENCRYPTION_MODE_OPPORTUNISTIC = 1; // Use video encryption if available, but stream without it if not supported
229 constexpr int ENCRYPTION_MODE_MANDATORY = 2; // Always use video encryption and refuse clients that can't encrypt
230
234 struct stream_t {
235 std::chrono::milliseconds ping_timeout;
236
237 std::string file_apps;
238
240
241 // Video encryption settings for LAN and WAN streams
244
245 // Limit the packetsize to avoid fragmentation on a low MTU link
247 };
248
252 struct nvhttp_t {
253 // Could be any of the following values:
254 // pc|lan|wan
256
257 std::string pkey;
258 std::string cert;
259
260 std::string sunshine_name;
261
262 std::string file_state;
263
264 std::string external_ip;
265 };
266
270 struct input_t {
271 std::unordered_map<int, int> keybindings;
272
273 std::chrono::milliseconds back_button_timeout;
274 std::chrono::milliseconds key_repeat_delay;
275 std::chrono::duration<double> key_repeat_period;
276
277 std::string gamepad;
282
283 bool keyboard;
285 bool mouse;
287
289
292 };
293
294 namespace flag {
306 } // namespace flag
307
311 struct prep_cmd_t {
319 prep_cmd_t(std::string &&do_cmd, std::string &&undo_cmd, bool &&elevated):
320 do_cmd(std::move(do_cmd)),
321 undo_cmd(std::move(undo_cmd)),
322 elevated(std::move(elevated)) {
323 }
324
331 explicit prep_cmd_t(std::string &&do_cmd, bool &&elevated):
332 do_cmd(std::move(do_cmd)),
333 elevated(std::move(elevated)) {
334 }
335
336 std::string do_cmd;
337 std::string undo_cmd;
338 bool elevated;
339 };
340
344 struct sunshine_t {
345 std::string locale;
347 std::bitset<flag::FLAG_SIZE> flags;
348 std::string credentials_file;
349
350 std::string username;
351 std::string password;
352 std::string salt;
353
354 std::string config_file;
355
359 struct cmd_t {
360 std::string name;
361 int argc;
362 char **argv;
363 } cmd;
364
365 std::uint16_t port;
366 std::string address_family;
367 std::string bind_address;
368
369 std::string log_file;
372 std::vector<prep_cmd_t> prep_cmds;
373
374 // List of allowed origins for CSRF protection (e.g., "https://example.com,https://app.example.com")
375 // Comma-separated list of additional origins. Default includes localhost variants and web UI port.
376 std::vector<std::string> csrf_allowed_origins;
377 };
378
379 extern video_t video;
380 extern audio_t audio;
381 extern stream_t stream;
382 extern nvhttp_t nvhttp;
383 extern input_t input;
384 extern sunshine_t sunshine;
385
393 int parse(int argc, char *argv[]);
400 std::unordered_map<std::string, std::string> parse_config(const std::string_view &file_content);
401} // namespace config
stream_t stream
Default stream configuration values used before file and CLI overrides.
Definition config.cpp:807
input_t input
Default input configuration values used before file and CLI overrides.
Definition config.cpp:836
std::unordered_map< std::string, std::string > parse_config(const std::string_view &file_content)
Parse Sunshine configuration text into key-value entries.
Definition config.cpp:1012
int parse(int argc, char *argv[])
Parse serialized text into the corresponding runtime representation.
Definition config.cpp:1899
video_t video
Default video configuration values used before file and CLI overrides.
Definition config.cpp:711
sunshine_t sunshine
Default top-level Sunshine configuration values used before file and CLI overrides.
Definition config.cpp:866
audio_t audio
Default audio configuration values used before file and CLI overrides.
Definition config.cpp:797
std::unordered_map< std::string, std::string > modified_config_settings
Configuration keys changed during the current parse or UI update.
Definition config.h:26
constexpr int PACKETSIZE_MAX
Highest accepted configured packet size in bytes.
Definition config.h:21
constexpr int ENCRYPTION_MODE_OPPORTUNISTIC
Encryption policy that uses encrypted video only when the client supports it.
Definition config.h:225
flag_e
Enumerates supported flag options.
Definition config.h:298
@ UPNP
Try Universal Plug 'n Play.
Definition config.h:302
@ FRESH_STATE
Do not load or save state.
Definition config.h:300
@ FLAG_SIZE
Number of flags.
Definition config.h:304
@ PIN_STDIN
Read PIN from stdin instead of http.
Definition config.h:299
@ FORCE_VIDEO_HEADER_REPLACE
force replacing headers inside video data
Definition config.h:301
@ CONST_PIN
Use "universal" pin.
Definition config.h:303
constexpr std::array redacted_config
Configuration keys whose values must be hidden in logs.
Definition config.h:32
constexpr int PACKETSIZE_LARGE
Default large packet size that avoids common MTU fragmentation.
Definition config.h:23
constexpr int PACKETSIZE_MIN
Lowest accepted configured packet size in bytes.
Definition config.h:20
constexpr int ENCRYPTION_MODE_MANDATORY
Encryption policy that rejects clients without video encryption support.
Definition config.h:229
constexpr int ENCRYPTION_MODE_NEVER
Encryption policy that always sends unencrypted video.
Definition config.h:221
constexpr int PACKETSIZE_SMALL
Conservative packet size used for low-MTU links.
Definition config.h:22
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:41
Declarations for NVENC encoder configuration.
Audio capture and encoder settings loaded from configuration.
Definition config.h:211
bool stream
Enable audio streaming to clients.
Definition config.h:214
bool install_steam_drivers
Install Steam audio drivers for enhanced compatibility.
Definition config.h:215
std::string sink
Audio output device/sink to use for audio capture.
Definition config.h:212
std::string virtual_sink
Virtual audio sink for audio routing.
Definition config.h:213
Input emulation settings loaded from configuration.
Definition config.h:270
bool mouse
Enable mouse input from clients.
Definition config.h:285
bool ds5_inputtino_randomize_mac
Randomize the inputtino DualSense MAC address.
Definition config.h:281
bool touchpad_as_ds4
Expose touchpad input through the DS4 protocol.
Definition config.h:280
bool keyboard
Enable keyboard input from clients.
Definition config.h:283
std::unordered_map< int, int > keybindings
Client keycode to platform keycode bindings.
Definition config.h:271
bool high_resolution_scrolling
Enable high-resolution mouse-wheel events.
Definition config.h:290
std::chrono::milliseconds key_repeat_delay
Delay before repeating a held keyboard key.
Definition config.h:274
bool key_rightalt_to_key_win
Map the client Right Alt key to the Windows key.
Definition config.h:284
bool controller
Enable controller input from clients.
Definition config.h:286
bool always_send_scancodes
Always send keyboard scancodes when available.
Definition config.h:288
std::string gamepad
Virtual controller backend selected by configuration.
Definition config.h:277
std::chrono::duration< double > key_repeat_period
Interval between repeated keyboard key events.
Definition config.h:275
bool native_pen_touch
Enable native pen and touch injection.
Definition config.h:291
bool motion_as_ds4
Expose motion controls through the DS4 protocol.
Definition config.h:279
bool ds4_back_as_touchpad_click
Map the DS4 Back button to a touchpad click.
Definition config.h:278
std::chrono::milliseconds back_button_timeout
Hold duration that turns a controller Back button into a special action.
Definition config.h:273
HTTP and HTTPS settings used by the GameStream pairing server.
Definition config.h:252
std::string file_state
Path to the persisted Sunshine state file.
Definition config.h:262
std::string external_ip
External address advertised to clients when configured.
Definition config.h:264
std::string cert
Certificate PEM string or path.
Definition config.h:258
std::string pkey
Private key PEM string or path.
Definition config.h:257
std::string sunshine_name
Host name advertised to Moonlight clients.
Definition config.h:260
std::string origin_web_ui_allowed
Origin policy used for Web UI access checks.
Definition config.h:255
External preparation command plus its privilege requirement.
Definition config.h:311
prep_cmd_t(std::string &&do_cmd, bool &&elevated)
Build a preparation command entry from parsed configuration data.
Definition config.h:331
prep_cmd_t(std::string &&do_cmd, std::string &&undo_cmd, bool &&elevated)
Build a preparation command entry from parsed configuration data.
Definition config.h:319
std::string undo_cmd
Command to run after the application exits.
Definition config.h:337
std::string do_cmd
Command to run before the application starts.
Definition config.h:336
bool elevated
Whether the process should be launched elevated.
Definition config.h:338
Network stream settings shared by audio, video, and control channels.
Definition config.h:234
int lan_encryption_mode
Video encryption policy for LAN clients.
Definition config.h:242
std::string file_apps
Path to the configured applications file.
Definition config.h:237
int wan_encryption_mode
Video encryption policy for WAN clients.
Definition config.h:243
int fec_percentage
Percentage of forward-error-correction packets to add to the stream.
Definition config.h:239
int packetsize
Maximum payload size for network packets.
Definition config.h:246
std::chrono::milliseconds ping_timeout
Timeout used when waiting for client ping responses.
Definition config.h:235
Command-line options parsed before configuration loading.
Definition config.h:359
char ** argv
Command-line argument vector.
Definition config.h:362
int argc
Number of command-line arguments.
Definition config.h:361
std::string name
Executable name from the command line.
Definition config.h:360
Top-level Sunshine configuration and credential state.
Definition config.h:344
bool system_tray
Enable the system tray integration.
Definition config.h:371
std::string salt
Salt used when hashing the Web UI password.
Definition config.h:352
std::string address_family
Address family requested for listening sockets.
Definition config.h:366
std::string password
Password hash or secret for the local Web UI account.
Definition config.h:351
std::string config_file
Path to the active Sunshine configuration file.
Definition config.h:354
std::uint16_t port
TCP port used by Sunshine services.
Definition config.h:365
std::string credentials_file
Path to the stored pairing credentials file.
Definition config.h:348
std::string locale
Locale selected for Sunshine UI and log messages.
Definition config.h:345
std::vector< prep_cmd_t > prep_cmds
Preparation commands executed around application launch.
Definition config.h:372
std::string log_file
Path to the configured log file.
Definition config.h:369
std::string username
Username for the local Web UI account.
Definition config.h:350
int min_log_level
Minimum severity level written to the configured log sink.
Definition config.h:346
std::bitset< flag::FLAG_SIZE > flags
Runtime flags parsed from command-line options.
Definition config.h:347
bool notify_pre_releases
Notify users about pre-release updates.
Definition config.h:370
struct config::sunshine_t::cmd_t cmd
Command line used to launch the application.
std::string bind_address
Local address Sunshine should bind to.
Definition config.h:367
std::vector< std::string > csrf_allowed_origins
Additional origins allowed by CSRF validation.
Definition config.h:376
Single display mode remapping rule from configuration.
Definition config.h:176
std::string final_refresh_rate
Refresh-rate string to apply after remapping.
Definition config.h:180
std::string requested_fps
Refresh-rate string requested by the client.
Definition config.h:178
std::string final_resolution
Resolution string to apply after remapping.
Definition config.h:179
std::string requested_resolution
Resolution string requested by the client.
Definition config.h:177
Collection of display mode remapping rules.
Definition config.h:186
std::vector< mode_remapping_entry_t > refresh_rate_only
To be use when only refresh_rate_option is set to automatic.
Definition config.h:189
std::vector< mode_remapping_entry_t > mixed
To be used when resolution_option and refresh_rate_option is set to automatic.
Definition config.h:187
std::vector< mode_remapping_entry_t > resolution_only
To be use when only resolution_option is set to automatic.
Definition config.h:188
Compatibility workarounds for display-device control.
Definition config.h:132
std::chrono::milliseconds hdr_toggle_delay
Specify whether to apply HDR high-contrast color workaround and what delay to use.
Definition config.h:133
Display-device integration settings.
Definition config.h:128
refresh_rate_option_e refresh_rate_option
Refresh-rate selection mode selected by configuration.
Definition config.h:195
std::string manual_resolution
Manual resolution in case resolution_option == resolution_option_e::manual.
Definition config.h:194
refresh_rate_option_e
Selects how Sunshine chooses the stream display refresh rate.
Definition config.h:159
hdr_option_e
Selects how Sunshine handles HDR state for the stream display.
Definition config.h:168
bool config_revert_on_disconnect
Specify whether to revert display configuration on client disconnect.
Definition config.h:199
std::chrono::milliseconds config_revert_delay
Time to wait until settings are reverted (after stream ends/app exists).
Definition config.h:198
std::string manual_refresh_rate
Manual refresh rate in case refresh_rate_option == refresh_rate_option_e::manual.
Definition config.h:196
config_option_e
Selects how Sunshine prepares the active display before streaming.
Definition config.h:139
@ disabled
Disable the configuration for the device.
hdr_option_e hdr_option
HDR-selection mode selected by configuration.
Definition config.h:197
resolution_option_e
Selects how Sunshine chooses the stream display resolution.
Definition config.h:150
@ automatic
Change resolution and use the one received from Moonlight.
@ manual
Change resolution and use the manually provided one.
mode_remapping_t mode_remapping
Display mode remapping rules grouped by automatic selection mode.
Definition config.h:200
workarounds_t wa
Display-device compatibility workarounds.
Definition config.h:201
config_option_e configuration_option
Display-preparation mode selected by configuration.
Definition config.h:192
resolution_option_e resolution_option
Resolution-selection mode selected by configuration.
Definition config.h:193
Video encoder, capture, and color settings loaded from configuration.
Definition config.h:47
std::string encoder
Encoder backend name selected by configuration.
Definition config.h:121
struct config::video_t::@1 nv_legacy
Legacy NVIDIA encoder options kept for config compatibility.
bool nv_realtime_hags
Enable the NVIDIA realtime HAGS workaround.
Definition config.h:66
std::string capture
Capture backend name selected by configuration.
Definition config.h:120
int qp
Quantization parameter used by encoders where higher values trade quality for compression.
Definition config.h:52
int max_bitrate
Maximum bitrate ceiling in kbps for bitrate requested from the client.
Definition config.h:204
int min_threads
Minimum number of threads or slices for CPU encoding.
Definition config.h:57
std::string adapter_name
Display adapter name selected in configuration.
Definition config.h:122
struct config::video_t::@6 vk
Vulkan encoder options.
std::string output_name
Display output name selected in configuration.
Definition config.h:123
struct config::video_t::dd_t dd
Display-device integration settings.
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:205
bool nv_sunshine_high_power_mode
Request NVIDIA high-power mode for Sunshine.
Definition config.h:68
struct config::video_t::@2 qsv
Intel Quick Sync encoder options.
int av1_mode
AV1 support mode advertised to clients.
Definition config.h:55
nvenc::nvenc_config nv
NVIDIA NVENC encoder settings.
Definition config.h:65
int hevc_mode
HEVC support mode advertised to clients.
Definition config.h:54
struct config::video_t::@5 vaapi
VA-API encoder options.
struct config::video_t::@4 vt
VideoToolbox encoder options.
struct config::video_t::@3 amd
AMD AMF encoder options.
bool nv_opengl_vulkan_on_dxgi
Prefer NVIDIA OpenGL/Vulkan-on-DXGI interop.
Definition config.h:67
struct config::video_t::@0 sw
Software encoder options.
NVENC encoder configuration.
Definition nvenc_config.h:30