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.
493 lines
22 KiB
C++
493 lines
22 KiB
C++
#pragma once
|
||
#include <imm.h>
|
||
#include <map>
|
||
#include <atomic>
|
||
#include "IOCPServer.h"
|
||
#include "..\..\client\CursorInfo.h"
|
||
#include "VideoDlg.h"
|
||
#include "ToolbarDlg.h"
|
||
#include "2015RemoteDlg.h"
|
||
|
||
#include "common/config.h"
|
||
#include "common/commands.h" // 包含 AudioFormat 定义
|
||
|
||
extern "C"
|
||
{
|
||
#include "libyuv\libyuv.h"
|
||
}
|
||
|
||
#if DISABLE_FFMPEG_FOR_TEST
|
||
|
||
#define AV_CODEC_ID_H264 27
|
||
#define AVERROR(e) (-(e))
|
||
|
||
// 伪装不涉及内部成员直接访问的上下文指针
|
||
typedef void AVCodecContext;
|
||
typedef void AVCodec;
|
||
|
||
// 伪装 AVPacket 结构体,补全被主程序访问的 data 和 size 成员
|
||
struct AVPacket {
|
||
unsigned char* data;
|
||
int size;
|
||
long long pts;
|
||
long long dts;
|
||
int flags;
|
||
};
|
||
|
||
// 伪装 AVFrame 结构体,补全被主程序访问的 data 和 linesize 成员
|
||
struct AVFrame {
|
||
unsigned char* data[8];
|
||
int linesize[8];
|
||
int width;
|
||
int height;
|
||
int format;
|
||
};
|
||
|
||
// 使用 extern "C" __inline 或者是 inline 关键字,直接就地实现函数体
|
||
extern "C" {
|
||
__inline void av_frame_unref(AVFrame* frame) {
|
||
if (frame) {
|
||
for (int i = 0; i < 8; i++) { frame->data[i] = nullptr; frame->linesize[i] = 0; }
|
||
}
|
||
}
|
||
__inline AVCodec* avcodec_find_decoder(int id) { return nullptr; }
|
||
__inline void av_init_packet(AVPacket* pkt) { if (pkt) { pkt->data = nullptr; pkt->size = 0; } }
|
||
__inline AVCodecContext* avcodec_alloc_context3(const AVCodec* codec) { return nullptr; }
|
||
__inline void avcodec_free_context(AVCodecContext** avctx) { if (avctx) *avctx = nullptr; }
|
||
__inline int avcodec_open2(AVCodecContext* avctx, const AVCodec* codec, void** options) { return -1; }
|
||
__inline int avcodec_send_packet(AVCodecContext* avctx, const AVPacket* avpkt) { return -1; }
|
||
__inline int avcodec_receive_frame(AVCodecContext* avctx, AVFrame* frame) { return -1; }
|
||
__inline void avcodec_flush_buffers(AVCodecContext* avctx) { /* 空白实现 */ }
|
||
}
|
||
|
||
#else
|
||
extern "C"
|
||
{
|
||
#include "libavcodec\avcodec.h"
|
||
#include "libavutil\avutil.h"
|
||
}
|
||
#ifndef _WIN64
|
||
// https://github.com/Terodee/FFMpeg-windows-static-build/releases
|
||
#pragma comment(lib,"ffmpeg/libavcodec.lib")
|
||
#pragma comment(lib,"ffmpeg/libavutil.lib")
|
||
#pragma comment(lib,"ffmpeg/libswresample.lib")
|
||
#else
|
||
// https://github.com/ShiftMediaProject/FFmpeg
|
||
#pragma comment(lib,"ffmpeg/libavcodec_x64.lib")
|
||
#pragma comment(lib,"ffmpeg/libavutil_x64.lib")
|
||
#pragma comment(lib,"ffmpeg/libswresample_x64.lib")
|
||
#endif
|
||
#endif
|
||
|
||
#ifndef _WIN64
|
||
#pragma comment(lib,"libyuv/libyuv.lib")
|
||
#else
|
||
#pragma comment(lib,"libyuv/libyuv_x64.lib")
|
||
#endif
|
||
|
||
#pragma comment(lib, "Mfplat.lib")
|
||
#pragma comment(lib, "Mfuuid.lib")
|
||
#pragma comment(lib, "Bcrypt.lib")
|
||
#pragma comment(lib, "Strmiids.lib")
|
||
|
||
// 文件接收消息(用于将工作线程的文件数据转发到主线程处理)
|
||
#define WM_RECVFILEV2_CHUNK (WM_USER + 0x200)
|
||
#define WM_RECVFILEV2_COMPLETE (WM_USER + 0x201)
|
||
// 来自 web 命令的音频开关,PostMessage 到对话框的 UI 线程,避免 WS 线程
|
||
// 直接动 waveOut 句柄
|
||
#define WM_AUDIO_TOGGLE_FROM_WEB (WM_USER + 0x202)
|
||
|
||
// ScreenSpyDlg 系统菜单命令 ID
|
||
enum {
|
||
IDM_CONTROL = 0x1010,
|
||
IDM_FULLSCREEN,
|
||
IDM_SEND_CTRL_ALT_DEL,
|
||
IDM_TRACE_CURSOR, // 跟踪显示远程鼠标
|
||
IDM_BLOCK_INPUT, // 锁定远程计算机输入
|
||
IDM_SAVEDIB, // 保存图片
|
||
IDM_GET_CLIPBOARD, // 获取剪贴板
|
||
IDM_SET_CLIPBOARD, // 设置剪贴板
|
||
IDM_ADAPTIVE_SIZE,
|
||
IDM_SAVEAVI,
|
||
IDM_SAVEAVI_H264,
|
||
IDM_SWITCHSCREEN,
|
||
IDM_MULTITHREAD_COMPRESS,
|
||
IDM_FPS_10,
|
||
IDM_FPS_15,
|
||
IDM_FPS_20,
|
||
IDM_FPS_25,
|
||
IDM_FPS_30,
|
||
IDM_FPS_UNLIMITED,
|
||
IDM_ORIGINAL_SIZE,
|
||
IDM_SCREEN_1080P,
|
||
IDM_REMOTE_CURSOR,
|
||
IDM_SCROLL_DETECT_OFF, // 滚动检测:关闭(局域网)
|
||
IDM_SCROLL_DETECT_2, // 滚动检测:跨网推荐
|
||
IDM_SCROLL_DETECT_4, // 滚动检测:标准模式
|
||
IDM_SCROLL_DETECT_8, // 滚动检测:省CPU模式
|
||
IDM_QUALITY_OFF, // 关闭质量控制(使用原有算法)
|
||
IDM_ADAPTIVE_QUALITY, // 自适应质量
|
||
IDM_QUALITY_ULTRA, // 手动质量:Ultra
|
||
IDM_QUALITY_HIGH, // 手动质量:High
|
||
IDM_QUALITY_GOOD, // 手动质量:Good
|
||
IDM_QUALITY_MEDIUM, // 手动质量:Medium
|
||
IDM_QUALITY_LOW, // 手动质量:Low
|
||
IDM_QUALITY_MINIMAL, // 手动质量:Minimal
|
||
IDM_ENABLE_SSE2,
|
||
IDM_FAST_STRETCH, // 快速缩放模式(降低CPU占用)
|
||
IDM_CUSTOM_CURSOR, // 使用自定义光标
|
||
IDM_RESTORE_CONSOLE, // RDP会话归位
|
||
IDM_RESET_VIRTUAL_DESKTOP, // 重置虚拟桌面
|
||
IDM_AUDIO_TOGGLE, // 音频开关
|
||
IDM_ENABLE_H264_HARD,
|
||
IDM_ENABLE_AV1_HARD,
|
||
IDM_MOUSE_CALIB, // 鼠标坐标校准(逐主机补偿客户端坐标换算偏差)
|
||
};
|
||
|
||
// 状态信息窗口 - 全屏时显示帧率/速度/质量
|
||
class CStatusInfoWnd : public CWnd
|
||
{
|
||
public:
|
||
CStatusInfoWnd() : m_nOpacityLevel(0), m_bVisible(false), m_bDragging(false) {}
|
||
|
||
BOOL Create(CWnd* pParent);
|
||
void UpdateInfo(double fps, double kbps, const CString& quality);
|
||
void Show();
|
||
void Hide();
|
||
void SetOpacityLevel(int level);
|
||
void UpdatePosition(const RECT& rcMonitor);
|
||
void LoadSettings();
|
||
void SaveSettings();
|
||
|
||
bool IsVisible() const { return m_bVisible; }
|
||
bool IsParentInControlMode(); // 检查父窗口是否处于控制模式
|
||
|
||
protected:
|
||
afx_msg void OnPaint();
|
||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
||
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
|
||
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
|
||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
||
DECLARE_MESSAGE_MAP()
|
||
|
||
private:
|
||
CString m_strInfo;
|
||
int m_nOpacityLevel;
|
||
bool m_bVisible;
|
||
|
||
// 拖动支持
|
||
bool m_bDragging;
|
||
CPoint m_ptDragStart;
|
||
|
||
// 位置保存
|
||
double m_dOffsetXRatio = 0.5;
|
||
int m_nOffsetY = 50;
|
||
bool m_bHasCustomPosition = false;
|
||
};
|
||
|
||
// CScreenSpyDlg 对话框
|
||
|
||
class CScreenSpyDlg : public DialogBase
|
||
{
|
||
DECLARE_DYNAMIC(CScreenSpyDlg)
|
||
CToolbarDlg* m_pToolbar = nullptr;
|
||
CMy2015RemoteDlg* m_pParent = nullptr;
|
||
|
||
public:
|
||
CStatusInfoWnd* m_pStatusInfoWnd = nullptr;
|
||
// MaxFPS=20, ScrollDetectInterval=2, Reserved={}, Capabilities=0
|
||
// MaxFPS=20, CompressThread=0, ScreenStrategy=0, ScreenWidth=0, ScreenHeight=0,
|
||
// FullScreen=0, RemoteCursor=0, ScrollDetectInterval=2, QualityLevel=-1,
|
||
// CpuSpeedup=0, ScreenType=0, AudioEnabled=0, Reserved={}, Capabilities=0
|
||
ScreenSettings m_Settings = { 20, 0, 0, 0, 0, 0, 0, 2, -1, 0, 0, 0, {}, 0 };
|
||
|
||
public:
|
||
// 快速缩放模式(全局配置,所有实例共享)
|
||
static int s_nFastStretch; // -1=未初始化, 0=关闭, 1=开启
|
||
static bool GetFastStretchMode();
|
||
static void SetFastStretchMode(bool bFast);
|
||
|
||
CScreenSpyDlg(CMy2015RemoteDlg* Parent, Server* IOCPServer=NULL, CONTEXT_OBJECT *ContextObject=NULL);
|
||
virtual ~CScreenSpyDlg();
|
||
virtual BOOL ShouldReconnect()
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
// Check if this dialog was created by Web request (shared by Web users)
|
||
bool IsWebSession() const { return m_bIsWebSession.load(); }
|
||
void SetWebSession(bool isWeb) { m_bIsWebSession.store(isWeb); }
|
||
|
||
// 把远程光标的位置/类型同步给 Web 客户端(非控制态由浏览器自己画光标)。
|
||
// force=true 用于类型变化,跳过节流立即发送。
|
||
void BroadcastCursorToWeb(bool force);
|
||
|
||
VOID SendNext(void);
|
||
// 下发主控端「高级 → 远程桌面调优」的开关位(CMD_SCREEN_TUNING),主控端默认 0x7
|
||
VOID SendScreenTuning(void);
|
||
VOID OnReceiveComplete();
|
||
HDC m_hFullDC;
|
||
HDC m_hFullMemDC;
|
||
HBITMAP m_BitmapHandle;
|
||
PVOID m_BitmapData_Full;
|
||
LPBITMAPINFO m_BitmapInfor_Full;
|
||
VOID DrawFirstScreen(void);
|
||
VOID DrawNextScreenDiff(bool keyFrame);
|
||
VOID DrawScrollFrame(void);
|
||
BOOL m_bIsFirst;
|
||
bool m_bQualitySwitch = false; // 质量切换中,不显示"请等待"
|
||
ULONG m_ulHScrollPos;
|
||
ULONG m_ulVScrollPos;
|
||
// fillMode: 0=不填充, 1=全黑, 2=半透明
|
||
VOID DrawTipString(CString strString, int fillMode=1);
|
||
|
||
// 标题栏显示的主机名:有备注用备注,否则用 IP
|
||
CString GetTitleHostName() const;
|
||
|
||
POINT m_ClientCursorPos;
|
||
BYTE m_bCursorIndex;
|
||
BOOL m_bIsTraceCursor;
|
||
CCursorInfo m_CursorInfo; //自定义的一个系统的光标类
|
||
VOID SendCommand(const MYMSG* Msg);
|
||
void SendScaledMouseMessage(MSG* pMsg, bool makeLP);
|
||
// 鼠标坐标补偿:默认 1.0(不补偿)。用于客户端上报的逻辑分辨率与实际显示不一致
|
||
// (例如合盖后用外接显示器的 Mac)时,抵消客户端在 OnReceive 里的错误换算。
|
||
double m_mouseScaleX = 1.0;
|
||
double m_mouseScaleY = 1.0;
|
||
bool m_mouseScaleFromConfig = false; // 当前系数来自已保存配置(否则对话框可自动建议)
|
||
void LoadMouseScale(); // 从配置读取本主机的补偿系数(会校验上报分辨率)
|
||
void ShowMouseCalibration();// 系统菜单「鼠标坐标校准」入口
|
||
VOID UpdateServerClipboard(char *szBuffer,ULONG ulLength);
|
||
VOID SendServerClipboard(void);
|
||
|
||
BOOL m_bIsCtrl;
|
||
LPBYTE m_szData;
|
||
BOOL m_bSend;
|
||
ULONG m_ulMsgCount;
|
||
int m_FrameID;
|
||
HIMC m_hOldIMC = NULL; // 保存原始 IME 上下文,控制模式切换时使用
|
||
bool m_bHide = false;
|
||
std::atomic<bool> m_bIsWebSession{false}; // True if this dialog was created by Web request (atomic for thread safety)
|
||
std::string m_strSaveNotice; // 截图保存路径提示
|
||
ULONGLONG m_nSaveNoticeTime = 0; // 截图提示开始时间
|
||
ULONGLONG m_nLastCursorBroadcast = 0; // 上次向 Web 广播光标的时间(50ms 节流)
|
||
BYTE m_bBroadcastCursorIndex = 0; // 上次广播的光标类型
|
||
POINT m_ptBroadcastCursor = {0, 0}; // 上次广播的光标位置
|
||
BOOL m_bUsingFRP = FALSE;
|
||
|
||
// 文件接收进度对话框(用于 Linux Ctrl+C -> 服务端 Ctrl+V)
|
||
// 按 transferID 管理多个并发传输
|
||
// 存储 {HWND, 指针} 对,HWND 用于安全检查(指针可能变成野指针)
|
||
std::map<uint64_t, std::pair<HWND, class CDlgFileSend*>> m_FileRecvDlgs;
|
||
|
||
void SaveSnapshot(void);
|
||
// 对话框数据
|
||
enum { IDD = IDD_DIALOG_SCREEN_SPY };
|
||
|
||
WINDOWPLACEMENT m_struOldWndpl;
|
||
|
||
const AVCodec* m_pCodec;
|
||
AVCodecContext* m_pCodecContext;
|
||
AVPacket m_AVPacket;
|
||
AVFrame m_AVFrame;
|
||
|
||
clock_t m_lastMouseMove; // 鼠标移动时间
|
||
POINT m_lastMousePoint;// 上次鼠标位置
|
||
BOOL m_bAdaptiveSize = TRUE;
|
||
HCURSOR m_hCustomCursor = NULL; // 缓存的自定义光标
|
||
DWORD m_dwCustomCursorHash = 0; // 当前自定义光标哈希
|
||
CRect m_CRect;
|
||
double m_wZoom=1, m_hZoom=1;
|
||
int m_offsetX=0, m_offsetY=0; // 自适应模式黑边偏移(像素)
|
||
|
||
// 自适应黑边合成缓冲(按窗口尺寸缓存,避免每帧分配 GDI 资源)
|
||
HDC m_hComposeDC = NULL;
|
||
HBITMAP m_hComposeBmp = NULL;
|
||
HBITMAP m_hComposeOldBmp = NULL;
|
||
int m_nComposeCX = 0;
|
||
int m_nComposeCY = 0;
|
||
|
||
// ========== 局部放大功能 ==========
|
||
bool m_bZoomedIn = false; // 是否处于放大状态
|
||
CRect m_rcZoomSrc; // 放大区域(原图坐标)
|
||
bool m_bSelectingZoom = false; // 是否正在框选
|
||
CPoint m_ptZoomStart; // 框选起点(屏幕坐标)
|
||
CPoint m_ptZoomCurrent; // 框选当前点(屏幕坐标)
|
||
bool m_bZoomDragging = false; // 是否正在拖拽平移
|
||
CPoint m_ptZoomDragStart; // 拖拽起点(用于点击检测)
|
||
CPoint m_ptZoomDragLast; // 拖拽上一点(用于增量计算)
|
||
|
||
// ========== 区域截图(右键框选) ==========
|
||
bool m_bSelectingShot = false; // 是否正在右键框选截图
|
||
CPoint m_ptShotStart; // 右键框选起点(屏幕坐标)
|
||
CPoint m_ptShotCurrent; // 右键框选当前点(屏幕坐标)
|
||
|
||
// ========== 远程ROI功能(Z按钮) ==========
|
||
bool m_bROIArmed = false; // Z已点击,等待拖选
|
||
bool m_bROIActive = false; // ROI已发送到远程,Z高亮
|
||
bool m_bSelectingROI = false; // 正在拖选ROI区域
|
||
CPoint m_ptROIStart; // 拖选起点(屏幕坐标)
|
||
CPoint m_ptROICurrent; // 拖选当前点(屏幕坐标)
|
||
void SendROICommand(const RECT& rc); // 发送COMMAND_SCREEN_ROI(不依赖控制模式)
|
||
void ResetROI(); // 清除ROI并通知远程
|
||
|
||
void ResetZoom(); // 重置放大状态
|
||
CPoint ScreenToImage(CPoint pt); // 屏幕坐标转原图坐标
|
||
CPoint ImageToScreen(CPoint pt); // 原图坐标转屏幕坐标
|
||
bool ScreenRectToImageRect(const CRect& rcScreen, CRect& rcImage); // 选框坐标→原图坐标
|
||
void SaveRegionScreenshot(const CRect& rcImage); // 保存裁剪区域为 BMP
|
||
|
||
CString m_aviFile;
|
||
CBmpToAvi m_aviStream;
|
||
|
||
// 传输速率统计
|
||
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)
|
||
|
||
// 自适应质量
|
||
struct {
|
||
bool enabled = false; // 是否启用自适应 (默认关闭)
|
||
int currentLevel = QUALITY_HIGH; // 当前质量等级
|
||
int currentMaxWidth = 0; // 当前分辨率限制 (0=原始)
|
||
int lastRTT = 0; // 上次RTT值
|
||
ULONGLONG lastChangeTime = 0; // 上次切换时间
|
||
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; // 分辨率切换中,阻止解码
|
||
|
||
// ========== 音频播放 ==========
|
||
// m_Settings.AudioEnabled 表示是否启用音频(与客户端同步)
|
||
BOOL m_bAudioPlaying = FALSE; // 音频是否正在播放
|
||
HWAVEOUT m_hWaveOut = NULL; // 波形输出设备句柄
|
||
WAVEFORMATEX m_AudioFormat = {}; // 音频格式
|
||
static const int AUDIO_BUFFER_COUNT = 8; // 缓冲区数量(增加到8个)
|
||
WAVEHDR m_WaveHdr[AUDIO_BUFFER_COUNT] = {}; // 波形头
|
||
LPBYTE m_pAudioBuf[AUDIO_BUFFER_COUNT] = {};// 音频缓冲区
|
||
int m_nAudioBufIndex = 0; // 当前缓冲区索引
|
||
static const DWORD AUDIO_BUF_SIZE = 8192; // 8KB 每个缓冲区(更小更频繁)
|
||
|
||
// 环形缓冲区(吸收网络抖动)
|
||
static const DWORD RING_BUF_SIZE = 65536; // 64KB 环形缓冲区
|
||
BYTE* m_pRingBuf = nullptr; // 环形缓冲区
|
||
DWORD m_nRingHead = 0; // 写入位置
|
||
DWORD m_nRingTail = 0; // 读取位置
|
||
DWORD m_nRingDataLen = 0; // 缓冲数据量
|
||
int m_nPrebufferCount = 0; // 预缓冲计数
|
||
static const int PREBUFFER_TARGET = 5; // 预缓冲目标(积累5个包再开始播放,约50ms)
|
||
|
||
BYTE m_nAudioCompression = 0; // 音频压缩类型 (AudioCompression)
|
||
#if USING_OPUS
|
||
void* m_pOpusDecoder = nullptr; // Opus 解码器
|
||
short* m_pOpusDecodeBuffer = nullptr; // Opus 解码输出缓冲区
|
||
#endif
|
||
|
||
// 网页端音频发送状态
|
||
BOOL m_bAudioFormatSent = FALSE; // 是否已发送格式信息到网页
|
||
AudioFormat m_AudioFormatWeb = {}; // 上次发送给网页的格式
|
||
|
||
// 音频到网页的多线程同步
|
||
std::mutex m_AudioWebMutex; // 保护音频发送状态的互斥锁
|
||
// 注意:m_Settings.AudioEnabled 是全局的音频启用/禁用状态
|
||
|
||
void OnAudioData(BYTE* pData, UINT32 len); // 处理音频数据
|
||
BOOL InitAudioPlayback(const AudioFormat* fmt); // 初始化音频播放
|
||
void StopAudioPlayback(); // 停止音频播放
|
||
void DisableAudio(); // 禁用音频(从网页命令)
|
||
void EnableAudio(); // 启用音频(从网页命令)
|
||
LRESULT OnAudioToggleFromWeb(WPARAM wParam, LPARAM lParam); // PostMessage 处理器
|
||
void SendAudioCtrl(BYTE enable, BYTE persist); // 发送音频控制命令
|
||
void FeedAudioBuffers(); // 填充音频缓冲区
|
||
void SendAudioToWeb(const BYTE* pAudioData, UINT32 len, const WAVEFORMATEX* pFormat, BYTE compression); // 发送音频到网页 (compression=AudioCompression)
|
||
|
||
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); // 更新质量菜单勾选状态
|
||
|
||
void OnTimer(UINT_PTR nIDEvent);
|
||
void UpdateWindowTitle();
|
||
|
||
bool Decode(LPBYTE Buffer, int size);
|
||
void EnterFullScreen();
|
||
bool LeaveFullScreen();
|
||
void UpdateCtrlStatus(BOOL ctrl);
|
||
void OnDropFiles(HDROP hDropInfo);
|
||
|
||
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
|
||
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
|
||
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
|
||
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
|
||
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
|
||
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
|
||
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
|
||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
||
afx_msg void OnMouseLeave();
|
||
afx_msg void OnKillFocus(CWnd* pNewWnd);
|
||
afx_msg void OnCaptureChanged(CWnd* pWnd);
|
||
afx_msg void OnSize(UINT nType, int cx, int cy);
|
||
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
|
||
afx_msg LRESULT OnDisconnect(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnWaveOutDone(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnRecvFileV2Chunk(WPARAM wParam, LPARAM lParam);
|
||
afx_msg LRESULT OnRecvFileV2Complete(WPARAM wParam, LPARAM lParam);
|
||
afx_msg void OnExitFullscreen()
|
||
{
|
||
BYTE cmd[4] = { CMD_FULL_SCREEN, m_Settings.FullScreen = FALSE };
|
||
m_ContextObject->Send2Client(cmd, sizeof(cmd));
|
||
LeaveFullScreen();
|
||
}
|
||
afx_msg void OnShowStatusInfo()
|
||
{
|
||
if (m_pStatusInfoWnd) m_pStatusInfoWnd->Show();
|
||
}
|
||
afx_msg void OnHideStatusInfo()
|
||
{
|
||
if (m_pStatusInfoWnd) m_pStatusInfoWnd->Hide();
|
||
}
|
||
|
||
protected:
|
||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||
|
||
DECLARE_MESSAGE_MAP()
|
||
public:
|
||
void PrepareDrawing(const LPBITMAPINFO bmp);
|
||
virtual BOOL OnInitDialog();
|
||
afx_msg void OnClose();
|
||
afx_msg void OnPaint();
|
||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
||
BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
|
||
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
|
||
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
||
void OnLButtonDblClk(UINT nFlags, CPoint point);
|
||
};
|