Skip to content

Commit

Permalink
feat: 为客户端指定并应用不同的HDR校准文件
Browse files Browse the repository at this point in the history
  • Loading branch information
qiin2333 committed Nov 8, 2024
1 parent 405342b commit f9b6aa6
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 212 deletions.
7 changes: 6 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{}
{
"printWidth": 120,
"semi": false,
"singleQuote": true,
"prettier.spaceBeforeFunctionParen": true
}
4 changes: 3 additions & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ namespace config {
true, // nv_realtime_hags
true, // nv_opengl_vulkan_on_dxgi
true, // nv_sunshine_high_power_mode
false, // preferUseVdd
false, // preferUseVdd
{}, // nv_legacy

{
Expand Down Expand Up @@ -424,6 +424,7 @@ namespace config {
CERTIFICATE_FILE,

boost::asio::ip::host_name(), // sunshine_name,
"[]",
"sunshine_state.json"s, // file_state
{}, // external_ip
{
Expand Down Expand Up @@ -1105,6 +1106,7 @@ namespace config {
path_f(vars, "pkey", nvhttp.pkey);
path_f(vars, "cert", nvhttp.cert);
string_f(vars, "sunshine_name", nvhttp.sunshine_name);
string_f(vars, "clients", nvhttp.clients);
path_f(vars, "log_path", config::sunshine.log_file);
path_f(vars, "file_state", nvhttp.file_state);

Expand Down
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ namespace config {
std::string cert;

std::string sunshine_name;

std::string clients;

std::string file_state;

Expand Down
9 changes: 9 additions & 0 deletions src/display_device/display_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,13 @@ namespace display_device {
bool
set_topology(const active_topology_t &new_topology);

/**
* @brief Apply the HDR profile to the specified client.
* @param client_name Name of the client to apply the HDR profile to.
* @returns True if the HDR profile has been applied, false otherwise.
*
*/
bool
apply_hdr_profile(const std::string &client_name);

} // namespace display_device
2 changes: 1 addition & 1 deletion src/display_device/parsed_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <cmath>

// local includes
#include "src/globals.h"
#include "display_device.h"
#include "parsed_config.h"
#include "session.h"
#include "src/config.h"
#include "src/globals.h"
#include "src/logging.h"
#include "src/rtsp.h"
#include "to_string.h"
Expand Down
4 changes: 4 additions & 0 deletions src/display_device/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ namespace display_device {
config.device_id = device_zako;
config::video.output_name = device_zako;

if (session.enable_hdr) {
display_device::apply_hdr_profile(session.client_name);
}

// 解决热切换可能造成的HDR映射异常
if (should_reset_zako_hdr && session.enable_hdr) {
std::thread { [this, device_zako]() {
Expand Down
2 changes: 2 additions & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ namespace nvhttp {
x++;
}
launch_session->unique_id = (get_arg(args, "uniqueid", "unknown"));
launch_session->client_name = util::from_view(get_arg(args, "clientname", "unknown"));
launch_session->appid = util::from_view(get_arg(args, "appid", "unknown"));
launch_session->enable_sops = util::from_view(get_arg(args, "sops", "0"));
launch_session->surround_info = util::from_view(get_arg(args, "surroundAudioInfo", "196610"));
Expand Down Expand Up @@ -381,6 +382,7 @@ namespace nvhttp {

launch_session->env["SUNSHINE_CLIENT_ID"] = std::to_string(launch_session->id);
launch_session->env["SUNSHINE_CLIENT_UNIQUE_ID"] = launch_session->unique_id;
launch_session->env["SUNSHINE_CLIENT_NAME"] = launch_session->client_name;
launch_session->env["SUNSHINE_CLIENT_WIDTH"] = std::to_string(launch_session->width);
launch_session->env["SUNSHINE_CLIENT_HEIGHT"] = std::to_string(launch_session->height);
launch_session->env["SUNSHINE_CLIENT_FPS"] = std::to_string(launch_session->fps);
Expand Down
52 changes: 52 additions & 0 deletions src/platform/windows/display_device/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// standard includes
#include <codecvt>
#include <fstream>
#include <thread>
#include <iostream>
#include <windows.h>
#include <icm.h>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

// local includes
#include "settings_topology.h"
Expand All @@ -13,6 +21,8 @@

namespace display_device {

namespace pt = boost::property_tree;

struct settings_t::persistent_data_t {
topology_pair_t topology; /**< Contains topology before the modification and the one we modified. */
std::string original_primary_display; /**< Original primary display in the topology we modified. Empty value if we didn't modify it. */
Expand Down Expand Up @@ -556,6 +566,48 @@ namespace display_device {

settings_t::~settings_t() = default;

bool
apply_hdr_profile(const std::string &client_name) {
pt::ptree clientArray;
std::stringstream ss(config::nvhttp.clients);
read_json(ss, clientArray);

std::string profile_name;
for (const auto &client : clientArray) {
if (client.second.get<std::string>("name") == client_name) {
profile_name = client.second.get<std::string>("hdrProfile");
break;
}
}

auto display_data { w_utils::query_display_config(w_utils::ACTIVE_ONLY_DEVICES) };
if (!display_data) return false;

const auto path { w_utils::get_active_path(config::video.output_name, display_data->paths) };
if (!path) return false;

std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::wstring wsProfileName = converter.from_bytes(profile_name);

HRESULT hr;
WCS_PROFILE_MANAGEMENT_SCOPE scope = WCS_PROFILE_MANAGEMENT_SCOPE_CURRENT_USER;
PCWSTR profileName = wsProfileName.c_str();
LUID targetAdapterID = path->targetInfo.adapterId;
UINT32 sourceID = 0;
BOOL setAsDefault = TRUE;
BOOL associateAsAdvancedColor = TRUE;

hr = ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor);
if (hr == S_OK) {
wprintf(L"色彩配置文件与显示设备关联成功。\n");
}
else {
wprintf(L"关联失败,错误码: 0x%x\n", hr);
BOOST_LOG(error) << "Fail to apply hdr profile: ";
}
return 0;
}

bool
settings_t::is_changing_settings_going_to_fail() const {
return w_utils::is_user_session_locked() || w_utils::test_no_access_to_ccd_api();
Expand Down
1 change: 1 addition & 0 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ namespace proc {
// Add Stream-specific environment variables
_env["SUNSHINE_APP_ID"] = std::to_string(_app_id);
_env["SUNSHINE_APP_NAME"] = _app.name;
_env["SUNSHINE_CLIENT_NAME"] = launch_session->client_name;
_env["SUNSHINE_CLIENT_WIDTH"] = std::to_string(launch_session->width);
_env["SUNSHINE_CLIENT_HEIGHT"] = std::to_string(launch_session->height);
_env["SUNSHINE_CLIENT_FPS"] = std::to_string(launch_session->fps);
Expand Down
1 change: 1 addition & 0 deletions src/rtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace rtsp_stream {

bool host_audio;
std::string unique_id;
std::string client_name;
int width;
int height;
int fps;
Expand Down
4 changes: 4 additions & 0 deletions src_assets/common/assets/web/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ <h4>{{ $t('apps.env_vars_about') }}</h4>
<td style="font-family: monospace">SUNSHINE_APP_NAME</td>
<td>{{ $t('apps.env_app_name') }}</td>
</tr>
<tr>
<td style="font-family: monospace">SUNSHINE_CLIENT_NAME</td>
<td>{{ $t('apps.env_client_name') }}</td>
</tr>
<tr>
<td style="font-family: monospace">SUNSHINE_CLIENT_WIDTH</td>
<td>{{ $t('apps.env_client_width') }}</td>
Expand Down
1 change: 1 addition & 0 deletions src_assets/common/assets/web/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"env_var_name": "Var Name",
"env_app_id": "App ID",
"env_app_name": "App Name",
"env_client_name": "Client friendly name (string)",
"env_client_width": "The Width requested by the client (int)",
"env_client_height": "The Height requested by the client (int)",
"env_client_fps": "The FPS requested by the client (int)",
Expand Down
Loading

0 comments on commit f9b6aa6

Please sign in to comment.