From 4884b080e8fc631197e94fd78df030f6f7f724b7 Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 7 Nov 2026 09:43:54 +0100 Subject: [PATCH] Improve: default the x264 bitrate cap off and label it for weak links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cap is capped CRF (VBV): when a frame needs more bits than the profile's nominal bitrate allows, x264 has to raise QP to stay under the ceiling. Scenes with lots of change (video, scrolling, window dragging) therefore lose detail and look blurry, while static scenes stay sharp - the cap only bites on motion. That trade is worth it on intercontinental or otherwise constrained links, where an uncapped frame can take seconds to transmit and stall everything queued behind it, but it is a pure quality loss on a LAN. The tuning item now defaults to unchecked, so a master sends 0x3 (GDI no-sleep and send pacing) by default; machines that already stored TuningX264Vbv keep their explicit choice. The menu entry is renamed to "x264 码率封顶 (VBV,仅限洲际弱网)" and the en_US, zh_TW and de_DE translations were updated to match the new source string. Only newly opened remote desktops pick up the flag, since CMD_SCREEN_TUNING is sent when the session starts. Verified by rebuilding the Debug x64 server and client, and by finding the new menu and translation strings in the built binary. Co-Authored-By: deepseek-flash --- client/EncoderFactory.cpp | 2 +- client/ScreenCapture.h | 3 ++- client/ScreenManager.cpp | 3 ++- client/ScreenManager.h | 3 ++- common/commands.h | 7 ++++--- server/2015Remote/2015Remote.rc | Bin 181564 -> 181558 bytes server/2015Remote/2015RemoteDlg.cpp | 11 +++++++---- server/2015Remote/2015RemoteDlg.h | 2 +- server/2015Remote/ScreenSpyDlg.h | 2 +- server/2015Remote/lang/de_DE.ini | 2 +- server/2015Remote/lang/en_US.ini | 2 +- server/2015Remote/lang/zh_TW.ini | 2 +- 12 files changed, 23 insertions(+), 16 deletions(-) diff --git a/client/EncoderFactory.cpp b/client/EncoderFactory.cpp index e04ec2c..9f34a75 100644 --- a/client/EncoderFactory.cpp +++ b/client/EncoderFactory.cpp @@ -60,7 +60,7 @@ std::unique_ptr CreateEncoder(const EncoderRequest& req) { auto enc = std::make_unique(); p.rc = RateControl::CRF; p.crf = BitRateToCRF(req.bitrate_kbps); - // capped CRF:由主控端「高级 → 远程桌面调优」控制,默认开、可取消勾选 + // capped CRF:由主控端「高级 → 远程桌面调优」控制,默认关、仅限洲际弱网勾选 p.vbv_cap = req.vbv_cap; if (enc->open(p)) { Mprintf("=> encoder: %s (SW, crf=%d%s)\n", enc->backendName(), p.crf, diff --git a/client/ScreenCapture.h b/client/ScreenCapture.h index 8c7e700..445f927 100644 --- a/client/ScreenCapture.h +++ b/client/ScreenCapture.h @@ -178,7 +178,8 @@ public: int m_nBitRate = 0; // H264 编码码率 (kbps), 0=自动 int m_nTuningFlags = 0; // 远程桌面调优开关位(CMD_SCREEN_TUNING 下发)。 // 本地初值恒为 0,由服务端在打开远程桌面时下发, - // 主控端默认下发 0x7(三项全开);位定义见 TUNING_* + // 主控端默认下发 0x3(GDI 去延时+发送节流, + // x264 码率封顶默认关);位定义见 TUNING_* // 感兴趣区域 (ROI) RECT m_ROI = {0,0,0,0}; diff --git a/client/ScreenManager.cpp b/client/ScreenManager.cpp index b0bf783..74b20b9 100644 --- a/client/ScreenManager.cpp +++ b/client/ScreenManager.cpp @@ -1148,7 +1148,8 @@ VOID CScreenManager::OnReceive(PBYTE szBuffer, ULONG ulLength) } case CMD_SCREEN_TUNING: { // 远程桌面调优开关:[cmd:1][flags:4 LE]。主控端「高级 → 远程桌面调优」三项, - // 默认下发 0x7;取消勾选时对应位清零,等于回到加开关前的行为。 + // 默认下发 0x3(GDI 去延时+发送节流;x264 码率封顶默认关,仅限洲际弱网); + // 取消勾选时对应位清零,等于回到加开关前的行为。 // 老客户端不认识这条命令,switch 无 default 直接忽略。 if (ulLength < 1 + sizeof(int)) break; int flags = 0; diff --git a/client/ScreenManager.h b/client/ScreenManager.h index 49f4f57..d13f9c8 100644 --- a/client/ScreenManager.h +++ b/client/ScreenManager.h @@ -42,7 +42,8 @@ public: HANDLE m_hWorkThread; ScreenSettings m_ScreenSettings = { 20 }; QualityProfile m_QualityProfiles[QUALITY_COUNT]; // 本地质量配置(可被服务端覆盖) - // 远程桌面调优开关位(CMD_SCREEN_TUNING 下发),本地初值 0,主控端默认下发 0x7。 + // 远程桌面调优开关位(CMD_SCREEN_TUNING 下发),本地初值 0,主控端默认下发 0x3 + //(GDI 去延时+发送节流;x264 码率封顶默认关,仅限洲际弱网时勾选)。 // 保存在这里而不是 ScreenSettings 里,避免改动服务端↔客户端的固定结构体布局。 int m_nTuningFlags = 0; diff --git a/common/commands.h b/common/commands.h index 0f1a441..3d3abdd 100644 --- a/common/commands.h +++ b/common/commands.h @@ -1371,10 +1371,11 @@ struct QualityProfile { }; // ===== 远程桌面调优开关(CMD_SCREEN_TUNING 的位定义)===== -// 主控端「高级 → 远程桌面调优」里逐项勾选。三项默认全部勾选;取消勾选即把对应位清零, +// 主控端「高级 → 远程桌面调优」里逐项勾选。GDI 去延时与发送节流默认勾选, +// x264 码率封顶默认不勾选(仅限洲际弱网);取消勾选即把对应位清零, // 回到加开关前的行为。每一位都能独立开关,某项出问题可以只关那一项,不必全关。 -// 默认值改在 CMy2015RemoteDlg::OnInitDialog 的 GetInt 第三参数上,注意存量机器如果 -// 已经写过 0,改默认值不会覆盖它们。 +// 默认值改在 CMy2015RemoteDlg::OnInitDialog 的 GetInt 第三参数上,注意存量机器只要 +// 已经写过该键,改默认值就不会覆盖它们(保持用户上次的显式选择)。 #define TUNING_X264_VBV 0x00000001 // x264 软编加 VBV 码率封顶(跨洲际防单帧打爆链路) #define TUNING_GDI_NO_SLEEP 0x00000002 // GDI 抓屏去掉分段 BitBlt 之间的 5ms 延时(1080p 省 110ms/帧) #define TUNING_PACE_FPS_FLOOR 0x00000004 // 发送节流帧率下限:慢链路下不再把帧率压到 2fps diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 7bd734d6b2f85e8e3087fb562bcc01b3c6a3f473..faca26e185fd0d99a4ca465f26678dcf6b560623 100644 GIT binary patch delta 44 zcmdnf#l5YIyP<_~3)3TcVV?g-{Q{;L<+@HYj1R2WWKd$znJ%x$q`F-}fk|d50CSlR Ac>n+a delta 29 lcmdni#l5GCyP<_~3)3U{=|$%m6{agFGRbY1Qecu<3IM903H|^8 diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index b6bf53b..fc7c050 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -2834,9 +2834,11 @@ BOOL CMy2015RemoteDlg::OnInitDialog() m_runNormal = THIS_CFG.GetInt("settings", "RunNormal", 0); // 高级菜单:DLL内嵌TLS证书(勾选状态来自 [settings] EmbedTlsInDll,见上面的加载) - // 以及「远程桌面调优」子菜单里的三项,默认全开;取消勾选即回到加开关前的行为。 - // 第三参数是默认值:只对从没写过该键的机器生效,已写过 0 的存量机器保持关。 - m_bTuningX264Vbv = THIS_CFG.GetInt("settings", "TuningX264Vbv", 1) != 0; + // 以及「远程桌面调优」子菜单。GDI 去延时、发送节流帧率下限默认开; + // x264 码率封顶默认关 —— 它靠压 QP 兑现码率上限,画面变化多时会明显发糊, + // 只适合洲际/弱网链路(防止单帧打爆链路导致"卡几秒再猛跳")。 + // 第三参数是默认值:只对从没写过该键的机器生效,已写过值的存量机器保持原样。 + m_bTuningX264Vbv = THIS_CFG.GetInt("settings", "TuningX264Vbv", 0) != 0; m_bTuningGdiNoSleep = THIS_CFG.GetInt("settings", "TuningGdiNoSleep", 1) != 0; m_bTuningPaceFpsFloor = THIS_CFG.GetInt("settings", "TuningPaceFpsFloor", 1) != 0; // 自适应加吞吐判据:纯服务端,默认开。判据分不清"链路慢"和"本机慢", @@ -10943,7 +10945,8 @@ void CMy2015RemoteDlg::SyncTuningMenuChecks() m_bAdaptiveDualCriteria ? MF_CHECKED : MF_UNCHECKED); } -// 高级→远程桌面调优→x264 码率封顶(VBV):默认开,取消勾选即关闭。 +// 高级→远程桌面调优→x264 码率封顶(VBV):默认关,勾选即开启,仅限洲际/弱网链路。 +// 开启后动场(视频、滚动、拖窗)会被 VBV 上限压 QP 而发糊,换来的是单帧不炸链路。 // 只影响此后打开的远程桌面窗口(打开时经 CMD_SCREEN_TUNING 下发),已打开的窗口不变, // 因为改编码器参数要重建编码器,会在画面上留下一次可感知的断流。 void CMy2015RemoteDlg::OnToolTuningX264Vbv() diff --git a/server/2015Remote/2015RemoteDlg.h b/server/2015Remote/2015RemoteDlg.h index 63b0027..52eaba2 100644 --- a/server/2015Remote/2015RemoteDlg.h +++ b/server/2015Remote/2015RemoteDlg.h @@ -283,7 +283,7 @@ public: // 高级→远程桌面调优:四项默认全开,取消勾选即回到加开关前的行为。 // 前三项勾选后经 CMD_SCREEN_TUNING 下发客户端,某项出问题可以只关那一项。 // 持久化在 [settings] Tuning*;注意默认值只对没写过该键的机器生效。 - bool m_bTuningX264Vbv = true; // TUNING_X264_VBV x264 软编加 VBV 码率封顶 + bool m_bTuningX264Vbv = false; // TUNING_X264_VBV x264 软编加 VBV 码率封顶(默认关,仅限洲际弱网) bool m_bTuningGdiNoSleep = true; // TUNING_GDI_NO_SLEEP GDI 抓屏去分段延时 bool m_bTuningPaceFpsFloor = true; // TUNING_PACE_FPS_FLOOR 发送节流帧率下限 // 高级→远程桌面调优→自适应加吞吐判据:这一项是纯服务端的,不下发客户端。 diff --git a/server/2015Remote/ScreenSpyDlg.h b/server/2015Remote/ScreenSpyDlg.h index bce4e41..b68d3ce 100644 --- a/server/2015Remote/ScreenSpyDlg.h +++ b/server/2015Remote/ScreenSpyDlg.h @@ -223,7 +223,7 @@ public: void BroadcastCursorToWeb(bool force); VOID SendNext(void); - // 下发主控端「高级 → 远程桌面调优」的开关位(CMD_SCREEN_TUNING),主控端默认 0x7 + // 下发主控端「高级 → 远程桌面调优」的开关位(CMD_SCREEN_TUNING),主控端默认 0x3 VOID SendScreenTuning(void); // 要求客户端下一帧强制 IDR(COMMAND_SCREEN_KEYFRAME_REQ) VOID RequestClientKeyFrame(void); diff --git a/server/2015Remote/lang/de_DE.ini b/server/2015Remote/lang/de_DE.ini index 67a7048..6118e86 100644 --- a/server/2015Remote/lang/de_DE.ini +++ b/server/2015Remote/lang/de_DE.ini @@ -2087,7 +2087,7 @@ MCPԶ Զ³Ì×ÀÃæÖÊÁ¿µȼ¶(&Q)=Remote Desktop &Qualitaetsstufen Զ³Ì×ÀÃæÖÊÁ¿µȼ¶=Remote Desktop Qualitaetsstufen Զ³Ì×ÀÃæµ÷ÓÅ(&T)=Remote-Desktop-Optimierung(&T) -x264 ÂëÂʷⶥ (VBV)=x264 Bitraten-Deckel (VBV) +x264 ÂëÂʷⶥ (VBV£¬½öÏÞÖ޼ÊÈõÍø)=x264 Bitraten-Deckel (VBV, nur f¨¹r interkontinentale/schwache Netze) GDI ץÆÁȥ·ֶÎÑÓʱ=GDI-Aufnahme ohne Segment-Pause ·¢ËͽÚÁ÷֡ÂÊÏÂÏÞ=Mindest-Framerate beim Senden ×ÔÊÊӦ¼ÓÍÌÍÂÅоÝ=Durchsatz-Kriterium (adaptiv) diff --git a/server/2015Remote/lang/en_US.ini b/server/2015Remote/lang/en_US.ini index 2e17294..14e65aa 100644 --- a/server/2015Remote/lang/en_US.ini +++ b/server/2015Remote/lang/en_US.ini @@ -2092,7 +2092,7 @@ HTTPS Զ³Ì×ÀÃæÖÊÁ¿µȼ¶(&Q)=Remote Desktop &Quality Levels Զ³Ì×ÀÃæÖÊÁ¿µȼ¶=Remote Desktop Quality Levels Զ³Ì×ÀÃæµ÷ÓÅ(&T)=Remote desktop tuning(&T) -x264 ÂëÂʷⶥ (VBV)=x264 bitrate cap (VBV) +x264 ÂëÂʷⶥ (VBV£¬½öÏÞÖ޼ÊÈõÍø)=x264 bitrate cap (VBV, intercontinental/weak links only) GDI ץÆÁȥ·ֶÎÑÓʱ=GDI capture: no per-slice delay ·¢ËͽÚÁ÷֡ÂÊÏÂÏÞ=Send pacing FPS floor ×ÔÊÊӦ¼ÓÍÌÍÂÅоÝ=Adaptive throughput criterion diff --git a/server/2015Remote/lang/zh_TW.ini b/server/2015Remote/lang/zh_TW.ini index 96c07a1..c1216e1 100644 --- a/server/2015Remote/lang/zh_TW.ini +++ b/server/2015Remote/lang/zh_TW.ini @@ -2085,7 +2085,7 @@ HTTPS Զ³Ì×ÀÃæÖÊÁ¿µȼ¶(&Q)=ßh¶Ë×ÀÃæƷÙ|µȼ‰(&Q) Զ³Ì×ÀÃæÖÊÁ¿µȼ¶=ßh¶Ë×ÀÃæƷÙ|µȼ‰ Զ³Ì×ÀÃæµ÷ÓÅ(&T)=ßh¶Ë×ÀÃæÕ{У(&T) -x264 ÂëÂʷⶥ (VBV)=x264 λԪÂÊÉÏÏÞ (VBV) +x264 ÂëÂʷⶥ (VBV£¬½öÏÞÖ޼ÊÈõÍø)=x264 λԪÂÊÉÏÏÞ (VBV£¬ƒHÏÞÖÞëHÈõ¾W) GDI ץÆÁȥ·ֶÎÑÓʱ=GDI ”Xȡȥ³ý·ֶÎÑÓßt ·¢ËͽÚÁ÷֡ÂÊÏÂÏÞ=‚÷Ë͹�Á÷Ӱ¸ñÂÊÏÂÏÞ ×ÔÊÊӦ¼ÓÍÌÍÂÅоÝ=×Ôßm‘ª¼ÓÍÌÍÂÅГþ