From fcbdaed1e09c2878caa0c00de09fedc0e9da9f35 Mon Sep 17 00:00:00 2001 From: Yukino Song Date: Wed, 15 Jan 2025 09:01:33 +0800 Subject: [PATCH] Fix build (Never wanna merge again) --- src/config.cpp | 3 +- src/confighttp.cpp | 66 +++++-------------- src/nvhttp.cpp | 8 --- src/process.cpp | 37 ++++++++--- src/rtsp.h | 4 ++ src_assets/common/assets/web/apps.html | 14 ++-- src_assets/common/assets/web/config.html | 14 ++-- .../assets/web/configs/tabs/AudioVideo.vue | 22 ++++--- .../assets/web/configs/tabs/General.vue | 26 ++++---- .../tabs/audiovideo/DisplayDeviceOptions.vue | 2 +- .../assets/web/public/assets/locale/en.json | 3 +- .../assets/web/public/assets/locale/zh.json | 3 +- 12 files changed, 93 insertions(+), 109 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index aeb17d80..97f1d28a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -486,8 +486,7 @@ namespace config { {}, // mode_remapping {} // wa }, // display_device - - 1 // min_fps_factor + 1, // min_fps_factor "1920x1080x60", // fallback_mode }; diff --git a/src/confighttp.cpp b/src/confighttp.cpp index d9819288..eade2ff0 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -583,20 +583,11 @@ namespace confighttp { print_req(request); - pt::ptree outputTree; - auto g = util::fail_guard([&]() { - std::ostringstream data; - pt::write_json(data, outputTree); - response->write(data.str()); - }); - auto args = request->parse_query_string(); if ( args.find("uuid"s) == std::end(args) ) { - outputTree.put("status", false); - outputTree.put("error", "Missing a required launch parameter"); - + bad_request(response, request, "Missing a required parameter to delete app"); return; } @@ -619,6 +610,10 @@ namespace confighttp { fileTree.push_back(std::make_pair("apps", newApps)); pt::write_json(config::stream.file_apps, fileTree); + + pt::ptree outputTree; + outputTree.put("status", true); + send_response(response, outputTree); } catch (std::exception &e) { BOOST_LOG(warning) << "DeleteApp: "sv << e.what(); @@ -1019,12 +1014,6 @@ namespace confighttp { pt::ptree outputTree; - auto g = util::fail_guard([&]() { - std::ostringstream data; - pt::write_json(data, outputTree); - response->write(data.str()); - }); - try { auto args = request->parse_query_string(); auto it = args.find("passphrase"); @@ -1049,12 +1038,11 @@ namespace confighttp { outputTree.put("name", config::nvhttp.sunshine_name); outputTree.put("status", true); outputTree.put("message", "OTP created, effective within 3 minutes."); + send_response(response, outputTree); } catch (std::exception &e) { BOOST_LOG(warning) << "OTP creation failed: "sv << e.what(); - outputTree.put("status", false); - outputTree.put("message", e.what()); - return; + bad_request(response, request, e.what()); } } @@ -1069,24 +1057,17 @@ namespace confighttp { pt::ptree inputTree, outputTree; - auto g = util::fail_guard([&]() { - std::ostringstream data; - pt::write_json(data, outputTree); - response->write(data.str()); - }); - try { pt::read_json(ss, inputTree); std::string uuid = inputTree.get("uuid"); std::string name = inputTree.get("name"); auto perm = (crypto::PERM)inputTree.get("perm") & crypto::PERM::_all; outputTree.put("status", nvhttp::update_device_info(uuid, name, perm)); + send_response(response, outputTree); } catch (std::exception &e) { BOOST_LOG(warning) << "Update Client: "sv << e.what(); - outputTree.put("status", false); - outputTree.put("error", e.what()); - return; + bad_request(response, request, e.what()); } } @@ -1155,19 +1136,11 @@ namespace confighttp { pt::ptree outputTree; - auto g = util::fail_guard([&]() { - std::ostringstream data; - pt::write_json(data, outputTree); - response->write(data.str()); - }); - auto args = request->parse_query_string(); if ( args.find("uuid"s) == std::end(args) ) { - outputTree.put("status", false); - outputTree.put("error", "Missing a required launch parameter"); - + bad_request(response, request, "Missing a required launch parameter"); return; } @@ -1190,14 +1163,12 @@ namespace confighttp { auto launch_session = nvhttp::make_launch_session(true, appid, args, &named_cert); auto err = proc::proc.execute(appid, app, launch_session); if (err) { - outputTree.put("status", false); - outputTree.put("error", - err == 503 + bad_request(response, request, err == 503 ? "Failed to initialize video capture/encoding. Is a display connected and turned on?" : "Failed to start the specified application"); - return; } else { outputTree.put("status", true); + send_response(response, outputTree); } return; @@ -1205,8 +1176,7 @@ namespace confighttp { } BOOST_LOG(error) << "Couldn't find app with uuid ["sv << uuid << ']'; - outputTree.put("status", false); - outputTree.put("error", "Cannot find requested application"); + bad_request(response, request, "Cannot find requested application"); } void @@ -1220,12 +1190,6 @@ namespace confighttp { pt::ptree inputTree, outputTree; - auto g = util::fail_guard([&]() { - std::ostringstream data; - pt::write_json(data, outputTree); - response->write(data.str()); - }); - try { pt::read_json(ss, inputTree); std::string uuid = inputTree.get("uuid"); @@ -1233,9 +1197,9 @@ namespace confighttp { } catch (std::exception &e) { BOOST_LOG(warning) << "Disconnect: "sv << e.what(); - outputTree.put("status", false); - outputTree.put("error", e.what()); + bad_request(response, request, e.what()); } + send_response(response, outputTree); } /** diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 05b7fc2e..4731ef0d 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -986,17 +986,12 @@ namespace nvhttp { print_req(request); pt::ptree tree; - bool revert_display_configuration { false }; auto g = util::fail_guard([&]() { std::ostringstream data; pt::write_xml(data, tree); response->write(data.str()); response->close_connection_after_response = true; - - if (revert_display_configuration) { - display_device::revert_configuration(); - } }); auto named_cert_p = get_verified_cert(request); @@ -1084,9 +1079,6 @@ namespace nvhttp { tree.put("root.gamesession", 1); rtsp_stream::launch_session_raise(launch_session); - - // Stream was started successfully, we will revert the config when the app or session terminates - revert_display_configuration = false; } void diff --git a/src/process.cpp b/src/process.cpp index f189c1f3..97e03a7f 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -166,13 +166,6 @@ namespace proc { // Save the original output name in case we modify it temporary later std::string output_name_orig = config::video.output_name; - // Executed when returning from function - auto fg = util::fail_guard([&]() { - // Restore to user defined output name - config::video.output_name = output_name_orig; - terminate(); - }); - _app = app; _app_id = app_id; _launch_session = launch_session; @@ -199,7 +192,19 @@ namespace proc { } #ifdef _WIN32 - if (config::video.headless_mode || launch_session->virtual_display || _app.virtual_display) { + bool create_virtual_display = config::video.headless_mode || launch_session->virtual_display || _app.virtual_display; + + // Executed when returning from function + auto fg = util::fail_guard([&]() { + // Restore to user defined output name + config::video.output_name = output_name_orig; + terminate(); + if (!create_virtual_display) { + display_device::revert_configuration(); + } + }); + + if (create_virtual_display) { if (vDisplayDriverStatus != VDISPLAY::DRIVER_STATUS::OK) { // Try init driver again initVDisplayDriver(); @@ -280,7 +285,19 @@ namespace proc { config::video.output_name = this->display_name; } } + } else { + display_device::configure_display(config::video, *launch_session); } +#else + // Executed when returning from function + auto fg = util::fail_guard([&]() { + // Restore to user defined output name + config::video.output_name = output_name_orig; + terminate(); + display_device::revert_configuration(); + }); + + display_device::configure_display(config::video, *launch_session); #endif // Probe encoders again before streaming to ensure our chosen @@ -419,7 +436,9 @@ namespace proc { // We should have got the actual streaming display by now std::string currentDisplay = this->display_name; - if (!currentDisplay.empty()) { + if (currentDisplay.empty()) { + BOOST_LOG(warning) << "Not getting current display in time! HDR will not be toggled."; + } else { auto currentDisplayW = platf::from_utf8(currentDisplay).c_str(); this->initial_display = currentDisplay; diff --git a/src/rtsp.h b/src/rtsp.h index c5ea11ca..90d59a89 100644 --- a/src/rtsp.h +++ b/src/rtsp.h @@ -11,6 +11,10 @@ #include "crypto.h" #include "thread_safe.h" +#ifdef _WIN32 + #include +#endif + // Resolve circular dependencies namespace stream { struct session_t; diff --git a/src_assets/common/assets/web/apps.html b/src_assets/common/assets/web/apps.html index 589e8451..45cb2717 100644 --- a/src_assets/common/assets/web/apps.html +++ b/src_assets/common/assets/web/apps.html @@ -273,12 +273,13 @@ default="true" > -
- - -
{{ $t('apps.virtual_display_desc') }}
-
+
@@ -399,7 +400,6 @@ import { initApp } from './init' import Navbar from './Navbar.vue' import Checkbox from './Checkbox.vue' - import PlatformLayout from './PlatformLayout.vue' import { Dropdown } from 'bootstrap/dist/js/bootstrap' const newApp = { diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index 93b80257..6b916e3c 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -37,6 +37,7 @@ @@ -135,6 +136,7 @@ config: null, currentTab: "general", vdisplayStatus: "1", + global_prep_cmd: [], server_cmd: [], tabs: [ // TODO: Move the options to each Component instead, encapsulate. { @@ -144,8 +146,8 @@ "locale": "en", "sunshine_name": "", "min_log_level": 2, - "global_prep_cmd": "[]", - "server_cmd": "[]", + "global_prep_cmd": [], + "server_cmd": [], "notify_pre_releases": "disabled", }, }, @@ -362,7 +364,7 @@ this.config.global_prep_cmd = this.config.global_prep_cmd || []; this.config.server_cmd = this.config.server_cmd || []; - this.global_prep_cmd = JSON.parse(this.config.global_prep_cmd); + this.global_prep_cmd = this.config.global_prep_cmd; this.server_cmd = JSON.parse(this.config.server_cmd); }); }, @@ -371,9 +373,6 @@ this.$forceUpdate() }, serialize() { - this.config.global_prep_cmd = JSON.stringify(this.global_prep_cmd.filter(cmd => cmd.do || cmd.undo)); - this.config.server_cmd = JSON.stringify(this.server_cmd.filter(cmd => cmd.name && cmd.cmd)); - // Validate fallback mode if (this.config.fallback_mode && !this.config.fallback_mode.match(/^\d+x\d+x\d+$/)) { this.config.fallback_mode = fallbackDisplayModeCache; @@ -381,8 +380,9 @@ fallbackDisplayModeCache = this.config.fallback_mode; } let config = JSON.parse(JSON.stringify(this.config)); - config.global_prep_cmd = JSON.stringify(config.global_prep_cmd); + config.global_prep_cmd = JSON.stringify(this.global_prep_cmd.filter(cmd => cmd.do || cmd.undo)); config.dd_mode_remapping = JSON.stringify(config.dd_mode_remapping); + config.server_cmd = JSON.stringify(this.server_cmd.filter(cmd => cmd.name && cmd.cmd)); return config; }, save() { diff --git a/src_assets/common/assets/web/configs/tabs/AudioVideo.vue b/src_assets/common/assets/web/configs/tabs/AudioVideo.vue index 877148c1..6da71b63 100644 --- a/src_assets/common/assets/web/configs/tabs/AudioVideo.vue +++ b/src_assets/common/assets/web/configs/tabs/AudioVideo.vue @@ -84,17 +84,19 @@ const validateFallbackMode = (event) => { default="true" > -
- - -
{{ $t('config.keep_sink_default_desc') }}
-
+ -
- - -
{{ $t('config.auto_capture_sink_desc') }}
-
+ diff --git a/src_assets/common/assets/web/configs/tabs/General.vue b/src_assets/common/assets/web/configs/tabs/General.vue index cb6d8510..807a9cae 100644 --- a/src_assets/common/assets/web/configs/tabs/General.vue +++ b/src_assets/common/assets/web/configs/tabs/General.vue @@ -99,7 +99,7 @@ onMounted(() => {
{{ $t('config.global_prep_cmd_desc') }}
- +
@@ -111,7 +111,7 @@ onMounted(() => { - + @@ -191,18 +191,20 @@ onMounted(() => { -
- - -
{{ $t('config.enable_pairing_desc') }}
-
+ -
- - -
{{ $t('config.hide_tray_controls_desc') }}
-
+
{{ $t('_common.do_cmd') }}