Fix: macOS use quality profile FPS/bitrate, add HW resolution downscaling

This commit is contained in:
yuanyuanxiang
2026-06-09 12:02:15 +02:00
parent 8e5ec20cf2
commit 3f662f1ca7
10 changed files with 254 additions and 77 deletions

View File

@@ -626,6 +626,11 @@ static void setupSignals()
// 经典 Unix 双 fork 守护进程
static void daemonize()
{
// macOS 10.12+ NSLog 默认只写 os_logUnified Logging非 TTY 时不写 stderr。
// CFLOG_FORCE_STDERR=1 恢复旧行为:无论是否 TTY都同时写 fd 2。
// 必须在 fork 前设置,子进程会继承环境变量。
setenv("CFLOG_FORCE_STDERR", "1", 1);
pid_t pid = fork();
if (pid < 0) exit(1);
if (pid > 0) exit(0); // 父进程退出
@@ -636,13 +641,32 @@ static void daemonize()
if (pid < 0) exit(1);
if (pid > 0) exit(0);
// 关闭标准文件描述符,重定向到 /dev/null
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
open("/dev/null", O_RDONLY); // fd 0 = stdin
open("/dev/null", O_WRONLY); // fd 1 = stdout
open("/dev/null", O_WRONLY); // fd 2 = stderr
// 用 dup2 而非 close+open 序列,确保 fd 号与目标对应,不依赖"最低可用 fd"假设
int nullFd = open("/dev/null", O_RDWR);
if (nullFd >= 0) {
dup2(nullFd, STDIN_FILENO);
dup2(nullFd, STDOUT_FILENO);
if (nullFd > STDOUT_FILENO) close(nullFd);
}
// stderr → /tmp/ghost.log若失败退回 $TMPDIR/ghost.log
int logFd = open("/tmp/ghost.log", O_WRONLY | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (logFd < 0) {
const char* tmp = getenv("TMPDIR");
if (!tmp) tmp = "/tmp";
char path[256];
snprintf(path, sizeof(path), "%s/ghost.log", tmp);
logFd = open(path, O_WRONLY | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
}
if (logFd >= 0) {
dup2(logFd, STDERR_FILENO);
if (logFd != STDERR_FILENO) close(logFd);
// 直接写 fd 2 确认重定向生效write 不经过 NSLog/os_log
const char* banner = "=== ghost daemon started ===\n";
write(STDERR_FILENO, banner, strlen(banner));
}
}
// ============== Main Entry Point ==============
@@ -808,6 +832,19 @@ int main(int argc, const char* argv[])
// 守护进程模式:在进入 autoreleasepool 之前 fork
if (daemon_mode) {
daemonize();
} else {
// App bundle 模式login item / open 命令启动):同样重定向日志到 /tmp/ghost.log。
// macOS 10.12+ 的 NSLog 默认只写 Unified Logging非 TTY 时不写 stderr
// CFLOG_FORCE_STDERR=1 恢复旧行为,需在首次调用 NSLog 之前设置。
setenv("CFLOG_FORCE_STDERR", "1", 1);
int logFd = open("/tmp/ghost.log", O_WRONLY | O_CREAT | O_APPEND,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (logFd >= 0) {
dup2(logFd, STDERR_FILENO);
if (logFd != STDERR_FILENO) close(logFd);
const char* banner = "=== ghost app started ===\n";
write(STDERR_FILENO, banner, strlen(banner));
}
}
@autoreleasepool {