The adaptive quality controller counted only complete frames per second, so when
a single frame took several seconds to arrive the sample was 0 fps and the
throughput criterion abstained forever: Ultra and High kept flipping while a
foreground video played. The audio watchdog had the opposite problem: it rebuilt
the WASAPI capture every three seconds on an idle endpoint, and its sleep
detector measured the whole loop including a blocking send.
Sample the last ten seconds in a ring buffer and feed the criterion a windowed
rate, guarded so a scroll burst, a stale window or a few KB clock patch is not
mistaken for congestion. Apply the same per-frame floor to the one-second
fallback and to the post-downgrade local-bottleneck probe. Normalize delayed
timer ticks by real elapsed milliseconds, and make the 40 second
upgrade-failure window outlast the resolution cooldown it has to cross.
On the client, rebuild only when an audio session is actually rendering, and
rebuild immediately when the captured endpoint is no longer the default output;
refresh the sleep timestamps on failed as well as successful init.
Tests cover the window and fallback helpers directly; the full suite passes
845/845, and both the Debug server and Debug client build.
Co-Authored-By: deepseek-flash
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Tests
quality_load_test(MSVC Release):27/27 通过,含新增的慢流量窗口、1 秒样本、本机瓶颈用例。linux/ghost二进制改动。审查结论:建议合并 ✅
这个 PR 解决两个独立但同源的慢链路问题,设计思路正确,测试覆盖充分,注释质量很高。
整体评价
A. 吞吐判据窗口采样(ScreenSpyDlg + commands.h)
CollectLoadSample统一采样管道消除了降档判据和本机瓶颈探测各采各的导致确认计数永远凑不齐的问题——这是核心修复。minFrameBytes门槛和实际耗时归一,堵住了窗口拒绝后小帧补丁从这条路漏回来的漏洞。volatile DWORD lastFrameTick用 32 位避免 x86 上 64 位读撕裂——考虑到位。B. WASAPI 看门狗(ScreenManager.cpp)
IsRenderingAudioActive+IsCapturedDeviceStale两个探测函数的 COM 引用计数管理正确,出错一律走安全方向(宁可多探不漏)。m_bAudioThreadRunning防 use-after-free,是关键安全检查。lastTick刷新移到Sleep(10)之前)是本 PR 最关键的 bug 修复——原来阻塞发送被误判为休眠恢复,每 2 秒重建一次捕获。测试: 16 个新用例覆盖所有新增函数和关键边界,每个用例都有注释说明对应的现场和判据意图。
两条非阻塞建议
见下方 inline 评论。
@@ -2489,0 +2561,4 @@}CoTaskMemFree(curId);return stale;}非阻塞建议:
CoCreateInstance频率IsCapturedDeviceStale每 3 秒在空闲端点上创建一次MMDeviceEnumerator实例。虽然开销很小(只是 COM 对象,不涉及设备打开),但如果想优化可以考虑缓存 enumerator 或在InitWASAPILoopback时创建一次、在UninitWASAPI时释放。不影响正确性,不阻塞合并。
@@ -408,0 +439,4 @@// 最近一次收全帧的时刻(区分「内容停了」)。写方是网络收包线程、读方是 UI// 线程,用 32 位的 GetTickCount 而不是 64 位:x86 上一次未加锁的 64 位读// 可能被撕裂成两个时刻,算出的帧龄会瞬间变成天文数字或负数。volatile DWORD lastFrameTick = 0;非阻塞建议:
volatile→std::atomic<DWORD>volatile在 C++ 标准里不保证跨线程可见性(那是std::atomic的职责)。在 MSVC/x86 上对对齐的 32 位DWORD读写实际是原子的,所以当前代码安全。但如果将来移植到 ARM 或换编译器,volatile的语义可能不够。建议后续用
std::atomic<DWORD>或InterlockedExchange/InterlockedCompareExchange替代,让线程安全意图更明确。不阻塞本次合并。@@ -56,0 +113,4 @@int f = 0, b = 0, k = 0;EXPECT_FALSE(GetCongestedLoadSample(3, 12ULL * 1024 * 1024, 1, 3, 10, 1, 8, 64 * 1024, f, b, k));// 同样这 3 帧散在 3 个秒里 → 才是"持续交付不动"EXPECT_TRUE (GetCongestedLoadSample(3, 12ULL * 1024 * 1024, 3, 1, 10, 1, 8, 64 * 1024, f, b, k));测试质量优秀
16 个新用例逐个覆盖了三道防误判门槛的每种假阳性现场(滚动停住、单帧突发、过期窗口),以及 1 秒退路的小帧下限和耗时归一。
特别欣赏
ShortBurstInOneSecondIsNotCongestion这个用例——3 帧挤在同一秒 vs 散在 3 个秒里的对比测试,精确验证了条件 ① 的设计意图。