Feature: throughput criterion for adaptive quality, plus anti-oscillation

Adaptive quality only looked at RTT, so a short RTT over a narrow pipe
read as "excellent": at 20-40ms it picks Ultra/High (DIFF/RGB565), both
with bitRate == 0, and never steps down. One 1080p RGB565 frame is
4.15 MB -- 1.66s of transmission on 20 Mbps.

Adds GetTargetQualityLevelByLoad(): congestion needs both fps < 60% of
baseline and bytes/frame still near the nominal bitrate, because a static
screen has a near-zero byte rate on any link. Merged with the RTT result
as max() -- averaging lets a good RTT mask a narrow pipe. Step-down is 3
confirmations and jumps straight to the level the throughput can carry
(capped at +2); step-up stays RTT-only, so the criterion is one-way and
the worst case is one level too low instead of a 30s/15s oscillation.

Anti-oscillation, all inside the switch: RTT hysteresis (85%/115% dead
band against the target level's threshold), failed step-up pinned for 3
minutes, cooldowns 3s -> 10s down / 15s up, counters interrupt each
other, and a hard limit of 6 changes per 5 minutes.

Server-only, no client change. m_ulBytesThisSecond had to be fixed first:
it is accumulated before the switch, so file transfer, audio and
clipboard counted as screen traffic; added m_ulScreenBytesThisSecond for
the four frame cases. Also gates a real bug in the 10s post-step-down
probe that disabled the criterion permanently on a static screen.

Default on (same migration caveat as the other four). Unticking takes the
original path unchanged. Verified on Debug: 27 hysteresis cases and the
load cases pass, menu defaults correct; not yet measured end to end.
This commit is contained in:
yuanyuanxiang committed 2026-11-05 14:24:42 +01:00
1 parent ab83f5d685
commit d6b04a98f0
12 files changed
+543 -23

No files matched your search

+24 -1
View File
@@ -341,10 +341,15 @@ public:
CBmpToAvi m_aviStream;
// 传输速率统计
ULONG m_ulBytesThisSecond = 0; // 本秒累计字节
ULONG m_ulBytesThisSecond = 0; // 本秒累计字节(含文件/音频/剪贴板,仅用于标题显示)
double m_dTransferRate = 0; // 当前速率 (KB/s)
// 屏幕数据单独统计:m_ulBytesThisSecond 混入了文件传输、音频、剪贴板,
// 传大文件时会让吞吐判据误判"链路塞满",所以只统计帧 TOKEN 的字节。
ULONG m_ulScreenBytesThisSecond = 0;
double m_dScreenKBps = 0; // 上一秒的屏幕数据速率 (KB/s)
// 帧率统计 (使用EMA平滑)
ULONG m_ulFramesThisSecond = 0; // 本秒累计帧数
ULONG m_ulFramesLastSecond = 0; // 上一秒的原始帧数(吞吐判据用,不用 EMA)
double m_dFrameRate = 0; // 平滑后的帧率 (FPS)
// 自适应质量
@@ -357,6 +362,23 @@ public:
ULONGLONG lastResChangeTime = 0; // 上次分辨率变化时间
ULONGLONG startTime = 0; // 启动时间 (用于延迟启动自适应)
int stableCount = 0; // 稳定计数 (用于防抖)
// ===== 吞吐判据(双判据)状态 =====
double baselineFps = 0; // 本会话健康帧率基线,启动后 60 秒内实测学习
int loadCount = 0; // 吞吐判据的确认计数(字节速率抖动大,比 RTT 多等一拍)
ULONGLONG loadProbeTime = 0; // 降档后的观察起点,0=未在观察
bool loadPinned = false; // 判定瓶颈在本机,本次会话停用吞吐判据
// ===== 防振荡状态(只双判据模式下使用)=====
// 升档失败封顶:升档后短时间内又降回来,说明那次升档是错的,
// 在 ceilingUntil 之前不再尝试好于 levelCeiling 的档位(-1 = 无封顶)。
// 思路同 TCP 的 ssthresh:宁可停在低一档,也不要在两个档位之间来回重建。
int levelCeiling = -1;
ULONGLONG ceilingUntil = 0;
ULONGLONG lastUpTime = 0; // 上次升档的时间
int lastUpFromLevel = -1; // 上次升档前的档位(回退到这里就封顶)
// 切换频率硬上限:不依赖具体成因的兜底,防止任何没预料到的振荡模式。
ULONGLONG changeWindowStart = 0; // 当前统计窗口起点
int changeCountInWindow = 0; // 窗口内的自适应切换次数
ULONGLONG lockUntil = 0; // 锁档截止时间(0=未锁)
} m_AdaptiveQuality;
volatile bool m_bResolutionChanging = false; // 分辨率切换中,阻止解码
@@ -408,6 +430,7 @@ public:
int GetClientRTT(); // 获取客户端RTT(ms)
void EvaluateQuality(); // 评估并调整质量
void ApplyQualityLevel(int level, bool persist = false); // 应用质量等级
void NoteAdaptiveChange(ULONGLONG now); // 自适应切换频率计数,超限则锁档
const char* GetQualityName(int level); // 获取质量等级名称
void UpdateQualityMenuCheck(CMenu* SysMenu = nullptr); // 更新质量菜单勾选状态