Feature: remote desktop tuning flags, on by default with per-item opt-out
Adds "Advanced -> Remote desktop tuning" with three independently checkable items, all enabled by default: x264 bitrate cap (VBV) TUNING_X264_VBV 0x1 GDI capture: no slice delay TUNING_GDI_NO_SLEEP 0x2 Send pacing FPS floor TUNING_PACE_FPS_FLOOR 0x4 Unticking an item clears its bit and restores the pre-commit behaviour exactly, so the escape hatch is one click per measure -- no rebuild, no config edit. Each bit is independent; a problem with one does not force turning all three off. Plumbing -------- Menu state -> [settings] Tuning* -> CMy2015RemoteDlg::GetScreenTuningFlags() -> CScreenSpyDlg::SendScreenTuning() (right after TOKEN_BITMAPINFO) -> CMD_SCREEN_TUNING = 178 [cmd:1][flags:4 LE] -> CScreenManager::OnReceive -> m_nTuningFlags -> ScreenCapture::SetTuningFlags Why it is safe to send to old clients: CScreenManager::OnReceive has no default branch in its switch, so an unknown command falls straight out (verified). 178 was unassigned (177 = COMMAND_SET_PROTO, 199 = TOKEN_DECRYPT), and the enum re-anchors explicitly so nothing auto- increments onto it. Flags are sent even when all-zero on purpose: the client's flag lives in CScreenManager, which survives closing and reopening the remote desktop window on the same connection. Without the zero send, unticking the menu would leave the previous flags in effect. Per-measure notes ----------------- VBV: capped CRF (peak = target, 0.5s buffer, init 0.9). The hardware paths already cap via rc_max_rate (1.5x, 1s buffer); this is tighter and only affects x264. After an IDR the buffer drains and takes up to 0.5s to refill, so a brief quality dip follows every keyframe -- if that shows up, relaxing to 1.5x/1s would match NVENC/QSV. GDI: keeps the 50-line BitBlt slicing (large single BitBlts hit driver limits) and only drops the 5ms sleep between slices -- 1080p is 22 slices = a forced 110ms per frame against a 50ms budget at 20fps. Pacing: clamps s0 to 2x the base interval instead of 4x (2fps -> 4fps), taken as max(2x base, 1000/MaxFPS) so it never exceeds the configured MaxFPS. The growth/decay code itself is untouched. This one works against the loop's own congestion signal, so it is the first to untick if a bad link feels laggier rather than smoother. SetTuningFlags only rebuilds the encoder when TUNING_ENCODER_BITS (currently just VBV) changes -- the GDI and pacing bits are read live by the capture and send threads, and rebuilding for them would drop an IDR and visibly flash the picture. Defaults: the on-by-default value lives in the third argument of THIS_CFG.GetInt(), which only applies when the key is absent. A machine that already has an explicit 0 keeps it, so the flip is not retroactive and a test machine can end up with a mixed state. Verified on the Debug build: with no Tuning* keys all three items start checked; unticking VBV alone leaves the other two checked and survives a restart; en_US/de_DE/zh_TW translations all resolve. Not yet measured end to end on a real remote desktop session.
This commit is contained in:
1 parent
1e336113a5
commit
ca4e85826f
19 files changed
+239
-9
No files matched your search
@@ -603,6 +603,11 @@ void CScreenManager::InitScreenSpy()
|
||||
if (m_ScreenSpyObject && level >= 0 && level < QUALITY_COUNT) {
|
||||
m_ScreenSpyObject->SetBitRate(m_QualityProfiles[level].bitRate);
|
||||
}
|
||||
// 调优开关:服务端在打开远程桌面时下发,截屏对象因换窗口/改分辨率重建后要重新应用,
|
||||
// 否则重建出来的编码器又退回默认参数。
|
||||
if (m_ScreenSpyObject && m_nTuningFlags) {
|
||||
m_ScreenSpyObject->SetTuningFlags(m_nTuningFlags);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL IsRunningAsSystem()
|
||||
@@ -735,6 +740,15 @@ DWORD WINAPI CScreenManager::WorkThreadProc(LPVOID lParam)
|
||||
if (szBuffer) {
|
||||
s0 = max(s0, 1000./This->m_ScreenSettings.MaxFPS); // 最快每秒20帧
|
||||
s0 = min(s0, 1000);
|
||||
// 帧率下限:网络慢时节流会把帧间隔放大到 4 倍(fps=8 → 500ms → ≈2fps),
|
||||
// 操作反馈变得很钝。主控端「高级 → 远程桌面调优 → 发送节流帧率下限」默认开,
|
||||
// 上限收到 2 倍(≈4fps)。代价是链路已饱和时排队更明显,弱网下若觉得画面
|
||||
// 更连贯但更滞后,应在高级菜单里关掉这一项。
|
||||
// 下限不能越过用户配置的 MaxFPS(MaxFPS 很低时间隔本来就更长),取两者较大值。
|
||||
if (This->m_nTuningFlags & TUNING_PACE_FPS_FLOOR) {
|
||||
const float floorS0 = max(sleep * 2.f, 1000.f / This->m_ScreenSettings.MaxFPS);
|
||||
if (s0 > floorS0) s0 = floorS0;
|
||||
}
|
||||
int span = s0-(clock() - last);
|
||||
Sleep(span > 0 ? span : 1);
|
||||
if (span < 0) { // 发送数据耗时较长,网络较差或数据较多
|
||||
@@ -1132,6 +1146,20 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CMD_SCREEN_TUNING: {
|
||||
// 远程桌面调优开关:[cmd:1][flags:4 LE]。主控端「高级 → 远程桌面调优」三项,
|
||||
// 默认下发 0x7;取消勾选时对应位清零,等于回到加开关前的行为。
|
||||
// 老客户端不认识这条命令,switch 无 default 直接忽略。
|
||||
if (ulLength < 1 + sizeof(int)) break;
|
||||
int flags = 0;
|
||||
memcpy(&flags, szBuffer + 1, sizeof(int));
|
||||
Mprintf("[CScreenManager] TuningFlags: 0x%08X\n", flags);
|
||||
m_nTuningFlags = flags;
|
||||
if (m_ScreenSpyObject) {
|
||||
m_ScreenSpyObject->SetTuningFlags(flags);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CMD_INSTRUCTION_SET: {
|
||||
int set = unsigned(szBuffer[1]);
|
||||
iniFile cfg(CLIENT_PATH);
|
||||
|
||||
Reference in new issue
Block a user