mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-12-20 22:49:11 +08:00
Compare commits
1 Commits
v1.1.4
...
a006eacf0b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a006eacf0b |
24
.github/workflows/build.yml
vendored
24
.github/workflows/build.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
|||||||
id: set_deb_version
|
id: set_deb_version
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
BUILD_DATE=$(date +%Y%m%d)
|
||||||
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
||||||
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
else
|
else
|
||||||
@@ -55,7 +55,7 @@ jobs:
|
|||||||
XMAKE_GLOBALDIR: /data
|
XMAKE_GLOBALDIR: /data
|
||||||
run: |
|
run: |
|
||||||
ls -la $XMAKE_GLOBALDIR
|
ls -la $XMAKE_GLOBALDIR
|
||||||
xmake f --CROSSDESK_VERSION=${LEGAL_VERSION} --USE_CUDA=true --root -y
|
xmake f --CROSSDESK_VERSION=${LEGAL_VERSION} --root -y
|
||||||
xmake b -vy --root crossdesk
|
xmake b -vy --root crossdesk
|
||||||
|
|
||||||
- name: Decode and save certificate
|
- name: Decode and save certificate
|
||||||
@@ -101,7 +101,7 @@ jobs:
|
|||||||
id: set_deb_version
|
id: set_deb_version
|
||||||
run: |
|
run: |
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
BUILD_DATE=$(date +%Y%m%d)
|
||||||
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
if [[ ! "${VERSION_NUM}" =~ ^[0-9] ]]; then
|
||||||
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
LEGAL_VERSION="v0.0.0-${VERSION_NUM}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
else
|
else
|
||||||
@@ -120,7 +120,7 @@ jobs:
|
|||||||
CUDA_PATH: /usr/local/cuda
|
CUDA_PATH: /usr/local/cuda
|
||||||
XMAKE_GLOBALDIR: /data
|
XMAKE_GLOBALDIR: /data
|
||||||
run: |
|
run: |
|
||||||
xmake f --CROSSDESK_VERSION=${LEGAL_VERSION} --USE_CUDA=true --root -y
|
xmake f --CROSSDESK_VERSION=${LEGAL_VERSION} --root -y
|
||||||
xmake b -vy --root crossdesk
|
xmake b -vy --root crossdesk
|
||||||
|
|
||||||
- name: Decode and save certificate
|
- name: Decode and save certificate
|
||||||
@@ -164,7 +164,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
VERSION="${GITHUB_REF##*/}"
|
VERSION="${GITHUB_REF##*/}"
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
BUILD_DATE=$(date +%Y%m%d)
|
||||||
VERSION_NUM="v${VERSION#v}-${BUILD_DATE}-${SHORT_SHA}"
|
VERSION_NUM="v${VERSION#v}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
echo "VERSION_NUM=${VERSION_NUM}" >> $GITHUB_ENV
|
echo "VERSION_NUM=${VERSION_NUM}" >> $GITHUB_ENV
|
||||||
echo "VERSION_NUM=${VERSION_NUM}"
|
echo "VERSION_NUM=${VERSION_NUM}"
|
||||||
@@ -174,7 +174,7 @@ jobs:
|
|||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.xmake/packages
|
path: ~/.xmake/packages
|
||||||
key: ${{ runner.os }}-xmake-deps-${{ matrix.cache-key }}-${{ github.sha }}
|
key: ${{ runner.os }}-xmake-deps-${{ matrix.cache-key }}-${{ hashFiles('**/xmake.lua') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-xmake-deps-${{ matrix.cache-key }}-
|
${{ runner.os }}-xmake-deps-${{ matrix.cache-key }}-
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Build CrossDesk
|
- name: Build CrossDesk
|
||||||
run: |
|
run: |
|
||||||
xmake f --CROSSDESK_VERSION=${VERSION_NUM} --USE_CUDA=true -y
|
xmake f --CROSSDESK_VERSION=${VERSION_NUM} -y
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
|
|
||||||
- name: Decode and save certificate
|
- name: Decode and save certificate
|
||||||
@@ -229,7 +229,7 @@ jobs:
|
|||||||
$version = $version -replace '^v', ''
|
$version = $version -replace '^v', ''
|
||||||
$version = $version -replace '/', '-'
|
$version = $version -replace '/', '-'
|
||||||
$SHORT_SHA = $env:GITHUB_SHA.Substring(0,7)
|
$SHORT_SHA = $env:GITHUB_SHA.Substring(0,7)
|
||||||
$BUILD_DATE = ([System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId((Get-Date), "China Standard Time")).ToString("yyyyMMdd")
|
$BUILD_DATE = Get-Date -Format "yyyyMMdd"
|
||||||
echo "VERSION_NUM=v$version-$BUILD_DATE-$SHORT_SHA" >> $env:GITHUB_ENV
|
echo "VERSION_NUM=v$version-$BUILD_DATE-$SHORT_SHA" >> $env:GITHUB_ENV
|
||||||
echo "BUILD_DATE=$BUILD_DATE" >> $env:GITHUB_ENV
|
echo "BUILD_DATE=$BUILD_DATE" >> $env:GITHUB_ENV
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ jobs:
|
|||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: D:\xmake_global\.xmake\packages
|
path: D:\xmake_global\.xmake\packages
|
||||||
key: ${{ runner.os }}-xmake-deps-intel-${{ github.sha }}
|
key: ${{ runner.os }}-xmake-deps-intel-${{ hashFiles('**/xmake.lua') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-xmake-deps-intel-
|
${{ runner.os }}-xmake-deps-intel-
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Build CrossDesk
|
- name: Build CrossDesk
|
||||||
run: |
|
run: |
|
||||||
xmake f --CROSSDESK_VERSION=${{ env.VERSION_NUM }} --USE_CUDA=true -y
|
xmake f --CROSSDESK_VERSION=${{ env.VERSION_NUM }} -y
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
|
|
||||||
- name: Decode and save certificate
|
- name: Decode and save certificate
|
||||||
@@ -340,8 +340,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
VERSION="${GITHUB_REF##*/}"
|
VERSION="${GITHUB_REF##*/}"
|
||||||
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
||||||
BUILD_DATE=$(TZ=Asia/Shanghai date +%Y%m%d)
|
BUILD_DATE=$(date +%Y%m%d)
|
||||||
BUILD_DATE_ISO=$(TZ=Asia/Shanghai date +%Y-%m-%d)
|
BUILD_DATE_ISO=$(date +%Y-%m-%d)
|
||||||
VERSION_NUM="${VERSION#v}-${BUILD_DATE}-${SHORT_SHA}"
|
VERSION_NUM="${VERSION#v}-${BUILD_DATE}-${SHORT_SHA}"
|
||||||
VERSION_WITH_V="v${VERSION_NUM}"
|
VERSION_WITH_V="v${VERSION_NUM}"
|
||||||
VERSION_ONLY="${VERSION#v}"
|
VERSION_ONLY="${VERSION#v}"
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -11,14 +11,8 @@
|
|||||||
|
|
||||||
[ [English](README_EN.md) / 中文 ]
|
[ [English](README_EN.md) / 中文 ]
|
||||||
|
|
||||||
PC 客户端
|
|
||||||

|

|
||||||
|
|
||||||
Web 客户端
|
|
||||||
<p align="center">
|
|
||||||
<img width="850" height="550" alt="6bddcbed47ffd4b9988a4037c7f4f524" src="https://github.com/user-attachments/assets/e44f73f9-24ac-46a3-a189-b7f8b6669881" />
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
CrossDesk 是一个轻量级的跨平台远程桌面软件,支持 Web 端控制远程设备。
|
CrossDesk 是一个轻量级的跨平台远程桌面软件,支持 Web 端控制远程设备。
|
||||||
@@ -61,7 +55,7 @@ CrossDesk 是 [MiniRTC](https://github.com/kunkundi/minirtc.git) 实时音视频
|
|||||||
Linux环境下需安装以下包:
|
Linux环境下需安装以下包:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install -y software-properties-common git curl unzip build-essential libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev libxfixes-dev libxv-dev libxtst-dev libasound2-dev libsndio-dev libxcb-shm0-dev libasound2-dev libpulse-dev
|
sudo apt-get install -y software-properties-common git curl unzip build-essential libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev libxv-dev libxtst-dev libasound2-dev libsndio-dev libxcb-shm0-dev libasound2-dev libpulse-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
编译
|
编译
|
||||||
@@ -76,14 +70,7 @@ git submodule update
|
|||||||
|
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
```
|
```
|
||||||
编译选项
|
|
||||||
```
|
|
||||||
--USE_CUDA=true/false: 启用 CUDA 硬件编解码,默认不启用
|
|
||||||
--CROSSDESK_VERSION=xxx: 指定 CrossDesk 的版本
|
|
||||||
|
|
||||||
# 示例
|
|
||||||
xmake f --CROSSDESK_VERSION=1.0.0 --USE_CUDA=true
|
|
||||||
```
|
|
||||||
运行
|
运行
|
||||||
```
|
```
|
||||||
xmake r crossdesk
|
xmake r crossdesk
|
||||||
@@ -91,14 +78,13 @@ xmake r crossdesk
|
|||||||
|
|
||||||
### 无 CUDA 环境下的开发支持
|
### 无 CUDA 环境下的开发支持
|
||||||
|
|
||||||
对于**未安装 CUDA 环境的 Linux 开发者,如果希望编译后的成果物拥有硬件编解码能力**,这里提供了预配置的 [Ubuntu 22.04 Docker 镜像](https://hub.docker.com/r/crossdesk/ubuntu22.04)。该镜像内置必要的构建依赖,可在容器中开箱即用,无需额外配置即可直接编译项目。
|
对于**未安装 CUDA 环境的 Linux 开发者**,这里提供了预配置的 [Ubuntu 22.04 Docker 镜像](https://hub.docker.com/r/crossdesk/ubuntu22.04)。该镜像内置必要的构建依赖,可在容器中开箱即用,无需额外配置即可直接编译项目。
|
||||||
|
|
||||||
进入容器,下载工程后执行:
|
进入容器,下载工程后执行:
|
||||||
```
|
```
|
||||||
export CUDA_PATH=/usr/local/cuda
|
export CUDA_PATH=/usr/local/cuda
|
||||||
export XMAKE_GLOBALDIR=/data
|
export XMAKE_GLOBALDIR=/data
|
||||||
|
|
||||||
xmake f --USE_CUDA=true
|
|
||||||
xmake b --root -vy crossdesk
|
xmake b --root -vy crossdesk
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -120,7 +106,6 @@ set CUDA_PATH=path_to_cuda_installdir
|
|||||||
```
|
```
|
||||||
重新执行:
|
重新执行:
|
||||||
```
|
```
|
||||||
xmake f --USE_CUDA=true
|
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -181,7 +166,7 @@ sudo docker run -d \
|
|||||||
-v /path/to/your/certs:/crossdesk-server/certs \
|
-v /path/to/your/certs:/crossdesk-server/certs \
|
||||||
-v /path/to/your/db:/crossdesk-server/db \
|
-v /path/to/your/db:/crossdesk-server/db \
|
||||||
-v /path/to/your/logs:/crossdesk-server/logs \
|
-v /path/to/your/logs:/crossdesk-server/logs \
|
||||||
crossdesk/crossdesk-server:v1.1.1
|
crossdesk/crossdesk-server:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
上述命令中,用户需注意的参数如下:
|
上述命令中,用户需注意的参数如下:
|
||||||
|
|||||||
21
README_EN.md
21
README_EN.md
@@ -11,14 +11,8 @@
|
|||||||
|
|
||||||
[ [中文](README.md) / English ]
|
[ [中文](README.md) / English ]
|
||||||
|
|
||||||
PC Client
|
|
||||||

|

|
||||||
|
|
||||||
Web Client
|
|
||||||
<p align="center">
|
|
||||||
<img width="850" height="550" alt="6bddcbed47ffd4b9988a4037c7f4f524" src="https://github.com/user-attachments/assets/e44f73f9-24ac-46a3-a189-b7f8b6669881" />
|
|
||||||
</p>
|
|
||||||
|
|
||||||
# Intro
|
# Intro
|
||||||
|
|
||||||
CrossDesk is a lightweight cross-platform remote desktop software.
|
CrossDesk is a lightweight cross-platform remote desktop software.
|
||||||
@@ -64,7 +58,7 @@ Requirements:
|
|||||||
Following packages need to be installed on Linux:
|
Following packages need to be installed on Linux:
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install -y software-properties-common git curl unzip build-essential libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev libxfixes-dev libxv-dev libxtst-dev libasound2-dev libsndio-dev libxcb-shm0-dev libasound2-dev libpulse-dev
|
sudo apt-get install -y software-properties-common git curl unzip build-essential libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxcb-randr0-dev libxcb-xtest0-dev libxcb-xinerama0-dev libxcb-shape0-dev libxcb-xkb-dev libxcb-xfixes0-dev libxv-dev libxtst-dev libasound2-dev libsndio-dev libxcb-shm0-dev libasound2-dev libpulse-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Build:
|
Build:
|
||||||
@@ -79,14 +73,7 @@ git submodule update
|
|||||||
|
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
```
|
```
|
||||||
Build options:
|
|
||||||
```
|
|
||||||
--USE_CUDA=true/false: enable CUDA acceleration codec, default: false
|
|
||||||
--CROSSDESK_VERSION=xxx: set the version number
|
|
||||||
|
|
||||||
# example:
|
|
||||||
xmake f --CROSSDESK_VERSION=1.0.0 --USE_CUDA=true
|
|
||||||
```
|
|
||||||
Run:
|
Run:
|
||||||
```
|
```
|
||||||
xmake r crossdesk
|
xmake r crossdesk
|
||||||
@@ -94,7 +81,7 @@ xmake r crossdesk
|
|||||||
|
|
||||||
#### Development Without CUDA Environment
|
#### Development Without CUDA Environment
|
||||||
|
|
||||||
For **Linux developers who do not have a CUDA environment installed and want to enable hardware codec feature**, a preconfigured [Ubuntu 22.04 Docker image](https://hub.docker.com/r/crossdesk/ubuntu22.04) is provided.
|
For **Linux developers who do not have a CUDA environment** installed, a preconfigured [Ubuntu 22.04 Docker image](https://hub.docker.com/r/crossdesk/ubuntu22.04) is provided.
|
||||||
This image comes with all required build dependencies and allows you to build the project directly inside the container without any additional setup.
|
This image comes with all required build dependencies and allows you to build the project directly inside the container without any additional setup.
|
||||||
|
|
||||||
After entering the container, download the project and run:
|
After entering the container, download the project and run:
|
||||||
@@ -102,7 +89,6 @@ After entering the container, download the project and run:
|
|||||||
export CUDA_PATH=/usr/local/cuda
|
export CUDA_PATH=/usr/local/cuda
|
||||||
export XMAKE_GLOBALDIR=/data
|
export XMAKE_GLOBALDIR=/data
|
||||||
|
|
||||||
xmake f --USE_CUDA=true
|
|
||||||
xmake b --root -vy crossdesk
|
xmake b --root -vy crossdesk
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -125,7 +111,6 @@ set CUDA_PATH=path_to_cuda_installdir:
|
|||||||
```
|
```
|
||||||
Then re-run:
|
Then re-run:
|
||||||
```
|
```
|
||||||
xmake f --USE_CUDA=true
|
|
||||||
xmake b -vy crossdesk
|
xmake b -vy crossdesk
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -189,7 +174,7 @@ sudo docker run -d \
|
|||||||
-v /path/to/your/certs:/crossdesk-server/certs \
|
-v /path/to/your/certs:/crossdesk-server/certs \
|
||||||
-v /path/to/your/db:/crossdesk-server/db \
|
-v /path/to/your/db:/crossdesk-server/db \
|
||||||
-v /path/to/your/logs:/crossdesk-server/logs \
|
-v /path/to/your/logs:/crossdesk-server/logs \
|
||||||
crossdesk/crossdesk-server:v1.1.1
|
crossdesk/crossdesk-server:v1.1.0
|
||||||
```
|
```
|
||||||
|
|
||||||
The parameters you need to pay attention to are as follows:
|
The parameters you need to pay attention to are as follows:
|
||||||
|
|||||||
@@ -11,19 +11,9 @@
|
|||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif __APPLE__
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <mach-o/dyld.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#else
|
#else
|
||||||
#include <errno.h>
|
Daemon* Daemon::instance_ = nullptr;
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -33,10 +23,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
Daemon* Daemon::instance_ = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// get executable file path
|
// get executable file path
|
||||||
static std::string GetExecutablePath() {
|
static std::string GetExecutablePath() {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -45,16 +31,6 @@ static std::string GetExecutablePath() {
|
|||||||
if (length > 0 && length < sizeof(path)) {
|
if (length > 0 && length < sizeof(path)) {
|
||||||
return std::string(path);
|
return std::string(path);
|
||||||
}
|
}
|
||||||
#elif __APPLE__
|
|
||||||
char path[PATH_MAX];
|
|
||||||
uint32_t size = sizeof(path);
|
|
||||||
if (_NSGetExecutablePath(path, &size) == 0) {
|
|
||||||
char resolved_path[PATH_MAX];
|
|
||||||
if (realpath(path, resolved_path) != nullptr) {
|
|
||||||
return std::string(resolved_path);
|
|
||||||
}
|
|
||||||
return std::string(path);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
ssize_t count = readlink("/proc/self/exe", path, sizeof(path) - 1);
|
ssize_t count = readlink("/proc/self/exe", path, sizeof(path) - 1);
|
||||||
@@ -78,90 +54,35 @@ Daemon::Daemon(const std::string& name)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Daemon::stop() { running_ = false; }
|
void Daemon::stop() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
running_ = false;
|
||||||
|
#else
|
||||||
|
running_ = false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool Daemon::isRunning() const { return running_; }
|
bool Daemon::isRunning() const {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return running_;
|
||||||
|
#else
|
||||||
|
return running_;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool Daemon::start(MainLoopFunc loop) {
|
bool Daemon::start(MainLoopFunc loop) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
running_ = true;
|
running_ = true;
|
||||||
return runWithRestart(loop);
|
return runWithRestart(loop);
|
||||||
#elif __APPLE__
|
|
||||||
// macOS: Use child process monitoring (like Windows) to preserve GUI
|
|
||||||
running_ = true;
|
|
||||||
return runWithRestart(loop);
|
|
||||||
#else
|
#else
|
||||||
// linux: Daemonize first, then run with restart monitoring
|
|
||||||
instance_ = this;
|
instance_ = this;
|
||||||
|
runUnix(loop);
|
||||||
// check if running from terminal before fork
|
return true;
|
||||||
bool from_terminal =
|
|
||||||
(isatty(STDIN_FILENO) != 0) || (isatty(STDOUT_FILENO) != 0);
|
|
||||||
|
|
||||||
// first fork: detach from terminal
|
|
||||||
pid_t pid = fork();
|
|
||||||
if (pid < 0) {
|
|
||||||
std::cerr << "Failed to fork daemon process" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (pid > 0) _exit(0);
|
|
||||||
|
|
||||||
if (setsid() < 0) {
|
|
||||||
std::cerr << "Failed to create new session" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
if (pid < 0) {
|
|
||||||
std::cerr << "Failed to fork daemon process (second fork)" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (pid > 0) _exit(0);
|
|
||||||
|
|
||||||
umask(0);
|
|
||||||
chdir("/");
|
|
||||||
|
|
||||||
// redirect file descriptors: keep stdout/stderr if from terminal, else
|
|
||||||
// redirect to /dev/null
|
|
||||||
int fd = open("/dev/null", O_RDWR);
|
|
||||||
if (fd >= 0) {
|
|
||||||
dup2(fd, STDIN_FILENO);
|
|
||||||
if (!from_terminal) {
|
|
||||||
dup2(fd, STDOUT_FILENO);
|
|
||||||
dup2(fd, STDERR_FILENO);
|
|
||||||
}
|
|
||||||
if (fd > 2) close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up signal handlers
|
|
||||||
signal(SIGTERM, [](int) {
|
|
||||||
if (instance_) instance_->stop();
|
|
||||||
});
|
|
||||||
signal(SIGINT, [](int) {
|
|
||||||
if (instance_) instance_->stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
// ignore SIGPIPE
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
|
||||||
|
|
||||||
// set up SIGCHLD handler to reap zombie processes
|
|
||||||
struct sigaction sa_chld;
|
|
||||||
sa_chld.sa_handler = [](int) {
|
|
||||||
// reap zombie processes
|
|
||||||
while (waitpid(-1, nullptr, WNOHANG) > 0) {
|
|
||||||
// continue until no more zombie children
|
|
||||||
}
|
|
||||||
};
|
|
||||||
sigemptyset(&sa_chld.sa_mask);
|
|
||||||
sa_chld.sa_flags = SA_RESTART | SA_NOCLDSTOP;
|
|
||||||
sigaction(SIGCHLD, &sa_chld, nullptr);
|
|
||||||
|
|
||||||
running_ = true;
|
|
||||||
return runWithRestart(loop);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
// windows: execute loop and catch C++ exceptions
|
||||||
static int RunLoopCatchCpp(Daemon::MainLoopFunc& loop) {
|
static int RunLoopCatchCpp(Daemon::MainLoopFunc& loop) {
|
||||||
try {
|
try {
|
||||||
loop();
|
loop();
|
||||||
@@ -175,11 +96,12 @@ static int RunLoopCatchCpp(Daemon::MainLoopFunc& loop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// windows: Use SEH wrapper function to catch system-level crashes
|
||||||
static int RunLoopWithSEH(Daemon::MainLoopFunc& loop) {
|
static int RunLoopWithSEH(Daemon::MainLoopFunc& loop) {
|
||||||
__try {
|
__try {
|
||||||
return RunLoopCatchCpp(loop);
|
return RunLoopCatchCpp(loop);
|
||||||
} __except (EXCEPTION_EXECUTE_HANDLER) {
|
} __except (EXCEPTION_EXECUTE_HANDLER) {
|
||||||
// catch system-level crashes (access violation, divide by zero, etc.)
|
// Catch system-level crashes (access violation, divide by zero, etc.)
|
||||||
DWORD code = GetExceptionCode();
|
DWORD code = GetExceptionCode();
|
||||||
std::cerr << "System crash detected (SEH exception code: 0x" << std::hex
|
std::cerr << "System crash detected (SEH exception code: 0x" << std::hex
|
||||||
<< code << std::dec << ")" << std::endl;
|
<< code << std::dec << ")" << std::endl;
|
||||||
@@ -188,7 +110,9 @@ static int RunLoopWithSEH(Daemon::MainLoopFunc& loop) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// run with restart logic: parent monitors child process and restarts on crash
|
// run function with restart logic (infinite restart)
|
||||||
|
// use child process monitoring: parent process creates child process to run
|
||||||
|
// main program, monitors child process status, restarts on crash
|
||||||
bool Daemon::runWithRestart(MainLoopFunc loop) {
|
bool Daemon::runWithRestart(MainLoopFunc loop) {
|
||||||
int restart_count = 0;
|
int restart_count = 0;
|
||||||
std::string exe_path = GetExecutablePath();
|
std::string exe_path = GetExecutablePath();
|
||||||
@@ -196,6 +120,7 @@ bool Daemon::runWithRestart(MainLoopFunc loop) {
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< "Failed to get executable path, falling back to direct execution"
|
<< "Failed to get executable path, falling back to direct execution"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
// fallback to direct execution
|
||||||
while (isRunning()) {
|
while (isRunning()) {
|
||||||
try {
|
try {
|
||||||
loop();
|
loop();
|
||||||
@@ -217,6 +142,7 @@ bool Daemon::runWithRestart(MainLoopFunc loop) {
|
|||||||
STARTUPINFOA si = {sizeof(si)};
|
STARTUPINFOA si = {sizeof(si)};
|
||||||
PROCESS_INFORMATION pi = {0};
|
PROCESS_INFORMATION pi = {0};
|
||||||
|
|
||||||
|
// build command line arguments (add --child flag)
|
||||||
std::string cmd_line = "\"" + exe_path + "\" --child";
|
std::string cmd_line = "\"" + exe_path + "\" --child";
|
||||||
std::vector<char> cmd_line_buf(cmd_line.begin(), cmd_line.end());
|
std::vector<char> cmd_line_buf(cmd_line.begin(), cmd_line.end());
|
||||||
cmd_line_buf.push_back('\0');
|
cmd_line_buf.push_back('\0');
|
||||||
@@ -243,6 +169,7 @@ bool Daemon::runWithRestart(MainLoopFunc loop) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wait for child process to exit
|
||||||
DWORD exit_code = 0;
|
DWORD exit_code = 0;
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
GetExitCodeProcess(pi.hProcess, &exit_code);
|
GetExitCodeProcess(pi.hProcess, &exit_code);
|
||||||
@@ -250,57 +177,56 @@ bool Daemon::runWithRestart(MainLoopFunc loop) {
|
|||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
|
||||||
if (exit_code == 0) {
|
if (exit_code == 0) {
|
||||||
break; // normal exit
|
// normal exit
|
||||||
}
|
break;
|
||||||
|
} else {
|
||||||
|
// abnormal exit, restart
|
||||||
restart_count++;
|
restart_count++;
|
||||||
std::cerr << "Child process exited with code " << exit_code
|
std::cerr << "Child process exited with code " << exit_code
|
||||||
<< ", restarting... (attempt " << restart_count << ")"
|
<< ", restarting... (attempt " << restart_count << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// linux: use fork + exec to create child process
|
// linux: use fork + exec to create child process
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
|
// child process: execute main program, pass --child argument
|
||||||
execl(exe_path.c_str(), exe_path.c_str(), "--child", nullptr);
|
execl(exe_path.c_str(), exe_path.c_str(), "--child", nullptr);
|
||||||
_exit(1); // exec failed
|
// if exec fails, exit
|
||||||
|
_exit(1);
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
|
// parent process: wait for child process to exit
|
||||||
int status = 0;
|
int status = 0;
|
||||||
pid_t waited_pid = waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
||||||
if (waited_pid < 0) {
|
|
||||||
restart_count++;
|
|
||||||
std::cerr << "waitpid failed, errno: " << errno
|
|
||||||
<< ", restarting... (attempt " << restart_count << ")"
|
|
||||||
<< std::endl;
|
|
||||||
std::this_thread::sleep_for(
|
|
||||||
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
int exit_code = WEXITSTATUS(status);
|
int exit_code = WEXITSTATUS(status);
|
||||||
if (exit_code == 0) {
|
if (exit_code == 0) {
|
||||||
break; // normal exit
|
// normal exit
|
||||||
}
|
break;
|
||||||
|
} else {
|
||||||
|
// abnormal exit, restart
|
||||||
restart_count++;
|
restart_count++;
|
||||||
std::cerr << "Child process exited with code " << exit_code
|
std::cerr << "Child process exited with code " << exit_code
|
||||||
<< ", restarting... (attempt " << restart_count << ")"
|
<< ", restarting... (attempt " << restart_count << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} else if (WIFSIGNALED(status)) {
|
|
||||||
restart_count++;
|
|
||||||
std::cerr << "Child process crashed with signal " << WTERMSIG(status)
|
|
||||||
<< ", restarting... (attempt " << restart_count << ")"
|
|
||||||
<< std::endl;
|
|
||||||
} else {
|
|
||||||
restart_count++;
|
|
||||||
std::cerr << "Child process exited with unknown status, restarting... "
|
|
||||||
"(attempt "
|
|
||||||
<< restart_count << ")" << std::endl;
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
|
}
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
// child process terminated by signal (crash)
|
||||||
|
int sig = WTERMSIG(status);
|
||||||
|
restart_count++;
|
||||||
|
std::cerr << "Child process crashed with signal " << sig
|
||||||
|
<< ", restarting... (attempt " << restart_count << ")"
|
||||||
|
<< std::endl;
|
||||||
|
std::this_thread::sleep_for(
|
||||||
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// fork failed
|
||||||
std::cerr << "Failed to fork child process" << std::endl;
|
std::cerr << "Failed to fork child process" << std::endl;
|
||||||
std::this_thread::sleep_for(
|
std::this_thread::sleep_for(
|
||||||
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
@@ -311,3 +237,132 @@ bool Daemon::runWithRestart(MainLoopFunc loop) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
void Daemon::runUnix(MainLoopFunc loop) {
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = [](int) {};
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = 0;
|
||||||
|
sigaction(SIGPIPE, &sa, nullptr);
|
||||||
|
sigaction(SIGCHLD, &sa, nullptr);
|
||||||
|
|
||||||
|
// daemon mode: fork twice, redirect output
|
||||||
|
pid_t pid = fork();
|
||||||
|
if (pid > 0) _exit(0);
|
||||||
|
setsid();
|
||||||
|
pid = fork();
|
||||||
|
if (pid > 0) _exit(0);
|
||||||
|
umask(0);
|
||||||
|
chdir("/");
|
||||||
|
int fd = open("/dev/null", O_RDWR);
|
||||||
|
if (fd >= 0) {
|
||||||
|
dup2(fd, STDIN_FILENO);
|
||||||
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
dup2(fd, STDERR_FILENO);
|
||||||
|
if (fd > 2) close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// catch signals for exit
|
||||||
|
signal(SIGTERM, [](int) { instance_->stop(); });
|
||||||
|
signal(SIGINT, [](int) { instance_->stop(); });
|
||||||
|
|
||||||
|
// catch crash signals, use atomic flags to mark crash
|
||||||
|
static std::atomic<bool> crash_detected{false};
|
||||||
|
static std::atomic<bool> should_restart{false};
|
||||||
|
|
||||||
|
// use safer signal handling: only set flags, don't call longjmp
|
||||||
|
struct sigaction sa_crash;
|
||||||
|
sa_crash.sa_handler = [](int sig) {
|
||||||
|
const char* sig_name = "Unknown";
|
||||||
|
switch (sig) {
|
||||||
|
case SIGSEGV:
|
||||||
|
sig_name = "SIGSEGV";
|
||||||
|
break;
|
||||||
|
case SIGABRT:
|
||||||
|
sig_name = "SIGABRT";
|
||||||
|
break;
|
||||||
|
case SIGFPE:
|
||||||
|
sig_name = "SIGFPE";
|
||||||
|
break;
|
||||||
|
case SIGILL:
|
||||||
|
sig_name = "SIGILL";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cerr << "Crash signal detected: " << sig_name
|
||||||
|
<< ", will restart after process exits" << std::endl;
|
||||||
|
crash_detected = true;
|
||||||
|
should_restart = true;
|
||||||
|
// don't call longjmp, let program exit normally, restart by monitoring
|
||||||
|
// thread
|
||||||
|
};
|
||||||
|
sigemptyset(&sa_crash.sa_mask);
|
||||||
|
sa_crash.sa_flags = SA_RESETHAND; // handle only once, avoid recursion
|
||||||
|
|
||||||
|
sigaction(SIGSEGV, &sa_crash, nullptr);
|
||||||
|
sigaction(SIGABRT, &sa_crash, nullptr);
|
||||||
|
sigaction(SIGFPE, &sa_crash, nullptr);
|
||||||
|
sigaction(SIGILL, &sa_crash, nullptr);
|
||||||
|
|
||||||
|
running_ = true;
|
||||||
|
|
||||||
|
// run with restart logic (infinite restart)
|
||||||
|
// run main loop in separate thread, main thread monitors thread status
|
||||||
|
int restart_count = 0;
|
||||||
|
while (running_) {
|
||||||
|
crash_detected = false;
|
||||||
|
should_restart = false;
|
||||||
|
std::atomic<bool> loop_completed{false};
|
||||||
|
std::exception_ptr loop_exception = nullptr;
|
||||||
|
|
||||||
|
// run main loop in separate thread
|
||||||
|
std::thread loop_thread([&loop, &loop_completed, &loop_exception]() {
|
||||||
|
try {
|
||||||
|
loop();
|
||||||
|
loop_completed = true;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
loop_exception = std::current_exception();
|
||||||
|
loop_completed = true;
|
||||||
|
} catch (...) {
|
||||||
|
loop_exception = std::current_exception();
|
||||||
|
loop_completed = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// wait for thread to complete
|
||||||
|
loop_thread.join();
|
||||||
|
|
||||||
|
// check exit reason
|
||||||
|
if (loop_exception) {
|
||||||
|
restart_count++;
|
||||||
|
try {
|
||||||
|
std::rethrow_exception(loop_exception);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "Exception caught: " << e.what() << std::endl;
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "Unknown exception caught" << std::endl;
|
||||||
|
}
|
||||||
|
std::cerr << "Restarting... (attempt " << restart_count << ")"
|
||||||
|
<< std::endl;
|
||||||
|
std::this_thread::sleep_for(
|
||||||
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if crash signal detected
|
||||||
|
if (crash_detected || should_restart) {
|
||||||
|
restart_count++;
|
||||||
|
std::cerr << "Crash detected, restarting... (attempt " << restart_count
|
||||||
|
<< ")" << std::endl;
|
||||||
|
std::this_thread::sleep_for(
|
||||||
|
std::chrono::milliseconds(DAEMON_DEFAULT_RESTART_DELAY_MS));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// normal exit
|
||||||
|
if (loop_completed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// default restart delay (milliseconds)
|
||||||
#define DAEMON_DEFAULT_RESTART_DELAY_MS 1000
|
#define DAEMON_DEFAULT_RESTART_DELAY_MS 1000
|
||||||
|
|
||||||
class Daemon {
|
class Daemon {
|
||||||
@@ -18,10 +19,13 @@ class Daemon {
|
|||||||
|
|
||||||
Daemon(const std::string& name);
|
Daemon(const std::string& name);
|
||||||
|
|
||||||
|
// start daemon (restart after 1 second by default)
|
||||||
bool start(MainLoopFunc loop);
|
bool start(MainLoopFunc loop);
|
||||||
|
|
||||||
|
// request exit
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
// check if running
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -32,6 +36,7 @@ class Daemon {
|
|||||||
bool running_;
|
bool running_;
|
||||||
#else
|
#else
|
||||||
static Daemon* instance_;
|
static Daemon* instance_;
|
||||||
|
void runUnix(MainLoopFunc loop);
|
||||||
volatile bool running_;
|
volatile bool running_;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ConfigCenter {
|
|||||||
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
VIDEO_FRAME_RATE video_frame_rate_ = VIDEO_FRAME_RATE::FPS_60;
|
||||||
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
VIDEO_ENCODE_FORMAT video_encode_format_ = VIDEO_ENCODE_FORMAT::H264;
|
||||||
bool hardware_video_codec_ = false;
|
bool hardware_video_codec_ = false;
|
||||||
bool enable_turn_ = true;
|
bool enable_turn_ = false;
|
||||||
bool enable_srtp_ = false;
|
bool enable_srtp_ = false;
|
||||||
std::string signal_server_host_ = "api.crossdesk.cn";
|
std::string signal_server_host_ = "api.crossdesk.cn";
|
||||||
std::string signal_server_host_default_ = "api.crossdesk.cn";
|
std::string signal_server_host_default_ = "api.crossdesk.cn";
|
||||||
|
|||||||
@@ -51,16 +51,7 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
g_on_key_action = nullptr;
|
|
||||||
g_user_ptr = nullptr;
|
|
||||||
|
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
if (display_) {
|
|
||||||
XSelectInput(display_, DefaultRootWindow(display_), 0);
|
|
||||||
XFlush(display_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ static void* g_user_ptr = nullptr;
|
|||||||
|
|
||||||
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
CGEventRef eventCallback(CGEventTapProxy proxy, CGEventType type,
|
||||||
CGEventRef event, void* userInfo) {
|
CGEventRef event, void* userInfo) {
|
||||||
if (!g_on_key_action) {
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyboardCapturer* keyboard_capturer = (KeyboardCapturer*)userInfo;
|
KeyboardCapturer* keyboard_capturer = (KeyboardCapturer*)userInfo;
|
||||||
if (!keyboard_capturer) {
|
if (!keyboard_capturer) {
|
||||||
LOG_ERROR("keyboard_capturer is nullptr");
|
LOG_ERROR("keyboard_capturer is nullptr");
|
||||||
@@ -124,23 +120,12 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
g_on_key_action = nullptr;
|
|
||||||
g_user_ptr = nullptr;
|
|
||||||
|
|
||||||
if (event_tap_) {
|
|
||||||
CGEventTapEnable(event_tap_, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (run_loop_source_) {
|
if (run_loop_source_) {
|
||||||
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_source_,
|
|
||||||
kCFRunLoopCommonModes);
|
|
||||||
CFRelease(run_loop_source_);
|
CFRelease(run_loop_source_);
|
||||||
run_loop_source_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_tap_) {
|
if (event_tap_) {
|
||||||
CFRelease(event_tap_);
|
CFRelease(event_tap_);
|
||||||
event_tap_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -39,12 +39,7 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
if (keyboard_hook_) {
|
|
||||||
g_on_key_action = nullptr;
|
|
||||||
g_user_ptr = nullptr;
|
|
||||||
UnhookWindowsHookEx(keyboard_hook_);
|
UnhookWindowsHookEx(keyboard_hook_);
|
||||||
keyboard_hook_ = nullptr;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,6 @@
|
|||||||
#define INPUT_WINDOW_PADDING_EN 96
|
#define INPUT_WINDOW_PADDING_EN 96
|
||||||
#define SETTINGS_WINDOW_WIDTH_CN 202
|
#define SETTINGS_WINDOW_WIDTH_CN 202
|
||||||
#define SETTINGS_WINDOW_WIDTH_EN 248
|
#define SETTINGS_WINDOW_WIDTH_EN 248
|
||||||
#if USE_CUDA
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#define SETTINGS_WINDOW_HEIGHT_CN 405
|
#define SETTINGS_WINDOW_HEIGHT_CN 405
|
||||||
#define SETTINGS_WINDOW_HEIGHT_EN 405
|
#define SETTINGS_WINDOW_HEIGHT_EN 405
|
||||||
@@ -28,15 +27,6 @@
|
|||||||
#define SETTINGS_WINDOW_HEIGHT_CN 375
|
#define SETTINGS_WINDOW_HEIGHT_CN 375
|
||||||
#define SETTINGS_WINDOW_HEIGHT_EN 375
|
#define SETTINGS_WINDOW_HEIGHT_EN 375
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
#if _WIN32
|
|
||||||
#define SETTINGS_WINDOW_HEIGHT_CN 375
|
|
||||||
#define SETTINGS_WINDOW_HEIGHT_EN 375
|
|
||||||
#else
|
|
||||||
#define SETTINGS_WINDOW_HEIGHT_CN 345
|
|
||||||
#define SETTINGS_WINDOW_HEIGHT_EN 345
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_CN 228
|
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_CN 228
|
||||||
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_EN 275
|
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_WIDTH_EN 275
|
||||||
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_HEIGHT_CN 195
|
#define SELF_HOSTED_SERVER_CONFIG_WINDOW_HEIGHT_CN 195
|
||||||
|
|||||||
@@ -173,9 +173,6 @@ static std::vector<std::string> enable_autostart = {
|
|||||||
reinterpret_cast<const char*>(u8"开机自启:"), "Auto Start:"};
|
reinterpret_cast<const char*>(u8"开机自启:"), "Auto Start:"};
|
||||||
static std::vector<std::string> enable_daemon = {
|
static std::vector<std::string> enable_daemon = {
|
||||||
reinterpret_cast<const char*>(u8"启用守护进程:"), "Enable Daemon:"};
|
reinterpret_cast<const char*>(u8"启用守护进程:"), "Enable Daemon:"};
|
||||||
static std::vector<std::string> takes_effect_after_restart = {
|
|
||||||
reinterpret_cast<const char*>(u8"重启后生效"),
|
|
||||||
"Takes effect after restart"};
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
static std::vector<std::string> minimize_to_tray = {
|
static std::vector<std::string> minimize_to_tray = {
|
||||||
reinterpret_cast<const char*>(u8"退出时最小化到系统托盘:"),
|
reinterpret_cast<const char*>(u8"退出时最小化到系统托盘:"),
|
||||||
|
|||||||
@@ -1340,7 +1340,6 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
|
|||||||
is_client_mode_ = false;
|
is_client_mode_ = false;
|
||||||
reload_recent_connections_ = true;
|
reload_recent_connections_ = true;
|
||||||
fullscreen_button_pressed_ = false;
|
fullscreen_button_pressed_ = false;
|
||||||
start_keyboard_capturer_ = false;
|
|
||||||
just_created_ = false;
|
just_created_ = false;
|
||||||
recent_connection_image_save_time_ = SDL_GetTicks();
|
recent_connection_image_save_time_ = SDL_GetTicks();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -448,7 +448,7 @@ class Render {
|
|||||||
int video_frame_rate_button_value_ = 1;
|
int video_frame_rate_button_value_ = 1;
|
||||||
int video_encode_format_button_value_ = 0;
|
int video_encode_format_button_value_ = 0;
|
||||||
bool enable_hardware_video_codec_ = false;
|
bool enable_hardware_video_codec_ = false;
|
||||||
bool enable_turn_ = true;
|
bool enable_turn_ = false;
|
||||||
bool enable_srtp_ = false;
|
bool enable_srtp_ = false;
|
||||||
char signal_server_ip_[256] = "api.crossdesk.cn";
|
char signal_server_ip_[256] = "api.crossdesk.cn";
|
||||||
char signal_server_port_[6] = "9099";
|
char signal_server_port_[6] = "9099";
|
||||||
@@ -460,7 +460,7 @@ class Render {
|
|||||||
int video_frame_rate_button_value_last_ = 0;
|
int video_frame_rate_button_value_last_ = 0;
|
||||||
int video_encode_format_button_value_last_ = 0;
|
int video_encode_format_button_value_last_ = 0;
|
||||||
bool enable_hardware_video_codec_last_ = false;
|
bool enable_hardware_video_codec_last_ = false;
|
||||||
bool enable_turn_last_ = true;
|
bool enable_turn_last_ = false;
|
||||||
bool enable_srtp_last_ = false;
|
bool enable_srtp_last_ = false;
|
||||||
bool enable_self_hosted_last_ = false;
|
bool enable_self_hosted_last_ = false;
|
||||||
bool enable_autostart_ = false;
|
bool enable_autostart_ = false;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "device_controller.h"
|
#include "device_controller.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
@@ -103,39 +101,28 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
|
|||||||
last_mouse_event.button.y >= props->stream_render_rect_.y &&
|
last_mouse_event.button.y >= props->stream_render_rect_.y &&
|
||||||
last_mouse_event.button.y <= props->stream_render_rect_.y +
|
last_mouse_event.button.y <= props->stream_render_rect_.y +
|
||||||
props->stream_render_rect_.h) {
|
props->stream_render_rect_.h) {
|
||||||
float scroll_x = event.wheel.x;
|
int scroll_x = event.wheel.x;
|
||||||
float scroll_y = event.wheel.y;
|
int scroll_y = event.wheel.y;
|
||||||
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||||
scroll_x = -scroll_x;
|
scroll_x = -scroll_x;
|
||||||
scroll_y = -scroll_y;
|
scroll_y = -scroll_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
remote_action.type = ControlType::mouse;
|
remote_action.type = ControlType::mouse;
|
||||||
|
if (scroll_x == 0) {
|
||||||
auto roundUp = [](float value) -> int {
|
|
||||||
if (value > 0) {
|
|
||||||
return static_cast<int>(std::ceil(value));
|
|
||||||
} else if (value < 0) {
|
|
||||||
return static_cast<int>(std::floor(value));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (std::abs(scroll_y) >= std::abs(scroll_x)) {
|
|
||||||
remote_action.m.flag = MouseFlag::wheel_vertical;
|
remote_action.m.flag = MouseFlag::wheel_vertical;
|
||||||
remote_action.m.s = roundUp(scroll_y);
|
remote_action.m.s = scroll_y;
|
||||||
} else {
|
} else if (scroll_y == 0) {
|
||||||
remote_action.m.flag = MouseFlag::wheel_horizontal;
|
remote_action.m.flag = MouseFlag::wheel_horizontal;
|
||||||
remote_action.m.s = roundUp(scroll_x);
|
remote_action.m.s = scroll_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
render_width = props->stream_render_rect_.w;
|
render_width = props->stream_render_rect_.w;
|
||||||
render_height = props->stream_render_rect_.h;
|
render_height = props->stream_render_rect_.h;
|
||||||
remote_action.m.x =
|
remote_action.m.x =
|
||||||
(float)(last_mouse_event.button.x - props->stream_render_rect_.x) /
|
(float)(event.button.x - props->stream_render_rect_.x) / render_width;
|
||||||
render_width;
|
|
||||||
remote_action.m.y =
|
remote_action.m.y =
|
||||||
(float)(last_mouse_event.button.y - props->stream_render_rect_.y) /
|
(float)(event.button.y - props->stream_render_rect_.y) /
|
||||||
render_height;
|
render_height;
|
||||||
|
|
||||||
std::string msg = remote_action.to_json();
|
std::string msg = remote_action.to_json();
|
||||||
@@ -238,6 +225,8 @@ void Render::OnReceiveVideoBufferCb(const XVideoFrame* video_frame,
|
|||||||
props->video_height_ = video_frame->height;
|
props->video_height_ = video_frame->height;
|
||||||
props->video_size_ = video_frame->size;
|
props->video_size_ = video_frame->size;
|
||||||
|
|
||||||
|
LOG_ERROR("receive: {}x{}", props->video_width_, props->video_height_);
|
||||||
|
|
||||||
if (need_to_update_render_rect) {
|
if (need_to_update_render_rect) {
|
||||||
render->UpdateRenderRect();
|
render->UpdateRenderRect();
|
||||||
}
|
}
|
||||||
@@ -469,12 +458,12 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
|
|||||||
render->need_to_send_host_info_ = true;
|
render->need_to_send_host_info_ = true;
|
||||||
render->start_screen_capturer_ = true;
|
render->start_screen_capturer_ = true;
|
||||||
render->start_speaker_capturer_ = true;
|
render->start_speaker_capturer_ = true;
|
||||||
// #ifdef CROSSDESK_DEBUG
|
#ifdef CROSSDESK_DEBUG
|
||||||
// render->start_mouse_controller_ = false;
|
render->start_mouse_controller_ = false;
|
||||||
// render->start_keyboard_capturer_ = false;
|
render->start_keyboard_capturer_ = false;
|
||||||
// #else
|
#else
|
||||||
render->start_mouse_controller_ = true;
|
render->start_mouse_controller_ = true;
|
||||||
// #endif
|
#endif
|
||||||
if (std::all_of(render->connection_status_.begin(),
|
if (std::all_of(render->connection_status_.begin(),
|
||||||
render->connection_status_.end(), [](const auto& kv) {
|
render->connection_status_.end(), [](const auto& kv) {
|
||||||
return kv.first.find("web") != std::string::npos;
|
return kv.first.find("web") != std::string::npos;
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ int Render::SettingWindow() {
|
|||||||
video_encode_format_items, IM_ARRAYSIZE(video_encode_format_items));
|
video_encode_format_items, IM_ARRAYSIZE(video_encode_format_items));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_CUDA && !defined(__aarch64__) && !defined(__arm__)
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -177,7 +176,6 @@ int Render::SettingWindow() {
|
|||||||
ImGui::Checkbox("##enable_hardware_video_codec",
|
ImGui::Checkbox("##enable_hardware_video_codec",
|
||||||
&enable_hardware_video_codec_);
|
&enable_hardware_video_codec_);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
@@ -272,15 +270,6 @@ int Render::SettingWindow() {
|
|||||||
}
|
}
|
||||||
ImGui::SetCursorPosY(settings_items_offset);
|
ImGui::SetCursorPosY(settings_items_offset);
|
||||||
ImGui::Checkbox("##enable_daemon_", &enable_daemon_);
|
ImGui::Checkbox("##enable_daemon_", &enable_daemon_);
|
||||||
if (ImGui::IsItemHovered()) {
|
|
||||||
ImGui::BeginTooltip();
|
|
||||||
ImGui::SetWindowFontScale(0.5f);
|
|
||||||
ImGui::Text("%s", localization::takes_effect_after_restart
|
|
||||||
[localization_language_index_]
|
|
||||||
.c_str());
|
|
||||||
ImGui::SetWindowFontScale(1.0f);
|
|
||||||
ImGui::EndTooltip();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include "screen_capturer_x11.h"
|
#include "screen_capturer_x11.h"
|
||||||
|
|
||||||
#include <X11/extensions/Xfixes.h>
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -102,7 +100,6 @@ int ScreenCapturerX11::Destroy() {
|
|||||||
|
|
||||||
int ScreenCapturerX11::Start(bool show_cursor) {
|
int ScreenCapturerX11::Start(bool show_cursor) {
|
||||||
if (running_) return 0;
|
if (running_) return 0;
|
||||||
show_cursor_ = show_cursor;
|
|
||||||
running_ = true;
|
running_ = true;
|
||||||
paused_ = false;
|
paused_ = false;
|
||||||
thread_ = std::thread([this]() {
|
thread_ = std::thread([this]() {
|
||||||
@@ -159,20 +156,6 @@ void ScreenCapturerX11::OnFrame() {
|
|||||||
AllPlanes, ZPixmap);
|
AllPlanes, ZPixmap);
|
||||||
if (!image) return;
|
if (!image) return;
|
||||||
|
|
||||||
// if enable show cursor, draw cursor
|
|
||||||
if (show_cursor_) {
|
|
||||||
Window root_return, child_return;
|
|
||||||
int root_x, root_y, win_x, win_y;
|
|
||||||
unsigned int mask;
|
|
||||||
if (XQueryPointer(display_, root_, &root_return, &child_return, &root_x,
|
|
||||||
&root_y, &win_x, &win_y, &mask)) {
|
|
||||||
if (root_x >= left_ && root_x < left_ + width_ && root_y >= top_ &&
|
|
||||||
root_y < top_ + height_) {
|
|
||||||
DrawCursor(image, root_x - left_, root_y - top_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needs_copy = image->bytes_per_line != width_ * 4;
|
bool needs_copy = image->bytes_per_line != width_ * 4;
|
||||||
std::vector<uint8_t> argb_buf;
|
std::vector<uint8_t> argb_buf;
|
||||||
uint8_t* src_argb = nullptr;
|
uint8_t* src_argb = nullptr;
|
||||||
@@ -203,82 +186,4 @@ void ScreenCapturerX11::OnFrame() {
|
|||||||
|
|
||||||
XDestroyImage(image);
|
XDestroyImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenCapturerX11::DrawCursor(XImage* image, int x, int y) {
|
|
||||||
if (!display_ || !image) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check XFixes extension
|
|
||||||
int event_base, error_base;
|
|
||||||
if (!XFixesQueryExtension(display_, &event_base, &error_base)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
XFixesCursorImage* cursor_image = XFixesGetCursorImage(display_);
|
|
||||||
if (!cursor_image) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int cursor_width = cursor_image->width;
|
|
||||||
int cursor_height = cursor_image->height;
|
|
||||||
|
|
||||||
int draw_x = x - cursor_image->xhot;
|
|
||||||
int draw_y = y - cursor_image->yhot;
|
|
||||||
|
|
||||||
// draw cursor on image
|
|
||||||
for (int cy = 0; cy < cursor_height; ++cy) {
|
|
||||||
for (int cx = 0; cx < cursor_width; ++cx) {
|
|
||||||
int img_x = draw_x + cx;
|
|
||||||
int img_y = draw_y + cy;
|
|
||||||
|
|
||||||
if (img_x < 0 || img_x >= image->width || img_y < 0 ||
|
|
||||||
img_y >= image->height) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long cursor_pixel = cursor_image->pixels[cy * cursor_width + cx];
|
|
||||||
unsigned char a = (cursor_pixel >> 24) & 0xFF;
|
|
||||||
|
|
||||||
// if alpha is 0, skip
|
|
||||||
if (a == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long img_pixel = XGetPixel(image, img_x, img_y);
|
|
||||||
|
|
||||||
unsigned char img_r = (img_pixel >> 16) & 0xFF;
|
|
||||||
unsigned char img_g = (img_pixel >> 8) & 0xFF;
|
|
||||||
unsigned char img_b = img_pixel & 0xFF;
|
|
||||||
|
|
||||||
unsigned char cursor_r = (cursor_pixel >> 16) & 0xFF;
|
|
||||||
unsigned char cursor_g = (cursor_pixel >> 8) & 0xFF;
|
|
||||||
unsigned char cursor_b = cursor_pixel & 0xFF;
|
|
||||||
|
|
||||||
// alpha mix
|
|
||||||
unsigned char final_r, final_g, final_b;
|
|
||||||
if (a == 255) {
|
|
||||||
// if alpha is 255, use cursor color
|
|
||||||
final_r = cursor_r;
|
|
||||||
final_g = cursor_g;
|
|
||||||
final_b = cursor_b;
|
|
||||||
} else {
|
|
||||||
float alpha = a / 255.0f;
|
|
||||||
float inv_alpha = 1.0f - alpha;
|
|
||||||
final_r =
|
|
||||||
static_cast<unsigned char>(cursor_r * alpha + img_r * inv_alpha);
|
|
||||||
final_g =
|
|
||||||
static_cast<unsigned char>(cursor_g * alpha + img_g * inv_alpha);
|
|
||||||
final_b =
|
|
||||||
static_cast<unsigned char>(cursor_b * alpha + img_b * inv_alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set pixel
|
|
||||||
unsigned long new_pixel = (final_r << 16) | (final_g << 8) | final_b;
|
|
||||||
XPutPixel(image, img_x, img_y, new_pixel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree(cursor_image);
|
|
||||||
}
|
|
||||||
} // namespace crossdesk
|
} // namespace crossdesk
|
||||||
Submodule submodules/minirtc updated: 0008123221...29ae03237f
10
xmake.lua
10
xmake.lua
@@ -7,12 +7,6 @@ option("CROSSDESK_VERSION")
|
|||||||
set_description("Set CROSSDESK_VERSION for build")
|
set_description("Set CROSSDESK_VERSION for build")
|
||||||
option_end()
|
option_end()
|
||||||
|
|
||||||
option("USE_CUDA")
|
|
||||||
set_default(false)
|
|
||||||
set_showmenu(true)
|
|
||||||
set_description("Use CUDA for hardware codec acceleration")
|
|
||||||
option_end()
|
|
||||||
|
|
||||||
add_rules("mode.release", "mode.debug")
|
add_rules("mode.release", "mode.debug")
|
||||||
set_languages("c++17")
|
set_languages("c++17")
|
||||||
set_encodings("utf-8")
|
set_encodings("utf-8")
|
||||||
@@ -22,8 +16,6 @@ set_encodings("utf-8")
|
|||||||
-- add_cxxflags("/W4", "/WX")
|
-- add_cxxflags("/W4", "/WX")
|
||||||
|
|
||||||
add_defines("UNICODE")
|
add_defines("UNICODE")
|
||||||
add_defines("USE_CUDA=" .. (is_config("USE_CUDA", true) and "1" or "0"))
|
|
||||||
|
|
||||||
if is_mode("debug") then
|
if is_mode("debug") then
|
||||||
add_defines("CROSSDESK_DEBUG")
|
add_defines("CROSSDESK_DEBUG")
|
||||||
end
|
end
|
||||||
@@ -45,7 +37,7 @@ elseif is_os("linux") then
|
|||||||
add_links("pulse-simple", "pulse")
|
add_links("pulse-simple", "pulse")
|
||||||
add_requires("libyuv")
|
add_requires("libyuv")
|
||||||
add_syslinks("pthread", "dl")
|
add_syslinks("pthread", "dl")
|
||||||
add_links("SDL3", "asound", "X11", "Xtst", "Xrandr", "Xfixes")
|
add_links("SDL3", "asound", "X11", "Xtst", "Xrandr")
|
||||||
add_cxflags("-Wno-unused-variable")
|
add_cxflags("-Wno-unused-variable")
|
||||||
elseif is_os("macosx") then
|
elseif is_os("macosx") then
|
||||||
add_links("SDL3")
|
add_links("SDL3")
|
||||||
|
|||||||
Reference in New Issue
Block a user