Feat(client): complete the macOS feature set (phase 0 and 1)
Phase 0 makes implementations that already existed reachable. macOS now declares TERMINAL, SCREEN_CLIPBOARD, PROCESS and C2C_RECV_ACK; PROCESS is a new bit and Linux declares it too. SystemManager was dead code -- its constructor took a second argument and it did not derive IOCPManager, so the sub-connection skeleton could never instantiate it -- and now matches the createHandler/OnReceive contract, so COMMAND_SYSTEM really spawns a sub-connection (proc_listpids, SIGKILL). DataProcess always gets a NULL user, so main.mm keeps a g_pMainClient handle and the V2 C2C receiver finally answers TOKEN_C2C_RECV_RESULT. The server asks for SupportsTerminal() on MAC for exec_command / terminal_* and for SupportsProcess() for kill_process, so an old build gets "client is too old" instead of a command nobody answers; kToolPlatforms and mcp/tools.json follow. http_probe stays win/lnx: the terminal works on macOS, but the probe uses GNU-only base64 -w. Phase 1 is POSIX parity. ScreenPreview captures through CGDisplayCreateImage, scales and ships BGRX for the server to encode, and the capability is only declared when preflight or a real capture says the display is readable. ActivityHistory samples the frontmost layer-0 window once a second and prints the same records as Windows and Linux. COMMAND_SCREEN_KEYFRAME_REQ is now consumed by Linux (x264 IDR) and macOS (VideoToolbox force keyframe): the receive thread raises a flag, the capture thread -- which owns the encoder -- consumes it and puts it back if the frame never went out. The macOS quality level persists in NSUserDefaults because main.mm rewrites config.conf. Linux client and Debug x64 server rebuild green; check_platform_table PASS. Not built or run on a Mac. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
c2b59f5d4a
commit
06b93f7bdb
19 files changed
+890
-121
No files matched your search
+30
-3
@@ -556,6 +556,13 @@ public:
|
||||
}
|
||||
break;
|
||||
|
||||
case COMMAND_SCREEN_KEYFRAME_REQ:
|
||||
// Web 屏幕墙恢复/新加入者请求:下一帧强制 IDR。只置标志,
|
||||
// 编码器实例归采集线程所有(COMMAND_SCREEN_KEYFRAME_REQ 与 CMD_QUALITY_LEVEL
|
||||
// 一样在屏幕子连接的接收线程上处理)。
|
||||
m_keyframeRequested.store(true);
|
||||
break;
|
||||
|
||||
case COMMAND_SCREEN_SET_CLIPBOARD:
|
||||
// 服务端设置剪贴板: [cmd:1][text:N]
|
||||
if (size > 1) {
|
||||
@@ -967,6 +974,9 @@ private:
|
||||
LinuxConfig m_config; // 配置持久化 (~/.config/ghost/config.conf)
|
||||
std::atomic<int> m_bFullScreen; // 全屏偏好(主控端下发,随 ScreenSettings 上报)
|
||||
std::atomic<int> m_bRemoteCursor; // 远程光标偏好(同上)
|
||||
// Web 端请求下一帧强制 IDR(COMMAND_SCREEN_KEYFRAME_REQ)。接收线程置位、
|
||||
// 采集线程消费:编码器实例只在采集线程里创建/销毁,接收线程不能直接碰。
|
||||
std::atomic<bool> m_keyframeRequested{false};
|
||||
|
||||
// H264 编码器
|
||||
std::unique_ptr<X264Encoder> m_h264Encoder;
|
||||
@@ -1068,6 +1078,18 @@ private:
|
||||
// 发送 H264 编码帧
|
||||
void SendH264Frame(bool forceKeyframe = false)
|
||||
{
|
||||
// 强制 IDR 请求在调用点已经 exchange 掉,只有真的把这一帧编出来才算消费成功。
|
||||
// 中途任何提前返回(抓屏失败 / 没连接 / 编码器开不起来 / 编码失败)都把它还回去,
|
||||
// 否则 Web 端要等编码器下一次自然 IDR(最长一个 GOP)才能解出画面。
|
||||
struct RearmOnFailure {
|
||||
std::atomic<bool>& flag;
|
||||
bool force;
|
||||
bool consumed;
|
||||
RearmOnFailure(std::atomic<bool>& f, bool force_)
|
||||
: flag(f), force(force_), consumed(false) {}
|
||||
~RearmOnFailure() { if (force && !consumed) flag.store(true); }
|
||||
} rearm(m_keyframeRequested, forceKeyframe);
|
||||
|
||||
if (!CaptureScreen(m_currFrame)) return;
|
||||
if (!m_client) return;
|
||||
|
||||
@@ -1096,7 +1118,7 @@ private:
|
||||
int result = m_h264Encoder->encode(
|
||||
m_currFrame.data(), 32, m_bmpHeader.biWidth * 4,
|
||||
m_bmpHeader.biWidth, m_bmpHeader.biHeight,
|
||||
&encodedData, &encodedSize, 1);
|
||||
&encodedData, &encodedSize, 1, forceKeyframe);
|
||||
|
||||
if (result != 0 || !encodedData || encodedSize == 0) {
|
||||
return;
|
||||
@@ -1117,6 +1139,7 @@ private:
|
||||
|
||||
memcpy(&packet[headerSize], encodedData, encodedSize);
|
||||
m_client->Send2Server((char*)packet.data(), packet.size());
|
||||
rearm.consumed = true;
|
||||
}
|
||||
|
||||
// 差异比较算法(支持 DIFF/RGB565/GRAY)
|
||||
@@ -1333,10 +1356,13 @@ private:
|
||||
if (algo != currentAlgo) {
|
||||
currentAlgo = algo;
|
||||
if (algo == ALGORITHM_H264) {
|
||||
// 切换到 H264,发送关键帧
|
||||
// 切换到 H264,发送关键帧;这一帧本身就是关键帧,
|
||||
// 挂起的强制 IDR 请求顺手清掉,别下一帧再打一次。
|
||||
m_keyframeRequested.store(false);
|
||||
SendH264Frame(true);
|
||||
} else {
|
||||
// 切换离开 H264,关闭编码器并发送完整帧
|
||||
m_keyframeRequested.store(false); // 关键帧请求对非 H264 无意义
|
||||
if (m_h264Encoder) {
|
||||
m_h264Encoder->close();
|
||||
m_h264Encoder.reset();
|
||||
@@ -1346,7 +1372,8 @@ private:
|
||||
} else {
|
||||
// 正常帧
|
||||
if (algo == ALGORITHM_H264) {
|
||||
SendH264Frame(false);
|
||||
// 服务端的强制 IDR 请求在这里消费:下一帧就是关键帧。
|
||||
SendH264Frame(m_keyframeRequested.exchange(false));
|
||||
} else {
|
||||
SendDiffFrame();
|
||||
}
|
||||
|
||||
+6
-1
@@ -165,12 +165,13 @@ public:
|
||||
* @param outData Output: pointer to encoded H264 data
|
||||
* @param outSize Output: size of encoded data
|
||||
* @param direction 1 = normal, -1 = vertical flip
|
||||
* @param forceKeyframe true = 本帧强制 IDR(服务端 COMMAND_SCREEN_KEYFRAME_REQ)
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int encode(uint8_t* bgra, uint8_t bpp, uint32_t stride,
|
||||
uint32_t width, uint32_t height,
|
||||
uint8_t** outData, uint32_t* outSize,
|
||||
int direction = 1)
|
||||
int direction = 1, bool forceKeyframe = false)
|
||||
{
|
||||
if (!m_encoder || !m_picIn || !fn_x264_encoder_encode) {
|
||||
return -1;
|
||||
@@ -197,9 +198,13 @@ public:
|
||||
}
|
||||
|
||||
// Encode
|
||||
// Web 端新加入/恢复时服务端会发 COMMAND_SCREEN_KEYFRAME_REQ:把本帧标成 IDR,
|
||||
// 参考链立即重建,不必等 keyint_max(15 秒)后的下一个关键帧。
|
||||
m_picIn->i_type = forceKeyframe ? X264_TYPE_IDR : X264_TYPE_AUTO;
|
||||
x264_nal_t* pNal = nullptr;
|
||||
int iNal = 0;
|
||||
int encodeSize = fn_x264_encoder_encode(m_encoder, &pNal, &iNal, m_picIn, m_picOut);
|
||||
m_picIn->i_type = X264_TYPE_AUTO; // 只对这一帧有效
|
||||
|
||||
if (encodeSize < 0) {
|
||||
return -4;
|
||||
|
||||
Reference in new issue
Block a user