Skip to content

Commit

Permalink
refactor: resolution and fps setting for vdd
Browse files Browse the repository at this point in the history
  • Loading branch information
qiin2333 committed Aug 23, 2024
1 parent a40ba6b commit 484bc6e
Show file tree
Hide file tree
Showing 13 changed files with 681 additions and 521 deletions.
16 changes: 12 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,28 @@ namespace config {
"sunshine_state.json"s, // file_state
{}, // external_ip
{
"352x240"s,
"480x360"s,
"858x480"s,
"1280x720"s,
"1920x1080"s,
"2560x1080"s,
"2560x1440"s,
"2560x1600"s,
"3440x1440"s,
"1920x1200"s,
"3840x2160"s,
"3840x1600"s,
"2316x1080"s,
"2340x1080"s,
"2388x1668"s,
"2480x1116"s,
"2670x1200"s,
"2800x1260"s,
"2880x1920"s,
"3200x1440"s,
"5120x2880"s,
"7680x4320"s,
}, // supported resolutions

{ 10, 30, 60, 90, 120 }, // supported fps
{ 30, 60, 90, 120, 165, 240 }, // supported fps
};

input_t input {
Expand Down
59 changes: 56 additions & 3 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "config.h"
#include "confighttp.h"
#include "crypto.h"
#include "src/display_device/display_device.h"
#include "src/display_device/to_string.h"
#include "display_device/session.h"
#include "file_handler.h"
#include "globals.h"
Expand All @@ -39,6 +37,8 @@
#include "nvhttp.h"
#include "platform/common.h"
#include "rtsp.h"
#include "src/display_device/display_device.h"
#include "src/display_device/to_string.h"
#include "utility.h"
#include "uuid.h"
#include "version.h"
Expand Down Expand Up @@ -597,6 +597,18 @@ namespace confighttp {
outputTree.put("locale", config::sunshine.locale);
}

std::vector<std::string>
split(const std::string &str, char delimiter) {
std::vector<std::string> tokens;
size_t start = 0, end = 0;
while ((end = str.find(delimiter, start)) != std::string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}

void
saveConfig(resp_https_t response, req_https_t request) {
if (!authenticate(response, request)) return;
Expand All @@ -613,17 +625,58 @@ namespace confighttp {
pt::write_json(data, outputTree);
response->write(data.str());
});

std::string idd_option_path = "c:\\IddSampleDriver\\vdd_settings.xml";
pt::ptree iddOptionTree;
pt::ptree resolutions_nodes;

pt::ptree inputTree;

try {
// TODO: Input Validation
pt::read_json(ss, inputTree);
std::string fpsArray = inputTree.get<std::string>("fps", "[]");

for (const auto &kv : inputTree) {
std::string value = inputTree.get<std::string>(kv.first);
if (value.length() == 0 || value.compare("null") == 0) continue;

// prepare resolutions setting for vdd
if (kv.first.compare("resolutions") == 0) {
boost::regex pattern("\\[|\\]|\\s+");
char delimiter = ',';
std::string str = boost::regex_replace(value, pattern, "");
boost::algorithm::trim(str);
for (const auto &resolution : split(str, delimiter)) {
auto index = resolution.find("x", 0);
pt::ptree res_node;
res_node.put("width", resolution.substr(0, index));
res_node.put("height", resolution.substr(index + 1));
for (const auto &fps : split(boost::regex_replace(fpsArray, pattern, ""), delimiter)) {
res_node.add("refresh_rate", fps);
}
resolutions_nodes.push_back(std::make_pair("resolution"s, res_node));
}
}
configStream << kv.first << " = " << value << std::endl;
}
file_handler::write_file(config::sunshine.config_file.c_str(), configStream.str());

if (fs::exists(idd_option_path)) {
pt::ptree monitor_node;
monitor_node.put("count", 1);

pt::ptree gpu_node;
gpu_node.put("friendlyname", inputTree.get<std::string>("adapter_name", ""));

iddOptionTree.add_child("monitors", monitor_node);
iddOptionTree.add_child("gpu", gpu_node);
iddOptionTree.add_child("resolutions", resolutions_nodes);

pt::ptree root;
root.add_child("vdd_settings", iddOptionTree);
auto setting = boost::property_tree::xml_writer_make_settings<std::string>('\t', 1);
write_xml(idd_option_path, root, std::locale(), setting);
}
}
catch (std::exception &e) {
BOOST_LOG(warning) << "SaveConfig: "sv << e.what();
Expand Down
2 changes: 1 addition & 1 deletion src/display_device/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace display_device {

// display_device::w_utils::togglePnpDeviceByFriendlyName("Generic Monitor (IDD HDR)", true);
// BOOST_LOG(info) << "Enable IDD...";
Sleep(1000);
Sleep(1500);
return settings.revert_settings();
});
}
Expand Down
Loading

0 comments on commit 484bc6e

Please sign in to comment.