Fix: Keep the web remote view alive across resolution and quality changes

Hidden web/MCP screen sessions never receive TOKEN_FIRSTSCREEN and never run
the local decode path, so m_bIsFirst stayed TRUE and every keyframe or scroll
frame after a resolution change was dropped, leaving the browser black. The
same black screen appears whenever the client runs a non-H.264 quality level
(Ultra/DIFF, High/RGB565): DrawNextScreenDiff forwards to the web only inside
the ALGORITHM_H264 branches while the MFC window renders every algorithm, and
the existing web clamp cannot run in fixed-level mode because EvaluateQuality
returns early when adaptive quality is disabled.

Clear m_bIsFirst once an IDR decodes and forward keyframe/nextscreen frames
for hidden web sessions. Clamp web sessions to QUALITY_GOOD in OnInitDialog,
re-push the level when the client reports a lower one in BITMAPINFO, and nudge
a flapping client back to H.264 at most three times. The browser now receives
stream_algorithm/web_supported notices and shows an explicit hint in both the
focus view and the wall instead of a silent black frame. Resolution-change
recovery moved into OnTimer(4) so hidden sessions flush the decoder and request
a fresh IDR too.

Also bound the client-supplied block offsets and scroll parameters in the
DIFF/GRAY/RGB565 decoders, which could otherwise write outside the destination
DIB, and share one keyframe-request throttle between the resolution path and
the web console. Verified with a Debug x64 server build and node --check on the
page script; the Go server does not emit the new notices yet and degrades to
the old behavior.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-10 11:34:07 +01:00
1 parent 5eb44307ee
commit c7e23f750d
5 files changed
+432 -53

No files matched your search

+12
View File
@@ -306,6 +306,14 @@ public:
HIMC m_hOldIMC = NULL; // 保存原始 IME 上下文,控制模式切换时使用
bool m_bHide = false;
std::atomic<bool> m_bIsWebSession{false}; // True if this dialog was created by Web request (atomic for thread safety)
// Web 会话的算法监视:浏览器只能解 H.264,一旦客户端按别的算法推帧(Ultra/DIFF、
// High/RGB565,或 x264 初始化失败的 RGB565 降级),服务端不转发任何视频帧,前端
// 就是一块永久黑屏。这里记住上一帧的算法并在变化时告知前端,同时节流地要求
// 客户端切回 H.264(见 DrawNextScreenDiff)。
int m_nLastWebAlgo = -1;
ULONGLONG m_nLastWebAlgoPush = 0;
int m_nWebQualityNudges = 0; // 本轮已要求客户端切回 H.264 的次数(上限 3 次)
int m_nLastEchoedQuality = -1; // 上次按 BITMAPINFO 上报档位回推的 CMD_QUALITY_LEVEL(去重)
std::string m_strSaveNotice; // 截图保存路径提示
ULONGLONG m_nSaveNoticeTime = 0; // 截图提示开始时间
ULONGLONG m_nLastCursorBroadcast = 0; // 上次向 Web 广播光标的时间(50ms 节流)
@@ -460,6 +468,9 @@ public:
} m_AdaptiveQuality;
volatile bool m_bResolutionChanging = false; // 分辨率切换中,阻止解码
// OnTimer 超时时置位,由解码线程在 Decode() 里消费,避免 UI 线程与
// Decode() 并发调用 avcodec_flush_buffers 访问同一个 AVCodecContext。
std::atomic<bool> m_bNeedFlushDecoder{false};
// ========== 音频播放 ==========
// m_Settings.AudioEnabled 表示是否启用音频(与客户端同步)
@@ -539,6 +550,7 @@ public:
void UpdateQualityMenuCheck(CMenu* SysMenu = nullptr); // 更新质量菜单勾选状态
void OnTimer(UINT_PTR nIDEvent);
void CheckResolutionChangeTimeout(); // 分辨率切换超时兜底,由 OnTimer(4) 驱动
void UpdateWindowTitle();
bool Decode(LPBYTE Buffer, int size);