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:
1 parent
d8048979e3
commit
2e34e49186
5 files changed
+77
-27
No files matched your search
@@ -216,7 +216,10 @@ bool CScreenManager::RestartScreen(BOOL switchScreen)
|
||||
// 3. 重新启动工作线程(InitScreenSpy 会创建新对象)
|
||||
m_bIsWorking = TRUE;
|
||||
m_SendFirst = FALSE;
|
||||
m_SwitchScreen = switchScreen;
|
||||
// 只有请求切换时才置位,普通重建(质量档/分辨率/ROI/换窗口)不清除:
|
||||
// 切屏请求要挂起到某次重建真正提交了屏索引为止。否则「切屏后紧跟一个质量档
|
||||
// 调整」会把请求覆盖成 false,截屏对象建好前被顶掉,切换就静默丢了。
|
||||
if (switchScreen) m_SwitchScreen = TRUE;
|
||||
m_hWorkThread = __CreateThread(NULL, 0, WorkThreadProc, this, 0, NULL);
|
||||
return true;
|
||||
}
|
||||
@@ -506,7 +509,12 @@ void CScreenManager::InitScreenSpy()
|
||||
BYTE* user = (BYTE*)m_ptrUser;
|
||||
BOOL all = FALSE;
|
||||
RECT rect = m_ROI;
|
||||
// 「切换显示器」是一次性请求:取用即清除。之后的自适应重启(质量档、分辨率、
|
||||
// ROI、换窗口)一律 switchScreen=false,沿用当前屏。不清除的话,工作线程里
|
||||
// 因窗口尺寸变化触发的原地重建(WorkThreadProc 直接调本函数,不经过
|
||||
// RestartScreen)会把旧请求再消费一次,每重建一次就换一块屏。
|
||||
BOOL switchScreen = m_SwitchScreen;
|
||||
m_SwitchScreen = FALSE;
|
||||
if (!(user == NULL || ((int)user) == 1)) {
|
||||
UserParam* param = (UserParam*)user;
|
||||
if (param && param->length>0) {
|
||||
@@ -543,7 +551,10 @@ void CScreenManager::InitScreenSpy()
|
||||
}
|
||||
// 保存屏幕类型,服务端用于判断是否显示虚拟桌面相关菜单
|
||||
m_ScreenSettings.ScreenType = DXGI;
|
||||
Mprintf("CScreenManager: Type %d Algorithm: %d (QualityLevel=%d)\n", DXGI, int(algo), level);
|
||||
// switch 是本次重建是否要换屏,all 是客户端是否支持多显示器;屏索引变化会打印
|
||||
// 在各后端自己的日志里(CScreenSpy 的 monitor= / DXGI 的 out=)。
|
||||
Mprintf("CScreenManager: Type %d Algorithm: %d (QualityLevel=%d) switch=%d all=%d\n",
|
||||
DXGI, int(algo), level, (int)switchScreen, (int)all);
|
||||
if (DXGI == USING_VIRTUAL) {
|
||||
m_virtual = TRUE;
|
||||
HDESK hDesk = SelectDesktop((char*)m_DesktopID.c_str());
|
||||
@@ -1138,10 +1149,13 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
m_ScreenSettings.MaxFPS = profile.maxFPS;
|
||||
bool needRestart = false;
|
||||
if (m_ScreenSpyObject) {
|
||||
// 如果当前是 H264 且码率变化,需要重启以重新创建编码器
|
||||
// 码率变化要重建编码器,但只在「目标档位仍是 H264」时才有意义:
|
||||
// 换到 RGB565/DIFF 的档位根本不用码率(profile.bitRate=0),
|
||||
// 为一次 3000→0 重启截屏纯属白丢一个 IDR(还连带重建抓屏对象)。
|
||||
bool isH264 = (m_ScreenSpyObject->GetAlgorithm() == ALGORITHM_H264);
|
||||
bool staysH264 = (profile.algorithm == ALGORITHM_H264);
|
||||
bool bitRateChanged = m_ScreenSpyObject->SetBitRate(profile.bitRate);
|
||||
if (isH264 && bitRateChanged) {
|
||||
if (isH264 && staysH264 && bitRateChanged) {
|
||||
needRestart = true;
|
||||
}
|
||||
m_ScreenSpyObject->SetAlgorithm(profile.algorithm);
|
||||
|
||||
Reference in new issue
Block a user