Skip to content

Commit 648d891

Browse files
committed
fix: vdd 就绪检测放宽
1 parent 15f66a5 commit 648d891

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

src/display_device/parsed_config.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,23 @@ namespace display_device {
538538
boost::optional<parsed_config_t>
539539
make_parsed_config(const config::video_t &config, const rtsp_stream::launch_session_t &session, bool is_reconfigure) {
540540
parsed_config_t parsed_config;
541-
parsed_config.device_id = config.output_name;
541+
542+
// 优先使用客户端指定的显示器名称,如果没有则使用全局配置
543+
std::string device_id_to_use = config.output_name;
544+
if (auto it = session.env.find("SUNSHINE_CLIENT_DISPLAY_NAME"); it != session.env.end()) {
545+
const std::string client_display_name = it->to_string();
546+
if (!client_display_name.empty()) {
547+
device_id_to_use = client_display_name;
548+
BOOST_LOG(debug) << "使用客户端指定的显示器: " << device_id_to_use;
549+
}
550+
}
551+
552+
parsed_config.device_id = device_id_to_use;
542553
parsed_config.device_prep = static_cast<parsed_config_t::device_prep_e>(config.display_device_prep);
543554
parsed_config.change_hdr_state = parse_hdr_option(config, session);
544555

545556
const int custom_screen_mode = session.custom_screen_mode;
557+
546558
// 客户端自定义屏幕模式
547559
if (custom_screen_mode != -1) {
548560
BOOST_LOG(debug) << "客户端自定义屏幕模式: "sv << custom_screen_mode;
@@ -577,9 +589,9 @@ namespace display_device {
577589
<< "\n刷新率: "sv << (parsed_config.refresh_rate ? to_string(*parsed_config.refresh_rate) : "不变")
578590
<< "\n"sv;
579591

580-
// 检查是否需要使用VDD
581-
const auto requested_device_id = display_device::find_one_of_the_available_devices(config.output_name);
582-
const bool is_vdd_device = (display_device::get_display_friendly_name(config.output_name) == ZAKO_NAME);
592+
// 检查是否需要使用VDD(使用解析后的 device_id,可能是客户端指定的显示器)
593+
const auto requested_device_id = display_device::find_one_of_the_available_devices(parsed_config.device_id);
594+
const bool is_vdd_device = (display_device::get_display_friendly_name(parsed_config.device_id) == ZAKO_NAME);
583595

584596
// 如果会话不需要VDD且指定设备存在且不是VDD设备,则跳过VDD准备
585597
if (!session.use_vdd && !requested_device_id.empty() && !is_vdd_device) {

src/display_device/session.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ namespace display_device {
150150
session_t::clear_vdd_state() {
151151
current_vdd_client_id.clear();
152152
last_vdd_setting.clear();
153+
// 恢复原始的 output_name,避免下一个会话使用已销毁的 VDD 设备 ID
154+
if (!original_output_name.empty()) {
155+
config::video.output_name = original_output_name;
156+
original_output_name.clear();
157+
BOOST_LOG(debug) << "已恢复原始 output_name: " << config::video.output_name;
158+
}
153159
}
154160

155161
void
@@ -182,17 +188,12 @@ namespace display_device {
182188
}
183189

184190
/**
185-
* @brief Wait for VDD device to initialize and be fully ready.
191+
* @brief Wait for VDD device to be available (active or inactive).
186192
* @param device_zako Output parameter for the device ID.
187193
* @param max_attempts Maximum number of retry attempts.
188194
* @param initial_delay Initial delay between retries.
189195
* @param max_delay Maximum delay between retries.
190-
* @return true if device was found and is ready, false otherwise.
191-
*
192-
* This function checks multiple conditions to ensure the VDD device is fully ready:
193-
* 1. Device can be found by friendly name
194-
* 2. Device is in the active device list
195-
* 3. Device has a valid source mode (can be queried for display configuration)
196+
* @return true if device was found (active or inactive), false otherwise.
196197
*/
197198
bool
198199
wait_for_vdd_device(std::string &device_zako, int max_attempts,
@@ -202,26 +203,19 @@ namespace display_device {
202203
[&device_zako]() {
203204
device_zako = display_device::find_device_by_friendlyname(ZAKO_NAME);
204205
if (device_zako.empty()) {
206+
BOOST_LOG(debug) << "VDD device not found by friendly name";
205207
return false;
206208
}
207209

208-
const auto display_data = w_utils::query_display_config(w_utils::ACTIVE_ONLY_DEVICES);
209-
if (!display_data) {
210-
return false;
211-
}
212-
213-
const auto path = w_utils::get_active_path(device_zako, display_data->paths);
214-
if (!path) {
215-
return false;
216-
}
217-
218-
const auto source_index = w_utils::get_source_index(*path, display_data->modes);
219-
return source_index && w_utils::get_source_mode(source_index, display_data->modes);
210+
// Device found by friendly name - that's all we need
211+
// It can be activated later during display configuration
212+
BOOST_LOG(debug) << "VDD device found: " << device_zako;
213+
return true;
220214
},
221215
{ .max_attempts = max_attempts,
222216
.initial_delay = initial_delay,
223217
.max_delay = max_delay,
224-
.context = "等待VDD设备初始化并完全就绪" });
218+
.context = "Waiting for VDD device availability" });
225219
}
226220

227221
/**
@@ -388,7 +382,7 @@ namespace display_device {
388382
if (device_zako.empty()) {
389383
BOOST_LOG(info) << "创建虚拟显示器...";
390384
vdd_utils::create_vdd_monitor(current_client_id, hdr_brightness, physical_size);
391-
std::this_thread::sleep_for(233ms);
385+
std::this_thread::sleep_for(500ms);
392386
}
393387

394388
// Wait for device to be ready
@@ -408,6 +402,11 @@ namespace display_device {
408402
return;
409403
}
410404

405+
if (original_output_name.empty()) {
406+
original_output_name = config::video.output_name;
407+
BOOST_LOG(debug) << "保存原始 output_name: " << original_output_name;
408+
}
409+
411410
// Update configuration and state
412411
config.device_id = device_zako;
413412
config::video.output_name = device_zako;

src/display_device/session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ namespace display_device {
231231
std::mutex mutex; /**< A mutex for ensuring thread-safety. */
232232
std::string last_vdd_setting; /**< Last VDD resolution and refresh rate setting. */
233233
std::string current_vdd_client_id; /**< Current client ID associated with VDD monitor. */
234+
std::string original_output_name; /**< Original output_name value before VDD device ID was set. */
234235

235236
/**
236237
* @brief An instance of StateRetryTimer.

0 commit comments

Comments
 (0)