Feature: Add window/region capture targets to remote_open
Pass the target HWND through the COMMAND_SCREEN_SPY token and send COMMAND_SCREEN_ROI after session start, so MCP remote control can stream just the target window or region instead of the scaled virtual desktop. The session records the target kind, remote_mouse refuses a redundant window_hwnd basis, and the cached resolution is refreshed per action so resized windows keep mapping correctly. Cold starts now clear the stale resolution cache used by the region handshake.
This commit is contained in:
1 parent
5501889d33
commit
cdd9c56b3d
7 files changed
+445
-39
No files matched your search
@@ -2475,7 +2475,7 @@ void CWebService::NotifyClipboardText(uint64_t device_id, const std::string& tex
|
||||
}
|
||||
}
|
||||
|
||||
bool CWebService::StartRemoteDesktop(uint64_t device_id, bool forceVirtualDesktop) {
|
||||
bool CWebService::StartRemoteDesktop(uint64_t device_id, bool forceVirtualDesktop, uint32_t windowHwnd) {
|
||||
if (!m_pParentDlg) return false;
|
||||
|
||||
context* ctx = m_pParentDlg->FindHost(device_id);
|
||||
@@ -2510,13 +2510,17 @@ bool CWebService::StartRemoteDesktop(uint64_t device_id, bool forceVirtualDeskto
|
||||
// This creates a new hidden Web dialog while MFC dialog remains visible
|
||||
|
||||
// Cold start: drop any stale IDR cached from a previous capture session, it
|
||||
// may have a different resolution / encoder instance.
|
||||
// may have a different resolution / encoder instance. Also invalidate the
|
||||
// cached resolution so remote_open cannot mistake the previous session's
|
||||
// size for this one's (window/region captures change it).
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_DeviceCacheMutex);
|
||||
auto it = m_DeviceCache.find(device_id);
|
||||
if (it != m_DeviceCache.end()) {
|
||||
std::lock_guard<std::mutex> cache_lock(it->second->cache_mutex);
|
||||
it->second->keyframe_cache.clear();
|
||||
it->second->screen_width = 0;
|
||||
it->second->screen_height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2525,11 +2529,19 @@ bool CWebService::StartRemoteDesktop(uint64_t device_id, bool forceVirtualDeskto
|
||||
bToken[1] = 0; // DXGI mode: 0=GDI
|
||||
bToken[2] = ALGORITHM_H264; // H264 algorithm
|
||||
bToken[3] = 1; // Multi-screen: true
|
||||
// 参数 buffer[11](wire 索引 12):强制抓整个虚拟桌面。客户端把 token 剥掉命令字节后
|
||||
// 按 buffer[i]=bToken[i+1] 索引,且 buffer[3..10](wire [4..11])是 HWND,
|
||||
// 不能占用。老客户端会忽略该字节,服务端只在客户端声明
|
||||
// CLIENT_CAP_VIRTUAL_DESKTOP 时置位。
|
||||
bToken[12] = forceVirtualDesktop ? 1 : 0;
|
||||
if (windowHwnd) {
|
||||
// 只推目标窗口(MCP remote_open window_hwnd):客户端按 wire [4..11] 的 HWND
|
||||
// 进入窗口捕获,用 DWM 可见边框作为帧尺寸、窗口原点作为注入坐标原点;窗口
|
||||
// 捕获强制 GDI,且与屏索引/虚拟桌面无关,所以不再置 forceVirtual([12])。
|
||||
uint64_t hwnd64 = windowHwnd;
|
||||
memcpy(bToken + 4, &hwnd64, sizeof(uint64_t));
|
||||
} else {
|
||||
// 参数 buffer[11](wire 索引 12):强制抓整个虚拟桌面。客户端把 token 剥掉命令字节后
|
||||
// 按 buffer[i]=bToken[i+1] 索引,且 buffer[3..10](wire [4..11])是 HWND,
|
||||
// 不能占用。老客户端会忽略该字节,服务端只在客户端声明
|
||||
// CLIENT_CAP_VIRTUAL_DESKTOP 时置位。
|
||||
bToken[12] = forceVirtualDesktop ? 1 : 0;
|
||||
}
|
||||
|
||||
return ctx->Send2Client(bToken, sizeof(bToken)) != FALSE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user