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 bool strict_rc_buffer;
110
111 struct {
112 int tune; // 0=default, 1=hq, 2=ll, 3=ull, 4=lossless
113 int rc_mode; // 0=driver, 1=cqp, 2=cbr, 4=vbr
114 } vk;
115
116 std::string capture;
117 std::string encoder;
118 std::string adapter_name;
119 std::string output_name;
120
124 struct dd_t {
129 std::chrono::milliseconds hdr_toggle_delay;
130 };
131
142
147 disabled,
148 automatic,
149 manual
150 };
151
156 disabled,
157 automatic,
158 manual
159 };
160
164 enum class hdr_option_e {
165 disabled,
166 automatic
167 };
168
174 std::string requested_fps;
175 std::string final_resolution;
176 std::string final_refresh_rate;
177 };
178
183 std::vector<mode_remapping_entry_t> mixed;
184 std::vector<mode_remapping_entry_t> resolution_only;
185 std::vector<mode_remapping_entry_t> refresh_rate_only;
186 };
187
190 std::string manual_resolution;
194 std::chrono::milliseconds config_revert_delay;
198 } dd;
199
202 };
203
207 struct audio_t {
208 std::string sink;
209 std::string virtual_sink;
210 bool stream;
212 };
213
217 constexpr int ENCRYPTION_MODE_NEVER = 0; // Never use video encryption, even if the client supports it
221 constexpr int ENCRYPTION_MODE_OPPORTUNISTIC = 1; // Use video encryption if available, but stream without it if not supported
225 constexpr int ENCRYPTION_MODE_MANDATORY = 2; // Always use video encryption and refuse clients that can't encrypt
226
230 struct stream_t {
231 std::chrono::milliseconds ping_timeout;
232
233 std::string file_apps;
234
236
237 // Video encryption settings for LAN and WAN streams
240
241 // Limit the packetsize to avoid fragmentation on a low MTU link
243 };
244
248 struct nvhttp_t {
249 // Could be any of the following values:
250 // pc|lan|wan
252
253 std::string pkey;
254 std::string cert;
255
256 std::string sunshine_name;
257
258 std::string file_state;
259
260 std::string external_ip;
261 };
262
266 struct input_t {
267 std::unordered_map<int, int> keybindings;
268
269 std::chrono::milliseconds back_button_timeout;
270 std::chrono::milliseconds key_repeat_delay;
271 std::chrono::duration<double> key_repeat_period;
272
273 std::string gamepad;
278
279 bool keyboard;
281 bool mouse;
283
285
288 };
289
290 namespace flag {
302 } // namespace flag
303
307 struct prep_cmd_t {
315 prep_cmd_t(std::string &&do_cmd, std::string &&undo_cmd, bool &&elevated):
316 do_cmd(std::move(do_cmd)),
317 undo_cmd(std::move(undo_cmd)),
318 elevated(std::move(elevated)) {
319 }
320
327 explicit prep_cmd_t(std::string &&do_cmd, bool &&elevated):
328 do_cmd(std::move(do_cmd)),
329 elevated(std::move(elevated)) {
330 }
331
332 std::string do_cmd;
333 std::string undo_cmd;
334 bool elevated;
335 };
336
340 struct sunshine_t {
341 std::string locale;
343 std::bitset<flag::FLAG_SIZE> flags;
344 std::string credentials_file;
345
346 std::string username;
347 std::string password;
348 std::string salt;
349
350 std::string config_file;
351
355 struct cmd_t {
356 std::string name;
357 int argc;
358 char **argv;
359 } cmd;
360
361 std::uint16_t port;
362 std::string address_family;
363 std::string bind_address;
364
365 std::string log_file;
368 std::vector<prep_cmd_t> prep_cmds;
369
370 // List of allowed origins for CSRF protection (e.g., "https://example.com,https://app.example.com")
371 // Comma-separated list of additional origins. Default includes localhost variants and web UI port.
372 std::vector<std::string> csrf_allowed_origins;
373 };
374
375 extern video_t video;
376 extern audio_t audio;
377 extern stream_t stream;
378 extern nvhttp_t nvhttp;
379 extern input_t input;
380 extern sunshine_t sunshine;
381
389 int parse(int argc, char *argv[]);
396 std::unordered_map<std::string, std::string> parse_config(const std::string_view &file_content);
397} // namespace config
stream_t stream
Default stream configuration values used before file and CLI overrides.
Definition config.cpp:715
input_t input
Default input configuration values used before file and CLI overrides.
Definition config.cpp:744
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:920
int parse(int argc, char *argv[])
Parse serialized text into the corresponding runtime representation.
Definition config.cpp:1797
video_t video
Default video configuration values used before file and CLI overrides.
Definition config.cpp:623
sunshine_t sunshine
Default top-level Sunshine configuration values used before file and CLI overrides.
Definition config.cpp:774
audio_t audio
Default audio configuration values used before file and CLI overrides.
Definition config.cpp:705
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:221
flag_e
Enumerates supported flag options.
Definition config.h:294
@ UPNP
Try Universal Plug 'n Play.
Definition config.h:298
@ FRESH_STATE
Do not load or save state.
Definition config.h:296
@ FLAG_SIZE
Number of flags.
Definition config.h:300
@ PIN_STDIN
Read PIN from stdin instead of http.
Definition config.h:295
@ FORCE_VIDEO_HEADER_REPLACE
force replacing headers inside video data
Definition config.h:297
@ CONST_PIN
Use "universal" pin.
Definition config.h:299
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:225
constexpr int ENCRYPTION_MODE_NEVER
Encryption policy that always sends unencrypted video.
Definition config.h:217
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:207
bool stream
Enable audio streaming to clients.
Definition config.h:210
bool install_steam_drivers
Install Steam audio drivers for enhanced compatibility.
Definition config.h:211
std::string sink
Audio output device/sink to use for audio capture.
Definition config.h:208
std::string virtual_sink
Virtual audio sink for audio routing.
Definition config.h:209
Input emulation settings loaded from configuration.
Definition config.h:266
bool mouse
Enable mouse input from clients.
Definition config.h:281
bool ds5_inputtino_randomize_mac
Randomize the inputtino DualSense MAC address.
Definition config.h:277
bool touchpad_as_ds4
Expose touchpad input through the DS4 protocol.
Definition config.h:276
bool keyboard
Enable keyboard input from clients.
Definition config.h:279
std::unordered_map< int, int > keybindings
Client keycode to platform keycode bindings.
Definition config.h:267
bool high_resolution_scrolling
Enable high-resolution mouse-wheel events.
Definition config.h:286
std::chrono::milliseconds key_repeat_delay
Delay before repeating a held keyboard key.
Definition config.h:270
bool key_rightalt_to_key_win
Map the client Right Alt key to the Windows key.
Definition config.h:280
bool controller
Enable controller input from clients.
Definition config.h:282
bool always_send_scancodes
Always send keyboard scancodes when available.
Definition config.h:284
std::string gamepad
Virtual controller backend selected by configuration.
Definition config.h:273
std::chrono::duration< double > key_repeat_period
Interval between repeated keyboard key events.
Definition config.h:271
bool native_pen_touch
Enable native pen and touch injection.
Definition config.h:287
bool motion_as_ds4
Expose motion controls through the DS4 protocol.
Definition config.h:275
bool ds4_back_as_touchpad_click
Map the DS4 Back button to a touchpad click.
Definition config.h:274
std::chrono::milliseconds back_button_timeout
Hold duration that turns a controller Back button into a special action.
Definition config.h:269
HTTP and HTTPS settings used by the GameStream pairing server.
Definition config.h:248
std::string file_state
Path to the persisted Sunshine state file.
Definition config.h:258
std::string external_ip
External address advertised to clients when configured.
Definition config.h:260
std::string cert
Certificate PEM string or path.
Definition config.h:254
std::string pkey
Private key PEM string or path.
Definition config.h:253
std::string sunshine_name
Host name advertised to Moonlight clients.
Definition config.h:256
std::string origin_web_ui_allowed
Origin policy used for Web UI access checks.
Definition config.h:251
External preparation command plus its privilege requirement.
Definition config.h:307
prep_cmd_t(std::string &&do_cmd, bool &&elevated)
Build a preparation command entry from parsed configuration data.
Definition config.h:327
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:315
std::string undo_cmd
Command to run after the application exits.
Definition config.h:333
std::string do_cmd
Command to run before the application starts.
Definition config.h:332
bool elevated
Whether the process should be launched elevated.
Definition config.h:334
Network stream settings shared by audio, video, and control channels.
Definition config.h:230
int lan_encryption_mode
Video encryption policy for LAN clients.
Definition config.h:238
std::string file_apps
Path to the configured applications file.
Definition config.h:233
int wan_encryption_mode
Video encryption policy for WAN clients.
Definition config.h:239
int fec_percentage
Percentage of forward-error-correction packets to add to the stream.
Definition config.h:235
int packetsize
Maximum payload size for network packets.
Definition config.h:242
std::chrono::milliseconds ping_timeout
Timeout used when waiting for client ping responses.
Definition config.h:231
Command-line options parsed before configuration loading.
Definition config.h:355
char ** argv
Command-line argument vector.
Definition config.h:358
int argc
Number of command-line arguments.
Definition config.h:357
std::string name
Executable name from the command line.
Definition config.h:356
Top-level Sunshine configuration and credential state.
Definition config.h:340
bool system_tray
Enable the system tray integration.
Definition config.h:367
std::string salt
Salt used when hashing the Web UI password.
Definition config.h:348
std::string address_family
Address family requested for listening sockets.
Definition config.h:362
std::string password
Password hash or secret for the local Web UI account.
Definition config.h:347
std::string config_file
Path to the active Sunshine configuration file.
Definition config.h:350
std::uint16_t port
TCP port used by Sunshine services.
Definition config.h:361
std::string credentials_file
Path to the stored pairing credentials file.
Definition config.h:344
std::string locale
Locale selected for Sunshine UI and log messages.
Definition config.h:341
std::vector< prep_cmd_t > prep_cmds
Preparation commands executed around application launch.
Definition config.h:368
std::string log_file
Path to the configured log file.
Definition config.h:365
std::string username
Username for the local Web UI account.
Definition config.h:346
int min_log_level
Minimum severity level written to the configured log sink.
Definition config.h:342
std::bitset< flag::FLAG_SIZE > flags
Runtime flags parsed from command-line options.
Definition config.h:343
bool notify_pre_releases
Notify users about pre-release updates.
Definition config.h:366
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:363
std::vector< std::string > csrf_allowed_origins
Additional origins allowed by CSRF validation.
Definition config.h:372
Single display mode remapping rule from configuration.
Definition config.h:172
std::string final_refresh_rate
Refresh-rate string to apply after remapping.
Definition config.h:176
std::string requested_fps
Refresh-rate string requested by the client.
Definition config.h:174
std::string final_resolution
Resolution string to apply after remapping.
Definition config.h:175
std::string requested_resolution
Resolution string requested by the client.
Definition config.h:173
Collection of display mode remapping rules.
Definition config.h:182
std::vector< mode_remapping_entry_t > refresh_rate_only
To be use when only refresh_rate_option is set to automatic.
Definition config.h:185
std::vector< mode_remapping_entry_t > mixed
To be used when resolution_option and refresh_rate_option is set to automatic.
Definition config.h:183
std::vector< mode_remapping_entry_t > resolution_only
To be use when only resolution_option is set to automatic.
Definition config.h:184
Compatibility workarounds for display-device control.
Definition config.h:128
std::chrono::milliseconds hdr_toggle_delay
Specify whether to apply HDR high-contrast color workaround and what delay to use.
Definition config.h:129
Display-device integration settings.
Definition config.h:124
refresh_rate_option_e refresh_rate_option
Refresh-rate selection mode selected by configuration.
Definition config.h:191
std::string manual_resolution
Manual resolution in case resolution_option == resolution_option_e::manual.
Definition config.h:190
refresh_rate_option_e
Selects how Sunshine chooses the stream display refresh rate.
Definition config.h:155
hdr_option_e
Selects how Sunshine handles HDR state for the stream display.
Definition config.h:164
bool config_revert_on_disconnect
Specify whether to revert display configuration on client disconnect.
Definition config.h:195
std::chrono::milliseconds config_revert_delay
Time to wait until settings are reverted (after stream ends/app exists).
Definition config.h:194
std::string manual_refresh_rate
Manual refresh rate in case refresh_rate_option == refresh_rate_option_e::manual.
Definition config.h:192
config_option_e
Selects how Sunshine prepares the active display before streaming.
Definition config.h:135
@ disabled
Disable the configuration for the device.
hdr_option_e hdr_option
HDR-selection mode selected by configuration.
Definition config.h:193
resolution_option_e
Selects how Sunshine chooses the stream display resolution.
Definition config.h:146
@ 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:196
workarounds_t wa
Display-device compatibility workarounds.
Definition config.h:197
config_option_e configuration_option
Display-preparation mode selected by configuration.
Definition config.h:188
resolution_option_e resolution_option
Resolution-selection mode selected by configuration.
Definition config.h:189
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:117
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:116
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:200
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:118
struct config::video_t::@6 vk
Vulkan encoder options.
std::string output_name
Display output name selected in configuration.
Definition config.h:119
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:201
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