Fix: Keep the captured monitor stable across restarts

GDI and DXGI each kept their own static monitor index, and DXGI
committed the index before its initialization had succeeded. When a
quality change restarted capture and DXGI fell back to GDI, the next
DXGI attempt read the failed attempt's index and jumped to the other
monitor. Both backends now share one process-wide index with separate
peek and commit steps, and the commit only happens after the backend
is actually up.

Manual switching is made a one-shot request: InitScreenSpy consumes
the flag and RestartScreen only sets it, so an adaptive restart that
lands in the middle of a switch no longer drops the request or
re-applies it on every later rebuild. Window capture no longer
touches the index at all, so leaving window mode returns to the
monitor that was on screen.

Also: restart capture on a bitrate change only when the target level
is still H.264 (switching to RGB565/DIFF never uses the bitrate), and
bound the DXGI output fallback so a session without any enumerable
output cannot spin forever in InitDXGI.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-08 20:44:49 +01:00
1 parent d8048979e3
commit 2e34e49186
5 files changed
+77 -27

No files matched your search

+2
View File
@@ -71,6 +71,8 @@ public:
RECT m_ROI = {0};
HWND m_hTargetWnd = NULL; // 窗口捕获目标(NULL=全屏)
bool m_bDynamicForeground = false; // true=每帧自动跟踪前景窗口(HWND sentinel=-1触发)
// 挂起的「切换显示器」请求:InitScreenSpy 取用一次即清除,只有 SwitchScreen()
// 会把它重新置位。为 TRUE 时下一次建截屏对象前进一格屏索引,否则沿用当前屏。
BOOL m_SwitchScreen = TRUE;
BOOL SendClientClipboard(BOOL fast);
VOID UpdateClientClipboard(char *szBuffer, ULONG ulLength);