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