From ff84aa4fd20622a67b0ebcaf72499d6f47f2c3c8 Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Thu, 15 Oct 2026 23:58:54 +0800 Subject: [PATCH] Support true color (H.264 4:4:4) and log viewer decoder capabilities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The viewer sends CaptureSettingRequest field 7 = 3 when 真彩 is enabled (ff_capture_setting versions are cumulative, so our version 4 already implies chroma sampling). Encode yuv444p with NVENC high444p / x264 high444 and report the encoded chroma in CaptureSettingSync; VAAPI and inproc stay 4:2:0. Log ConnectOptions decoder_cap_list (numbers only). Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 8 ++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- README.en.md | 2 +- README.md | 2 +- docs/release-notes/v0.1.15.md | 20 +++++++++++++++++ src/capture_setting.rs | 42 ++++++++++++++++++++++++++++++----- src/signaling.rs | 7 ++++++ src/video.rs | 23 ++++++++++++++++--- 9 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 docs/release-notes/v0.1.15.md diff --git a/AGENTS.md b/AGENTS.md index e929f37..2104c54 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -164,7 +164,13 @@ started a second full host server instead, so check that a subcommand exists in - CaptureSettingRequest: field 1 is an **fps option index** (1=30, 2=60, 3=90); the real frame rate is field 18 `fpsCount`. Field 2 quality: 1 Fast, 2 General (高清 2M), 3 HD (超清 8M), 4 Bluray (原画 20M), 5 Auto, 6 Custom. Resolution: 16/17 pixel size or 5/6, 10 resolution_type (3 = follow remote). - Reply `RpcResponse{2 CaptureSettingResponse{}}` (no errors = applied) and send Message 25 CaptureSettingSync. + Field 7 `chorma_format` (ChromaFormat 1 = 4:2:0, 3 = 4:4:4) is sent when 真彩 is toggled; ff_capture_setting versions + are cumulative (3 CHROMA_SAMPLING, 4 CUSTOM_BITRATE, 5 DPI_SCALE, 6 HDR). 4:4:4 = NVENC `high444p` / x264 `high444` + with `yuv444p`; VAAPI and inproc stay 4:2:0. + Reply `RpcResponse{2 CaptureSettingResponse{}}` (no errors = applied) and send Message 25 CaptureSettingSync + (field 3 = the chroma actually encoded). +- ConnectOptions field 4 `decoder_cap_list` = DecoderCap {1 fps, 2 codec_type (1 H264, 2 H265), 3 width, 4 height, + 5 chroma_format}. The Mac viewer lists H.264 and H.265, each 4:2:0 and 4:4:4, up to 3840x2160@120. - SystemMetrics (Message 13): GeneralMetric `2 system_sound_support` is an enum, **2 = supported** (1 = not supported); SettingMetric 1 keep_mute, 2 mute_permanent, 3 auto_lock, 5 file_transfer_save_location, 8/9/10 permission states (2 = allow). diff --git a/Cargo.lock b/Cargo.lock index e2ff9b9..9bad1b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2649,7 +2649,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uu-remote-linux" -version = "0.1.14" +version = "0.1.15" dependencies = [ "base64 0.22.1", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 6220fe8..5e11382 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uu-remote-linux" -version = "0.1.14" +version = "0.1.15" edition = "2021" authors = ["uu-remote-linux contributors"] description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients" diff --git a/README.en.md b/README.en.md index 35b8c37..a9bf9f9 100644 --- a/README.en.md +++ b/README.en.md @@ -88,7 +88,7 @@ mapping and hardware acceleration remain unverified. This is not zero-copy VAAPI | Feature | Status | |---|---| | Switching between multiple monitors | In progress | -| True color (4:4:4) | Not implemented; not declared in the handshake, so the client does not enable it | +| True color (4:4:4) | Supported (v0.1.15): the default FFmpeg pipeline with NVENC / libx264 encodes H.264 High 4:4:4; VAAPI and `inproc-av` stay 4:2:0 and report that to the client | | HDR | Not implemented | | Super screen / virtual display | Not implemented | | Privacy screen on the host | Not implemented | diff --git a/README.md b/README.md index c55889d..452afef 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端 | 功能 | 状态 | |---|---| | 多显示器切换 | 开发中 | -| 真彩(4:4:4) | 未实现,握手时不声明,客户端不会启用 | +| 真彩(4:4:4) | 支持(v0.1.15):NVENC / libx264 的默认 FFmpeg 管线输出 H.264 High 4:4:4;VAAPI 和 `inproc-av` 管线仍为 4:2:0,并如实回报给客户端 | | HDR | 未实现 | | 超级屏 / 虚拟显示器 | 未实现 | | 被控端防窥模式 | 未实现 | diff --git a/docs/release-notes/v0.1.15.md b/docs/release-notes/v0.1.15.md new file mode 100644 index 0000000..574dcae --- /dev/null +++ b/docs/release-notes/v0.1.15.md @@ -0,0 +1,20 @@ +支持真彩(4:4:4)。/ True color (4:4:4) support. + +### 新功能 / Added +- **真彩(4:4:4)**:在客户端画面菜单打开「真彩」后,主机改用 H.264 High 4:4:4 编码,彩色细字(红字、链接、 + 代码高亮)边缘不再发虚;关闭后切回 4:2:0。适用于默认的 FFmpeg 管线(NVENC 或 libx264);VAAPI 和 + `--features inproc-av` 管线仍为 4:2:0,并如实告知客户端。 + ✅ 已用官方 Mac 客户端在 RTX 3090(NVENC)上实机验证:开关来回切换正常、画面正常解码。 + When 真彩 is enabled the host encodes H.264 High 4:4:4 (default FFmpeg pipeline with NVENC or libx264); VAAPI and + inproc-av stay 4:2:0 and report it. Verified with the official Mac viewer on NVENC (toggling, decoding). +- 日志记录客户端声明的解码能力(编码类型、色度、最大分辨率、帧率,仅数字),便于排查画质问题。 + The log now shows the viewer's declared decoder capabilities (numbers only). + +### 说明 / Notes +- 4:4:4 码率会略高于 4:2:0;在缩放到较低分辨率时差别不明显,建议配合「跟随远端」分辨率使用。 + 4:4:4 costs some bitrate; the difference is hardly visible when the stream is scaled down. + +### 下载 / Download +`uu-remote-linux-v0.1.15-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。 + +**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.** diff --git a/src/capture_setting.rs b/src/capture_setting.rs index 2578f85..582040f 100644 --- a/src/capture_setting.rs +++ b/src/capture_setting.rs @@ -19,9 +19,14 @@ pub const QUALITY_AUTO: u64 = 5; pub const QUALITY_CUSTOM: u64 = 6; /// FeatureFlag.ff_capture_setting we declare: fps, preset quality and custom bitrate. -/// (Chroma 4:4:4, DPI scaling and HDR are higher versions and are not implemented.) +/// Versions are cumulative (official FF_CaptureSetting enum: 3 CHROMA_SAMPLING, 4 CUSTOM_BITRATE, +/// 5 DPI_SCALE, 6 HDR), so 4 also tells the viewer we accept a chroma format (真彩). pub const FEATURE_VERSION: u64 = 4; +/// Official GvPb_ChromaFormat values (CaptureSettingRequest field 7, CaptureSettingSync field 3). +pub const CHROMA_420: u64 = 1; +pub const CHROMA_444: u64 = 3; + const MIN_FPS: u32 = 5; const MAX_FPS: u32 = 144; @@ -33,10 +38,12 @@ pub struct VideoSettings { pub custom_mbps: u32, /// Scaled stream size (其他分辨率); None streams the native desktop size. pub output: Option<(u32, u32)>, + /// CHROMA_420 or CHROMA_444 (真彩); 4:4:4 only when the encoder pipeline supports it. + pub chroma: u64, } impl Default for VideoSettings { - fn default() -> Self { Self { fps: 60, quality: QUALITY_AUTO, custom_mbps: 0, output: None } } + fn default() -> Self { Self { fps: 60, quality: QUALITY_AUTO, custom_mbps: 0, output: None, chroma: CHROMA_420 } } } /// Selectable smaller stream sizes with the desktop's aspect ratio (even dimensions). @@ -95,6 +102,10 @@ fn fps_from_option(value: u64) -> Option { /// Applies a capture-setting RPC to `settings` and returns the RpcResponse payload (Message 22), /// or None when the RPC is not a capture/fps/quality setting. pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender, native: (u32, u32)) -> Option> { + apply_rpc(rpc, settings, native, crate::video::full_chroma_available()) +} + +fn apply_rpc(rpc: &[WireField], settings: &watch::Sender, native: (u32, u32), full_chroma: bool) -> Option> { let header = message(rpc, 1).unwrap_or(&[]); let mut next = *settings.borrow(); if let Some(request) = message(rpc, 2) { @@ -106,6 +117,13 @@ pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender, na if let Some(fps) = number(&fields, 18).filter(|v| *v > 0).or_else(|| number(&fields, 1).and_then(fps_from_option)) { next.fps = fps as u32; } if let Some(quality) = number(&fields, 2).filter(|v| *v > 0) { next.quality = quality; } if let Some(bitrate) = number(&fields, 8).filter(|v| *v > 0) { next.custom_mbps = bitrate as u32; } + // Field 7 chorma_format (sic): 3 = 4:4:4 when 真彩 is on, 1 = 4:2:0. The Sync reports what is encoded. + match number(&fields, 7) { + Some(CHROMA_444) if full_chroma => next.chroma = CHROMA_444, + Some(CHROMA_444) => { log::info!("Chroma 4:4:4 requested; this encoder pipeline only supports 4:2:0"); next.chroma = CHROMA_420; } + Some(CHROMA_420) => next.chroma = CHROMA_420, + _ => {} + } // ChooseResolutionType 3 = follow remote (native); otherwise pixel size, else logical size. if number(&fields, 10) == Some(3) { next.output = None; } else if let Some((w, h)) = number(&fields, 16).zip(number(&fields, 17)).or_else(|| number(&fields, 5).zip(number(&fields, 6))) { @@ -129,7 +147,7 @@ pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender, na } next.fps = next.fps.clamp(MIN_FPS, MAX_FPS); settings.send_if_modified(|current| if *current != next { - log::info!("Desktop video settings: fps={} quality={} max_kbps={:?} output={:?}", next.fps, next.quality, next.max_kbps(), next.output); + log::info!("Desktop video settings: fps={} quality={} max_kbps={:?} output={:?} chroma={}", next.fps, next.quality, next.max_kbps(), next.output, next.chroma); *current = next; true } else { false }); let mut out = Vec::new(); @@ -156,7 +174,7 @@ pub fn sync_payload(settings: &VideoSettings, native: (u32, u32)) -> Vec { let mut out = Vec::new(); put_varint(1, u64::from(settings.fps), &mut out); put_varint(2, settings.quality, &mut out); - put_varint(3, 1, &mut out); // ChromaFormat_420 + put_varint(3, settings.chroma, &mut out); if settings.custom_mbps > 0 { put_varint(4, u64::from(settings.custom_mbps), &mut out); } put_varint(5, u64::from(size.0), &mut out); put_varint(6, u64::from(size.1), &mut out); @@ -187,7 +205,7 @@ mod tests { put_varint(18, 30, &mut body); let request = rpc(77, 2, &body); let response = handle_rpc(&decode_wire(&request).unwrap(), &tx, (1920, 1080)).unwrap(); - assert_eq!(*rx.borrow(), VideoSettings { fps: 30, quality: QUALITY_GENERAL, custom_mbps: 0, output: None }); + assert_eq!(*rx.borrow(), VideoSettings { fps: 30, quality: QUALITY_GENERAL, custom_mbps: 0, output: None, chroma: CHROMA_420 }); assert_eq!(rx.borrow().max_kbps(), Some(2_000)); let fields = decode_wire(&response).unwrap(); assert_eq!(message(&fields, 1), Some(&[8u8, 77][..])); @@ -208,6 +226,20 @@ mod tests { assert!(handle_rpc(&decode_wire(&rpc(3, 9, &[])).unwrap(), &tx, (1920, 1080)).is_none()); } + #[test] + fn true_color_request_selects_444_only_when_the_encoder_supports_it() { + let (tx, rx) = watch::channel(VideoSettings::default()); + // Observed Mac viewer request with 真彩 on: field 7 = 3. + let request = rpc(5, 2, &[8, 2, 16, 4, 56, 3, 144, 1, 60]); + apply_rpc(&decode_wire(&request).unwrap(), &tx, (1920, 1080), false).unwrap(); + assert_eq!(rx.borrow().chroma, CHROMA_420); + apply_rpc(&decode_wire(&request).unwrap(), &tx, (1920, 1080), true).unwrap(); + assert_eq!(rx.borrow().chroma, CHROMA_444); + assert_eq!(number(&decode_wire(&sync_payload(&rx.borrow(), (1920, 1080))).unwrap(), 3), Some(CHROMA_444)); + apply_rpc(&decode_wire(&rpc(6, 2, &[56, 1])).unwrap(), &tx, (1920, 1080), true).unwrap(); + assert_eq!(rx.borrow().chroma, CHROMA_420); + } + #[test] fn resolution_requests_scale_below_native_only() { let (tx, rx) = watch::channel(VideoSettings::default()); diff --git a/src/signaling.rs b/src/signaling.rs index 75fc38a..09ac310 100644 --- a/src/signaling.rs +++ b/src/signaling.rs @@ -317,6 +317,13 @@ impl SignalingClient { let ice_id = ["ice_id", "iceId"].iter().find_map(|k| header.get(*k).or_else(|| header.get("data").and_then(|d| d.get(*k)))) .and_then(|v| v.as_str()).map(str::to_owned); log::info!("be-controlled connect request: capture_type={} header_keys={:?} ice_id_present={}", capture_type, keys, ice_id.is_some()); + // ConnectOptions 4 decoder_cap_list: DecoderCap {1 fps, 2 codec_type (1 H264, 2 H265), + // 3 width, 4 height, 5 chroma_format (1 4:2:0, 3 4:4:4)}. Numbers only. + let caps: Vec> = fields.iter().flatten().filter(|f| f.number == 4).filter_map(|f| match f.value { + crate::protocol::WireValue::Bytes(b) => crate::protocol::decode_wire(b).ok().map(|cap| cap.iter().filter_map(|x| match x.value { + crate::protocol::WireValue::Varint(v) => Some((x.number, v)), _ => None }).collect()), + _ => None }).collect(); + if !caps.is_empty() { log::info!("Viewer decoder caps (fps,codec,w,h,chroma fields): {:?}", caps); } // Viewer platform (website enum: 1 windows, 2 android, 3 ios, 4 macos, 5 tv). let platform = header.get("controller_platform").or_else(|| header.get("data").and_then(|d| d.get("controller_platform"))); let controller_mac = platform.is_some_and(|v| v.as_i64() == Some(4) diff --git a/src/video.rs b/src/video.rs index a7aa4c5..e8d9578 100644 --- a/src/video.rs +++ b/src/video.rs @@ -68,6 +68,22 @@ impl Encoder { fn nvidia_present() -> bool { std::path::Path::new("/proc/driver/nvidia/version").exists() || std::path::Path::new("/dev/nvidia0").exists() } +/// 真彩 (4:4:4) needs the FFmpeg process pipeline with NVENC or libx264 (h264_vaapi and the +/// in-process encoder are 4:2:0 only). +pub fn full_chroma_available() -> bool { + #[cfg(feature = "inproc-av")] + if crate::inproc_encoder::selected() { return false; } + Encoder::requested() != Encoder::Vaapi +} + +/// (-profile:v, -pix_fmt) for NVENC / libx264: 4:4:4 needs a High 4:4:4 profile. +fn chroma_args(settings: &VideoSettings, encoder: Encoder) -> (&'static str, &'static str) { + match (settings.chroma == crate::capture_setting::CHROMA_444, encoder) { + (true, Encoder::Nvenc) => ("high444p", "yuv444p"), + (true, _) => ("high444", "yuv444p"), + (false, _) => ("baseline", "yuv420p"), + } +} pub(crate) fn vaapi_device() -> String { std::env::var("UU_VAAPI_DEVICE").unwrap_or_else(|_| "/dev/dri/renderD128".into()) } /// NV12 conversion must precede upload; scaling runs on software frames, before hwupload. @@ -232,7 +248,8 @@ async fn read_encoder_with( let (maxrate, bufsize) = rate_args(&settings, encoder); let cq = settings.cq().to_string(); let target = settings.max_kbps().map_or("16M".to_string(), |k| format!("{}k", k * 3 / 4)); - log::info!("Desktop encoder: display={} source={} output={:?} fps={} cq={} maxrate={} encoder={} low_latency=true",display,size,settings.output,settings.fps,cq,maxrate,encoder.name()); + let (profile, pix_fmt) = chroma_args(&settings, encoder); + log::info!("Desktop encoder: display={} source={} output={:?} fps={} cq={} maxrate={} encoder={} pix_fmt={} low_latency=true",display,size,settings.output,settings.fps,cq,maxrate,encoder.name(),if encoder == Encoder::Vaapi { "nv12" } else { pix_fmt }); // A bundled FFmpeg prefix (config ffmpeg_root / UU_FFMPEG_ROOT) or `ffmpeg` on PATH. let mut command=match crate::config::ffmpeg_root() { Some(root) => { let mut c=Command::new(root.join("bin/ffmpeg")); c.env("LD_LIBRARY_PATH",root.join("lib/x86_64-linux-gnu")); c } @@ -258,14 +275,14 @@ async fn read_encoder_with( command.args(vaapi_options(&settings, &gop)); } else if encoder == Encoder::Nvenc { command.args(["-c:v","h264_nvenc","-preset","p4","-tune","ull", - "-profile:v","baseline","-pix_fmt","yuv420p","-g",&gop,"-bf","0", + "-profile:v",profile,"-pix_fmt",pix_fmt,"-g",&gop,"-bf","0", "-rc","vbr","-cq",&cq,"-b:v",&target,"-maxrate",&maxrate,"-bufsize",&bufsize, "-rc-lookahead","0","-zerolatency","1","-delay","0","-aud","1"]); }else{ let x264 = format!("aud=1:repeat-headers=1:scenecut=0:keyint={gop}:min-keyint={gop}"); command.args([ "-c:v", "libx264", "-preset", "superfast", "-tune", "zerolatency", - "-profile:v", "baseline", "-pix_fmt", "yuv420p", "-g", &gop, "-threads", "4", + "-profile:v", profile, "-pix_fmt", pix_fmt, "-g", &gop, "-threads", "4", "-crf", &cq, "-maxrate", &maxrate, "-bufsize", &bufsize, "-x264-params", &x264]); }