From 4375d8a95fc44988444a51b4e5f895d23d2d585d Mon Sep 17 00:00:00 2001 From: qiin2333 <414382190@qq.com> Date: Tue, 10 Sep 2024 11:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=99=9A=E6=8B=9F=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E6=98=AF=E5=90=A6=E5=B8=B8=E9=A9=BB=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/display_device/display_device.h | 3 ++ src/display_device/session.cpp | 32 ++++++++++++++----- src/nvhttp.cpp | 4 +-- .../display_device/general_functions.cpp | 30 +++++++++++++++++ 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/display_device/display_device.h b/src/display_device/display_device.h index b6c1c80cd38..17ef25f2d22 100644 --- a/src/display_device/display_device.h +++ b/src/display_device/display_device.h @@ -144,6 +144,9 @@ namespace display_device { std::string get_display_name(const std::string &device_id); + std::string + get_display_friendly_name(const std::string &device_id); + /** * @brief Get current display modes for the devices. * @param device_ids A list of devices to get the modes for. diff --git a/src/display_device/session.cpp b/src/display_device/session.cpp index b656f96b5cc..3b5ad22370b 100644 --- a/src/display_device/session.cpp +++ b/src/display_device/session.cpp @@ -160,7 +160,7 @@ namespace display_device { return; } - if (config.preferUseVdd || display_device::get_display_name(config::video.output_name) == "VDD by MTT") { + if (config.preferUseVdd || display_device::get_display_friendly_name(config::video.output_name) == "VDD by MTT") { session_t::get().prepare_vdd(*parsed_config); } @@ -270,24 +270,40 @@ namespace display_device { void session_t::prepare_vdd(const parsed_config_t &config) { + auto devices { display_device::enum_available_devices() }; + bool isVddAvailable { false }; + if (!devices.empty()) { + const auto device_it { std::find_if(std::begin(devices), std::end(devices), [&](const auto &entry) { + return entry.first == config.device_id; + }) }; + if (device_it != std::end(devices)) { + isVddAvailable = true; + } + } + std::stringstream new_setting; new_setting << to_string(*config.resolution) << "x" << to_string(*config.refresh_rate); + BOOST_LOG(info) << "last_vdd_setting/new_setting: "sv << display_device::session_t::get().last_vdd_setting << "/" << new_setting.str(); if (display_device::session_t::get().last_vdd_setting != new_setting.str()) { std::stringstream resolutions; std::stringstream fps; resolutions << "[1920x1080," << to_string(*config.resolution) << "]"; fps << "[60," << to_string(*config.refresh_rate) << "]"; - if (display_device::is_primary_device(config.device_id)) { - display_device::session_t::get().disable_vdd(); - // std::this_thread::sleep_for(std::chrono::milliseconds(1500)); - } - confighttp::saveVddSettings(resolutions.str(), fps.str(), config::video.adapter_name); BOOST_LOG(info) << "Set Client request res to VDD: "sv << new_setting.str() << " ."sv; display_device::session_t::get().last_vdd_setting = new_setting.str(); - display_device::session_t::get().disable_vdd(); - // std::this_thread::sleep_for(std::chrono::milliseconds(4500)); + + if (isVddAvailable) { + display_device::session_t::get().disable_vdd(); + Sleep(3000); + } + display_device::session_t::get().enable_vdd(); + Sleep(3000); + } + else if (!isVddAvailable) { + display_device::session_t::get().enable_vdd(); + Sleep(3000); } } diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index e32ac0587ad..c4fc7b4caf9 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -47,6 +47,7 @@ namespace nvhttp { namespace pt = boost::property_tree; crypto::cert_chain_t cert_chain; + std::string last_vdd_setting; class SunshineHTTPS: public SimpleWeb::HTTPS { public: @@ -1067,7 +1068,6 @@ namespace nvhttp { return; } } - auto encryption_mode = net::encryption_mode_for_address(request->remote_endpoint().address()); if (!launch_session->rtsp_cipher && encryption_mode == config::ENCRYPTION_MODE_MANDATORY) { BOOST_LOG(error) << "Rejecting client that cannot comply with mandatory encryption requirement"sv; @@ -1125,7 +1125,7 @@ namespace nvhttp { #ifdef _WIN32 auto devices { display_device::enum_available_devices() }; if (config::video.preferUseVdd && devices.size() > 1) { - Sleep(1000); + Sleep(2500); display_device::session_t::get().disable_vdd(); } #endif diff --git a/src/platform/windows/display_device/general_functions.cpp b/src/platform/windows/display_device/general_functions.cpp index 0e2cf06e6f2..8d89fffb07a 100644 --- a/src/platform/windows/display_device/general_functions.cpp +++ b/src/platform/windows/display_device/general_functions.cpp @@ -35,6 +35,36 @@ namespace display_device { return display_name; } + std::string + get_display_friendly_name(const std::string &device_id) { + if (device_id.empty()) { + // Valid return, no error + return {}; + } + + const auto display_data { w_utils::query_display_config(w_utils::ALL_DEVICES) }; + if (!display_data) { + // Error already logged + return {}; + } + + const auto path { std::find_if(std::begin(display_data->paths), std::end(display_data->paths), [&](const auto &entry) { + return w_utils::get_device_info_for_valid_path(entry, w_utils::ALL_DEVICES)->device_id == device_id; + }) }; + if (path == std::end(display_data->paths)) { + // Debug level, because inactive device is valid case for this function + BOOST_LOG(debug) << "Failed to find device for " << device_id << "!"; + return {}; + } + + const auto display_friendly_name { w_utils::get_friendly_name(*path) }; + if (display_friendly_name.empty()) { + BOOST_LOG(error) << "Device " << device_id << " has no display name assigned."; + } + + return display_friendly_name; + } + bool is_primary_device(const std::string &device_id) { if (device_id.empty()) {