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