Skip to content

Commit

Permalink
优化虚拟屏幕是否常驻的逻辑
Browse files Browse the repository at this point in the history
qiin2333 committed Sep 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent cdb2593 commit 4375d8a
Showing 4 changed files with 59 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/display_device/display_device.h
Original file line number Diff line number Diff line change
@@ -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.
32 changes: 24 additions & 8 deletions src/display_device/session.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}

4 changes: 2 additions & 2 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions src/platform/windows/display_device/general_functions.cpp
Original file line number Diff line number Diff line change
@@ -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()) {

0 comments on commit 4375d8a

Please sign in to comment.