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