The tuning switches lived in the master's Advanced menu and were saved globally, so two hosts could not use different settings. The client already sends ScreenSettings when a remote desktop starts, so the state belongs there: the four items now sit in the remote desktop window's system menu, directly below Screen quality, and are saved per client. ScreenSettings had a 40-byte Reserved area at offset 56; four bytes became TuningFlags, keeping the struct at 100 bytes with Capabilities at 96. A new Capabilities bit marks a value written by a versioned master; old clients, and new clients never configured, report 0 and are not trusted. CMD_SCREEN_TUNING now ends with a version byte. A five-byte command comes from an older master that does not know the server-only adaptive bit: the client applies those three bits to the session but does not save them. A fresh client starts at 0, so an old master still gets pre-feature behaviour; the new master's 0xE default is persisted on its first session. The per-client master copy stays as the old-client fallback, and the old global [settings] Tuning* keys are honoured when neither exists, so an explicit opt-out survives the migration. Verified on the Debug server with the in-process test client: a fresh client stored 0xE on first use; toggling VBV wrote 0xF to both sides; after deleting the master copy and reopening, the menu restored VBV from the client report. Co-Authored-By: deepseek-flash
75 lines
2.8 KiB
C++
75 lines
2.8 KiB
C++
#include "EncoderFactory.h"
|
||
#include "common/config.h"
|
||
#include "common/logger.h"
|
||
#include "X264Encoder.h"
|
||
// 合规守护:DISABLE_FFMPEG_FOR_TEST=1 时硬编实现整体移出工程,仅保留 x264 软编路径
|
||
#if defined(_WIN64) && !DISABLE_FFMPEG_FOR_TEST
|
||
#include "CFFmpegH264Encoder.h"
|
||
#include "CFFmpegAV1Encoder.h"
|
||
#endif
|
||
|
||
namespace {
|
||
// 与 ScreenCapture::BitRateToCRF 同步:码率越高 CRF 越低(质量更好)。
|
||
// 仅 x264 软编路径用,硬编路径直接用 bitrate_kbps 走 CBR。
|
||
int BitRateToCRF(int bitRate) {
|
||
if (bitRate <= 0) return 23;
|
||
if (bitRate >= 3000) return 20;
|
||
if (bitRate >= 2000) return 20 + (3000 - bitRate) * 3 / 1000;
|
||
if (bitRate >= 800) return 23 + (2000 - bitRate) * 7 / 1200;
|
||
return 32;
|
||
}
|
||
}
|
||
|
||
std::unique_ptr<VideoEncoderBase> CreateEncoder(const EncoderRequest& req) {
|
||
EncoderParams p;
|
||
p.width = req.width;
|
||
p.height = req.height;
|
||
p.fps = req.fps;
|
||
|
||
#if defined(_WIN64) && !DISABLE_FFMPEG_FOR_TEST
|
||
// AV1 硬编路径(仅当客户端声明支持 AV1 解码)
|
||
// 硬件门槛高:仅 RTX 40+ / RX 7000+ / Intel Arc 才有 av1 encoder ASIC;
|
||
// 没合适硬件时 open() 全部失败,自然 fall through 到下面 H.264 路径。
|
||
if (req.encodeLevel >= LEVEL_AV1_HARD) {
|
||
auto enc = std::make_unique<CFFmpegAV1Encoder>();
|
||
p.rc = RateControl::BITRATE;
|
||
p.bitrate_kbps = req.bitrate_kbps;
|
||
if (enc->open(p)) {
|
||
Mprintf("=> encoder: %s (HW AV1, bitrate=%dk)\n", enc->backendName(), req.bitrate_kbps);
|
||
return enc;
|
||
}
|
||
Mprintf("=> all AV1 HW backends failed, falling back to H.264\n");
|
||
}
|
||
|
||
|
||
// H.264 硬编:CFFmpegH264Encoder 内部按 nvenc/qsv/amf/mf 顺序探
|
||
if (req.encodeLevel >= LEVEL_H264_HARD) {
|
||
auto enc = std::make_unique<CFFmpegH264Encoder>();
|
||
p.rc = RateControl::BITRATE;
|
||
p.bitrate_kbps = req.bitrate_kbps;
|
||
if (enc->open(p)) {
|
||
Mprintf("=> encoder: %s (HW, bitrate=%dk)\n", enc->backendName(), req.bitrate_kbps);
|
||
return enc;
|
||
}
|
||
Mprintf("=> all H.264 HW backends failed, falling back to x264\n");
|
||
}
|
||
#endif
|
||
|
||
// x264 软编兜底(无硬件 / 全失败 / 虚拟机 / 远程桌面会话场景)
|
||
if (req.encodeLevel >= LEVEL_H264_SOFT) {
|
||
auto enc = std::make_unique<CX264Encoder>();
|
||
p.rc = RateControl::CRF;
|
||
p.crf = BitRateToCRF(req.bitrate_kbps);
|
||
// capped CRF:由远程桌面对话框「远程桌面调优」控制,默认关、仅限洲际弱网勾选
|
||
p.vbv_cap = req.vbv_cap;
|
||
if (enc->open(p)) {
|
||
Mprintf("=> encoder: %s (SW, crf=%d%s)\n", enc->backendName(), p.crf,
|
||
p.vbv_cap ? ", vbv capped" : "");
|
||
return enc;
|
||
}
|
||
}
|
||
|
||
Mprintf("=> ERROR: no encoder could be opened\n");
|
||
return nullptr;
|
||
}
|