Sunshine v2025.628.4510
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
144 };
145
146 struct audio_t {
147 std::string sink;
148 std::string virtual_sink;
149 bool stream;
150 bool install_steam_drivers;
151 };
152
153 constexpr int ENCRYPTION_MODE_NEVER = 0; // Never use video encryption, even if the client supports it
154 constexpr int ENCRYPTION_MODE_OPPORTUNISTIC = 1; // Use video encryption if available, but stream without it if not supported
155 constexpr int ENCRYPTION_MODE_MANDATORY = 2; // Always use video encryption and refuse clients that can't encrypt
156
157 struct stream_t {
158 std::chrono::milliseconds ping_timeout;
159
160 std::string file_apps;
161
162 int fec_percentage;
163
164 // Video encryption settings for LAN and WAN streams
165 int lan_encryption_mode;
166 int wan_encryption_mode;
167 };
168
169 struct nvhttp_t {
170 // Could be any of the following values:
171 // pc|lan|wan
172 std::string origin_web_ui_allowed;
173
174 std::string pkey;
175 std::string cert;
176
177 std::string sunshine_name;
178
179 std::string file_state;
180
181 std::string external_ip;
182 };
183
184 struct input_t {
185 std::unordered_map<int, int> keybindings;
186
187 std::chrono::milliseconds back_button_timeout;
188 std::chrono::milliseconds key_repeat_delay;
189 std::chrono::duration<double> key_repeat_period;
190
191 std::string gamepad;
192 bool ds4_back_as_touchpad_click;
193 bool motion_as_ds4;
194 bool touchpad_as_ds4;
195
196 bool keyboard;
197 bool mouse;
198 bool controller;
199
200 bool always_send_scancodes;
201
202 bool high_resolution_scrolling;
203 bool native_pen_touch;
204 };
205
206 namespace flag {
215 } // namespace flag
216
217 struct prep_cmd_t {
218 prep_cmd_t(std::string &&do_cmd, std::string &&undo_cmd, bool &&elevated):
219 do_cmd(std::move(do_cmd)),
220 undo_cmd(std::move(undo_cmd)),
221 elevated(std::move(elevated)) {
222 }
223
224 explicit prep_cmd_t(std::string &&do_cmd, bool &&elevated):
225 do_cmd(std::move(do_cmd)),
226 elevated(std::move(elevated)) {
227 }
228
229 std::string do_cmd;
230 std::string undo_cmd;
231 bool elevated;
232 };
233
234 struct sunshine_t {
235 std::string locale;
236 int min_log_level;
237 std::bitset<flag::FLAG_SIZE> flags;
238 std::string credentials_file;
239
240 std::string username;
241 std::string password;
242 std::string salt;
243
244 std::string config_file;
245
246 struct cmd_t {
247 std::string name;
248 int argc;
249 char **argv;
250 } cmd;
251
252 std::uint16_t port;
253 std::string address_family;
254
255 std::string log_file;
256 bool notify_pre_releases;
257 std::vector<prep_cmd_t> prep_cmds;
258 };
259
260 extern video_t video;
261 extern audio_t audio;
262 extern stream_t stream;
263 extern nvhttp_t nvhttp;
264 extern input_t input;
265 extern sunshine_t sunshine;
266
267 int parse(int argc, char *argv[]);
268 std::unordered_map<std::string, std::string> parse_config(const std::string_view &file_content);
269} // namespace config
flag_e
Definition config.h:207
@ UPNP
Try Universal Plug 'n Play.
Definition config.h:211
@ FRESH_STATE
Do not load or save state.
Definition config.h:209
@ FLAG_SIZE
Number of flags.
Definition config.h:213
@ PIN_STDIN
Read PIN from stdin instead of http.
Definition config.h:208
@ FORCE_VIDEO_HEADER_REPLACE
force replacing headers inside video data
Definition config.h:210
@ CONST_PIN
Use "universal" pin.
Definition config.h:212
Contains all the functions and variables related to the nvhttp (GameStream) server.
Definition nvhttp.cpp:40
Declarations for NVENC encoder configuration.
Definition config.h:146
Definition config.h:184
Definition config.h:169
Definition config.h:217
Definition config.h:157
Definition config.h:246
Definition config.h:234
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
NVENC encoder configuration.
Definition nvenc_config.h:18