fix: 移除服务端黑帧自动切换无障碍截图模式逻辑

- 连续黑帧不再发送captureMode:accessibility指令给安卓端
- 黑帧计数仅用于日志统计,不触发模式切换
- 避免服务端误判导致安卓端回退到低帧率无障碍截图
This commit is contained in:
wdvipa
2026-02-15 19:21:23 +08:00
parent 10028a0e2e
commit f62d7ff687
3 changed files with 9 additions and 47 deletions

View File

@@ -546,52 +546,21 @@ export class MessageRouter {
if (dataSize > 0 && dataSize < MIN_VALID_FRAME_SIZE) {
this.droppedFrames++
// 追踪连续黑帧数
// 追踪连续黑帧数(仅记录日志,不触发模式切换)
const deviceId = screenData.deviceId
const count = (this.consecutiveBlackFrames.get(deviceId) || 0) + 1
this.consecutiveBlackFrames.set(deviceId, count)
if (this.routedFrames % 100 === 0) {
this.logger.warn(`⚠️ 过滤黑屏帧: ${dataSize} 字符 < ${MIN_VALID_FRAME_SIZE}, 设备${deviceId}, 连续黑帧${count}, 已丢弃${this.droppedFrames}`)
}
// ✅ 连续50个黑帧后通知Android端切换到无障碍截图模式
if (count >= 50 && !this.captureModeSwitchSent.has(deviceId)) {
this.captureModeSwitchSent.add(deviceId)
this.logger.warn(`🔄 设备${deviceId}连续${count}个黑帧,发送切换到无障碍截图模式指令`)
try {
const deviceSocketId = this.deviceManager.getDeviceSocketId(deviceId)
if (deviceSocketId) {
const deviceSocket = this.webClientManager.io?.sockets.sockets.get(deviceSocketId)
if (deviceSocket) {
deviceSocket.emit('quality_adjust', {
captureMode: 'accessibility',
fps: 10,
quality: 50,
maxWidth: 480,
maxHeight: 854
})
this.logger.info(`📤 已向设备${deviceId}发送切换采集模式指令`)
}
}
} catch (e) {
this.logger.error(`❌ 发送切换采集模式指令失败:`, e)
}
if (count % 100 === 1) {
this.logger.warn(`过滤黑屏帧: ${dataSize} 字符 < ${MIN_VALID_FRAME_SIZE}, 设备${deviceId}, 连续黑帧${count}, 已丢弃${this.droppedFrames}`)
}
return false
}
// 收到有效帧,重置黑帧计数
// 收到有效帧,重置黑帧计数
if (screenData.deviceId) {
const prevCount = this.consecutiveBlackFrames.get(screenData.deviceId) || 0
if (prevCount > 0) {
this.logger.info(`✅ 设备${screenData.deviceId}收到有效帧(${dataSize}字符),重置黑帧计数(之前${prevCount})`)
}
this.consecutiveBlackFrames.set(screenData.deviceId, 0)
// 收到有效帧后允许再次发送切换指令(如果后续又出现黑帧)
this.captureModeSwitchSent.delete(screenData.deviceId)
}
// 🔧 检查设备是否有控制者,没有控制者直接丢弃(提前检查,减少处理开销)