Compare commits

...
3 Commits
Author SHA1 Message Date
VallierDevandClaude Opus 5.5 5e92abe373 Release v0.1.17
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 01:30:24 +08:00
VallierDevandClaude Opus 5.5 b63bedd4dc Repaint full-screen terminal programs on reattach; ABR for libx265 bitrate presets
Reattaching replays the scrollback tail, which starts mid-redraw for
full-screen programs (tmux, vim, TUIs), and an unchanged size raises no
SIGWINCH. Shrink the PTY by one row and restore the latest requested size
after a pause so the program repaints (#17).

Apply the #15 ABR change to the libx265 path as well, clarify the
non-wayland build error, and document the Wayland systemd unit and uinput
module autoload (#16).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 01:30:09 +08:00
wenmou 9c1ae123db Wayland: keep capturing without output power management; x264 ABR for bitrate presets (#15)
* Wayland: keep capturing when output power management is unavailable

keep_display_awake() runs on the desktop video start path, so a compositor\nwithout wlr-output-power-management made uu_wl_wake() return -1 and aborted\nthe whole desktop stream. Treat the missing protocol as nothing to wake.

* x264: average bitrate for the bitrate presets so 4K keyframes fit

Capped CRF plus VBV cannot fit a large IDR frame at 4K and a low cap, so\nkeyframes came out near-grey. NVENC and VAAPI already carry a target bitrate;\ngive x264 the same and keep CRF only for automatic quality.
2026-10-16 01:30:00 +08:00
9 changed files with 117 additions and 13 deletions

No files matched your search

Generated
+1 -1
View File
@@ -2649,7 +2649,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uu-remote-linux"
version = "0.1.16"
version = "0.1.17"
dependencies = [
"async-trait",
"base64 0.22.1",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "uu-remote-linux"
version = "0.1.16"
version = "0.1.17"
edition = "2021"
authors = ["uu-remote-linux contributors"]
description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients"
+9 -1
View File
@@ -75,6 +75,8 @@ Wayland limits: single screen, fixed resolution. The native Hyprland backend now
dynamic resolution yet; the clipboard syncs while the viewer's remote window has focus. On the first connection the desktop asks for "Remote Desktop / Screen Sharing"
permission; the permission is remembered once granted.
The native Wayland backend needs `wlr-output-power-management` from the compositor to wake a turned-off screen; without it only wake is unavailable — capture and encoding are unaffected.
Native Wayland experiments: `UU_WAYLAND_PIPELINE=0` disables pipelining for comparison.
`UU_WAYLAND_DMABUF=1` explicitly tries dma-buf → GBM CPU mapping (off by default;
requires runtime libgbm; `UU_WAYLAND_DMABUF_DEVICE` overrides `/dev/dri/renderD128`).
@@ -260,6 +262,8 @@ Common environment variables:
Host settings such as "lock after remote session" and "mute host" are stored in
`~/.config/uuremote/host_settings.json`.
With external FFmpeg CPU encoding, the bitrate presets (Original / Ultra / HD / custom) use average bitrate (ABR) to avoid gray keyframes at 4K and low bitrates; Auto keeps constant rate factor (CRF).
## Let an AI agent install or develop it
If you use Claude Code, Codex, Cursor or a similar coding agent, have it read [AGENTS.md](AGENTS.md) first.
@@ -364,10 +368,14 @@ cargo build --release --features wayland
Omarchy uses Hyprland: run in its user session, select `UU_DESKTOP_BACKEND=wayland`,
and retain `WAYLAND_DISPLAY` / `XDG_RUNTIME_DIR`. This requires wlr-screencopy and the
virtual input protocols supported by Hyprland; other compositors may need `--features wayland,portal`.
For uinput, load `uinput` and apply the uaccess rule above; seat ACLs require an active login.
For uinput, load `uinput` (at boot: `echo uinput | sudo tee /etc/modules-load.d/uinput.conf`) and apply the uaccess rule above; seat ACLs require an active login.
For unattended accounts, explicitly restrict `/dev/uinput` access to a dedicated group.
This permission can inject into the whole seat, including lock/greeter screens.
`UU_INPUT_BACKEND=uinput` requests kernel devices; verify startup actually reports uinput.
In Hyprland / uwsm sessions `default.target` may start before the compositor exports `WAYLAND_DISPLAY`;
tie the unit to the graphical session instead (community-verified autostart on Omarchy):
`After=` and `PartOf=graphical-session.target`, `ConditionEnvironment=WAYLAND_DISPLAY`,
`Environment=UU_DESKTOP_BACKEND=wayland` (no `DISPLAY`), and `WantedBy=graphical-session.target`.
Optional VAAPI: `intel-media-driver` (modern Intel) or `libva-mesa-driver` (AMD), `libva-utils`
for `vainfo`. Optional KMS: `libdrm`. Virtual Xfce: `xorg-server-xvfb xorg-xauth xorg-xdpyinfo
xfce4-session xfce4-panel xfdesktop xfwm4 gnome-terminal`.
+22 -1
View File
@@ -66,6 +66,8 @@ Portal 仅作用于本服务获授权的会话。文件传输、终端等独立
Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持唤醒屏幕和动态分辨率;剪贴板只在控制端的远控窗口处于前台时同步。
原生 Wayland 后端需要合成器提供 `wlr-output-power-management` 才能唤醒已关闭的屏幕;缺少该协议不影响采集和编码。
原生 Wayland 实验选项:`UU_WAYLAND_PIPELINE=0` 可关闭流水线做对照。`UU_WAYLAND_DMABUF=1` 显式尝试 dma-buf→GBM CPU 映射(默认关闭,需要运行时 libgbm;可用 `UU_WAYLAND_DMABUF_DEVICE` 指定 render node,默认 `/dev/dri/renderD128`)。仅支持显式线性修饰符、单平面 8-bit RGB,失败回退 SHM;virgl VM 中只验证了回退,成功导入/映射和硬件加速均未验证。这不是零拷贝 VAAPI 路径;选择 `UU_VIDEO_ENCODER=vaapi` 时仍由 FFmpeg 上传 CPU 帧。
首次连接时,桌面会弹窗请求「远程桌面 / 屏幕共享」授权,同意后会记住授权。
@@ -231,6 +233,8 @@ systemctl --user restart uuremote-native.service
「远程结束后自动锁屏」「静音运行」等设置保存在 `~/.config/uuremote/host_settings.json`。
选择码率档(原画 / 超清 / 高清 / 自定义)时,外部 FFmpeg 的 CPU 编码以平均码率(ABR)为目标,避免 4K 低码率下关键帧发灰;「自动」档仍使用恒定质量(CRF)。
## 让 AI 帮你安装或开发
如果你用 Claude Code、Codex、Cursor 等 AI 编程工具,让它先阅读 [AGENTS.md](AGENTS.md)。
@@ -319,10 +323,27 @@ cargo build --release --features wayland
Omarchy 使用 Hyprland:在其用户会话中运行,设置 `UU_DESKTOP_BACKEND=wayland`,保留
`WAYLAND_DISPLAY` 和 `XDG_RUNTIME_DIR`。其他合成器可能需要 `--features wayland,portal`。
uinput 需加载内核模块并应用上文 uaccess 规则;无人登录账号需要专用组的受限授权。
uinput 需加载内核模块(开机自动加载:`echo uinput | sudo tee /etc/modules-load.d/uinput.conf`)并应用上文 uaccess 规则;无人登录账号需要专用组的受限授权。
该权限能向整个 seat(包括锁屏/登录界面)注入输入。设置 `UU_INPUT_BACKEND=uinput` 后,
仍须确认启动日志实际选择了 uinput。
Hyprland / uwsm 等会话中,`default.target` 可能早于合成器导出 `WAYLAND_DISPLAY`。systemd 单元可改为随图形会话启动
(社区在 Omarchy 上验证过开机自启):
```ini
[Unit]
After=graphical-session.target
PartOf=graphical-session.target
ConditionEnvironment=WAYLAND_DISPLAY
[Service]
Environment=UU_DESKTOP_BACKEND=wayland
# 其余同上文 X11 示例,去掉 DISPLAY
[Install]
WantedBy=graphical-session.target
```
VAAPI 可选包:Intel 新显卡用 `intel-media-driver`,AMD 用 `libva-mesa-driver`,`libva-utils` 提供
`vainfo`。KMS 依赖 `libdrm`。虚拟 Xfce 依赖 `xorg-server-xvfb xorg-xauth xorg-xdpyinfo
xfce4-session xfce4-panel xfdesktop xfwm4 gnome-terminal`。
+2
View File
@@ -347,6 +347,8 @@ end:
}
int uu_wl_wake(void) {
pthread_mutex_lock(&lock); int result=-1;
/* Output power management is optional; missing it must not block screencopy. */
if(initialized && !power) result=0;
if(initialized && power && !power_failed) {
zwlr_output_power_v1_set_mode(power,ZWLR_OUTPUT_POWER_V1_MODE_ON);
if(sync_display()==0 && !power_failed) result=0;
+24
View File
@@ -0,0 +1,24 @@
修复终端接回错位、低码率 CPU 编码灰屏、niri 无法建流。/ Terminal reattach, low-bitrate CPU encoding and niri fixes.
### 修复 / Fixed
- **终端接回后全屏程序画面错位**(#17):接回已有会话时,主机先把终端行数临时减一、稍后恢复,触发 tmux、vim、
Claude Code 等全屏程序整屏重画。
⚠️ 已通过单元测试;尚未用 Android 客户端实机验证,如仍错位请在 #17 反馈。
Reattaching a terminal session now nudges the PTY size so full-screen programs repaint. Unit-tested; not yet
verified with the Android viewer.
- **低码率档周期性灰屏**(#15,感谢 @mengdehong):外部 FFmpeg 的 CPU 编码(libx264,以及同样处理的 libx265)在
码率档(原画 / 超清 / 高清 / 自定义)改用平均码率(ABR),避免 4K 低码率下关键帧耗尽缓冲而发灰;「自动」档仍用 CRF。
libx264 修复由贡献者在 Android 客户端实测;libx265 只验证了参数可用。
CPU encoding uses ABR for bitrate presets (CRF for Auto), fixing gray keyframes at 4K and low bitrates.
- **niri 等合成器无法建流**(#15):原生 Wayland 后端在合成器没有 `wlr-output-power-management` 时跳过唤醒屏幕,
不再中断采集。Capture continues when the compositor lacks output power management.
### 文档 / Docs
- Wayland 会话的 systemd 单元写法、uinput 模块开机加载(#16,感谢 @meotao 的实机测量与建议);未编入 `wayland`
特性时的报错改为明确提示重新编译。
Wayland systemd unit, uinput autoload, and a clearer error when the binary lacks the `wayland` feature.
### 下载 / Download
`uu-remote-linux-v0.1.17-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+42 -2
View File
@@ -71,6 +71,7 @@ struct Session {
pid: i32,
sink: Mutex<Option<UnboundedSender<Vec<u8>>>>,
scrollback: Mutex<VecDeque<u8>>,
size: Mutex<(u16, u16)>,
}
impl Session {
@@ -83,9 +84,26 @@ impl Session {
false
}
fn resize(&self, cols: u16, rows: u16) {
*self.size.lock().unwrap() = (cols, rows);
self.set_winsize(cols, rows);
}
fn set_winsize(&self, cols: u16, rows: u16) {
let win = libc::winsize { ws_row: rows, ws_col: cols, ws_xpixel: 0, ws_ypixel: 0 };
unsafe { libc::ioctl(self.master.as_raw_fd(), libc::TIOCSWINSZ as _, &win); }
}
/// Full-screen programs repaint only on SIGWINCH, which an unchanged size never raises:
/// shrink by one row, then restore the latest requested size after a pause.
fn force_redraw(self: &Arc<Self>) {
let (cols, rows) = *self.size.lock().unwrap();
if rows <= 1 { return; }
self.set_winsize(cols, rows - 1);
let s = self.clone();
std::thread::spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(150));
let (cols, rows) = *s.size.lock().unwrap();
s.set_winsize(cols, rows);
});
}
fn write(&self, data: &[u8]) {
let mut off = 0;
while off < data.len() {
@@ -137,7 +155,7 @@ fn spawn(requested_id: u32, cols: u16, rows: u16, shell: Option<&str>) -> Result
}
};
let session = Arc::new(Session { id, shell: shell.clone(), created_ms: now_ms(), pid: child.id() as i32,
master: pty.master, sink: Mutex::new(None), scrollback: Mutex::new(VecDeque::new()) });
master: pty.master, sink: Mutex::new(None), scrollback: Mutex::new(VecDeque::new()), size: Mutex::new((cols, rows)) });
let mut reader = std::fs::File::from(session.master.try_clone().map_err(|e| format!("pty dup failed: {e}"))?);
let worker = session.clone();
std::thread::Builder::new().name(format!("uu-term-{id}")).spawn(move || {
@@ -212,6 +230,7 @@ impl TerminalConn {
OPEN => {
let v = json(&frame.payload);
let (cols, rows) = dims(&v);
let reattach = existing.is_some();
let session = match existing {
Some(s) => { s.resize(cols, rows); Ok(s) }
None => spawn(frame.session, cols, rows, v.get("shell").and_then(|s| s.as_str())),
@@ -225,6 +244,9 @@ impl TerminalConn {
let replay: Vec<u8> = s.scrollback.lock().unwrap().iter().copied().collect();
// A full scrollback exceeds SCTP's 64 KiB outbound message limit.
for chunk in replay.chunks(OUTPUT_CHUNK) { self.send(STDOUT, s.id, chunk); }
drop(sink);
// The replay tail starts mid-redraw for full-screen programs.
if reattach { s.force_redraw(); }
}
Err(e) => { log::warn!("Terminal open failed: {}", e); self.send(OPEN_RESP, frame.session, &reply(1, &e)); }
}
@@ -291,13 +313,31 @@ mod tests {
}
}
#[test]
fn force_redraw_shrinks_then_restores_latest_size() {
let pty = nix::pty::openpty(None, None).unwrap();
let session = Arc::new(Session { id: u32::MAX - 2, shell: "/bin/sh".into(), created_ms: now_ms(),
master: pty.master, pid: 0, sink: Mutex::new(None),
scrollback: Mutex::new(VecDeque::new()), size: Mutex::new((80, 24)) });
let rows = |s: &Session| {
let mut win = libc::winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0 };
unsafe { libc::ioctl(s.master.as_raw_fd(), libc::TIOCGWINSZ as _, &mut win); }
(win.ws_col, win.ws_row)
};
session.resize(100, 30);
session.force_redraw();
assert_eq!(rows(&session), (100, 29));
session.resize(120, 40);
std::thread::sleep(std::time::Duration::from_millis(400));
assert_eq!(rows(&session), (120, 40), "restore must use the latest requested size");
}
#[test]
fn reconnect_replays_large_history_in_bounded_frames() {
let pty = nix::pty::openpty(None, None).unwrap();
let id = u32::MAX - 1;
let history: Vec<u8> = (0..SCROLLBACK).map(|n| (n % 251) as u8).collect();
let session = Arc::new(Session { id, shell: "/bin/sh".into(), created_ms: now_ms(),
master: pty.master, pid: 0, sink: Mutex::new(None),
scrollback: Mutex::new(history.iter().copied().collect()) });
scrollback: Mutex::new(history.iter().copied().collect()), size: Mutex::new((80, 24)) });
registry().lock().unwrap().insert(id, session.clone());
struct Cleanup(u32);
impl Drop for Cleanup { fn drop(&mut self) { registry().lock().unwrap().remove(&self.0); } }
+15 -6
View File
@@ -136,10 +136,16 @@ pub(crate) fn x265_params(gop: &str) -> String {
fn cpu_hevc_options(settings: &VideoSettings, gop: &str) -> Vec<String> {
let (maxrate, buffer) = rate_args(settings, Encoder::Cpu);
let (profile, pix_fmt) = chroma_args(settings, Encoder::Cpu);
["-c:v", "libx265", "-preset", "superfast", "-tune", "zerolatency", "-profile:v", profile,
"-pix_fmt", pix_fmt, "-g", gop, "-bf", "0", "-threads", "4", "-crf", &settings.cq().to_string(),
let mut options = ["-c:v", "libx265", "-preset", "superfast", "-tune", "zerolatency", "-profile:v", profile,
"-pix_fmt", pix_fmt, "-g", gop, "-bf", "0", "-threads", "4",
"-maxrate", &maxrate, "-bufsize", &buffer, "-x265-params", &x265_params(gop)]
.into_iter().map(str::to_owned).collect()
.into_iter().map(str::to_owned).collect::<Vec<_>>();
// Same as libx264: capped CRF starves repeated keyframes, so bitrate presets use ABR.
match settings.max_kbps() {
Some(k) => options.extend(["-b:v".into(), format!("{}k", k * 3 / 4)]),
None => options.extend(["-crf".into(), settings.cq().to_string()]),
}
options
}
fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str) -> Vec<String> {
@@ -157,10 +163,13 @@ fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str) -> Vec
}
if settings.codec == VideoCodec::H265 { return cpu_hevc_options(settings, gop); }
let params = format!("aud=1:repeat-headers=1:scenecut=0:keyint={gop}:min-keyint={gop}");
["-c:v", "libx264", "-preset", "superfast", "-tune", "zerolatency",
let mut options = vec!["-c:v", "libx264", "-preset", "superfast", "-tune", "zerolatency",
"-profile:v", profile, "-pix_fmt", pix_fmt, "-g", gop, "-threads", "4",
"-crf", &cq, "-maxrate", &maxrate, "-bufsize", &bufsize, "-x264-params", &params]
.into_iter().map(str::to_owned).collect()
"-maxrate", &maxrate, "-bufsize", &bufsize, "-x264-params", &params];
// Capped CRF starves repeated 4K keyframes; use ABR for bitrate presets.
if settings.max_kbps().is_some() { options.extend(["-b:v", &target]); }
else { options.extend(["-crf", &cq]); }
options.into_iter().map(str::to_owned).collect()
}
fn ffmpeg_command() -> Command {
+1 -1
View File
@@ -26,7 +26,7 @@ pub fn init() -> Result<(u32,u32),String> {
return Ok((w as u32,h as u32));
}
#[cfg(not(all(target_os="linux", feature="wayland")))]
Err("Wayland backend requires Linux and a build with --features wayland".into())
Err("this build was compiled without the wayland feature; rebuild with --features wayland".into())
}
pub fn capture(buffer:&mut [u8]) -> Result<(),String> {
#[cfg(all(target_os="linux", feature="wayland"))]