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