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

+13
View File
@@ -116,10 +116,19 @@ struct WebDeviceInfo {
std::string client_type; // RES_CLIENT_TYPE: "APK"=Android, "EXE"=Windows, "LNX"=Linux, "MAC"=macOS
// 当前会话的音频开关。-1=未知(客户端 BITMAPINFO 还没回来),0=关,1=开
int audio_enabled = -1;
// 客户端当前视频算法(ALGORITHM_*)。-1=未知(还没收到第一帧)。浏览器只解 H.264,
// 非 H.264 时服务端不转发视频帧,新加入的浏览器要靠 connect_result 里带出去的
// web_supported 才知道该提示什么(见 NotifyStreamAlgorithm)。
int stream_algo = -1;
// Keyframe cache for new web clients
std::vector<uint8_t> keyframe_cache;
std::mutex cache_mutex;
// 上次因分辨率变化向客户端请求新 IDR 的时间(GetTickCount64)。
// 快速重连/连续 TOKEN_BITMAPINFO 会在一秒内多次触发通知,按设备节流
// 避免连续强制多帧 IDR;RegisterScreenContext 会清零,新会话首包不受
// 上一会话的时间戳影响。由 m_DeviceCacheMutex 保护。
uint64_t last_keyframe_req_ms = 0;
WebDeviceInfo() : id(0), screen_width(0), screen_height(0), online(false) {}
};
@@ -159,6 +168,10 @@ public:
// Resolution change notification
void NotifyResolutionChange(uint64_t device_id, int width, int height, bool top_down = false, const std::string& client_type = "");
// 当前视频算法(ALGORITHM_*)变化通知。浏览器只解 H.264:非 H.264 时服务端不转发
// 任何视频帧,前端需要据此给出明确提示,而不是一直等一块黑屏。
void NotifyStreamAlgorithm(uint64_t device_id, int algo);
// 读回 NotifyResolutionChange 缓存的物理捕获分辨率(来自 TOKEN_BITMAPINFO)。
// 尚未收到分辨率时返回 false 并置 w/h 为 0。MCP 远程控制(remote_open)用它映射归一化坐标。
bool GetScreenSize(uint64_t device_id, int& width, int& height);