From 6882b768015ba9f3dd390961b2168ff85cf41c75 Mon Sep 17 00:00:00 2001 From: VallierDev <24893073+VallierDev@users.noreply.github.com> Date: Fri, 16 Oct 2026 12:36:06 +0800 Subject: [PATCH] Wayland: free cached dma-buf on SHM fallback; recapture after a stall Review follow-ups to #20: the copy-failure fallback cleared frame state but no longer released cached dma-buf buffers, and after a backpressure stall the engine's prefetched frame was as old as the stall. Release v0.1.22. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 2 +- Cargo.toml | 2 +- c_engine/wayland_engine.c | 3 ++- docs/release-notes/v0.1.22.md | 15 +++++++++++++++ src/wayland.rs | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 docs/release-notes/v0.1.22.md diff --git a/Cargo.lock b/Cargo.lock index 5d753cd..42512e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2717,7 +2717,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uu-remote-linux" -version = "0.1.21" +version = "0.1.22" dependencies = [ "async-trait", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 7e4d4df..61af9d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uu-remote-linux" -version = "0.1.21" +version = "0.1.22" 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/c_engine/wayland_engine.c b/c_engine/wayland_engine.c index 0bbb34e..6a5642b 100644 --- a/c_engine/wayland_engine.c +++ b/c_engine/wayland_engine.c @@ -425,7 +425,8 @@ retry:; if(frame->failed && frame->dmabuf_used && !retried) { /* Mapping/copy failure retries once on SHM; connection errors do not. */ dma_disable("copy"); retried=1; - for(unsigned i=0;i<2;i++) frame_clear(&frames[i]); + /* dma-buf stays disabled, so its cached buffers are never reused. */ + for(unsigned i=0;i<2;i++) { frame_clear(&frames[i]); dma_clear(&frames[i]); } pending=0; goto retry; } if(frame->failed || !frame->pixels || frame->width!=width || frame->height!=height) goto end; diff --git a/docs/release-notes/v0.1.22.md b/docs/release-notes/v0.1.22.md new file mode 100644 index 0000000..80c7ff3 --- /dev/null +++ b/docs/release-notes/v0.1.22.md @@ -0,0 +1,15 @@ +v0.1.21 视频管线改动的两处修正。/ Two follow-up fixes to the v0.1.21 video pipeline changes. + +### 修复 / Fixed +- 原生 Wayland 的 dma-buf 映射失败、回退到 SHM 时,已缓存的 dma-buf 缓冲没有释放(最多两个槽位,到会话结束才回收)。 + Release cached dma-buf buffers when capture falls back to SHM. +- 原生 Wayland 在发送受阻(背压)解除后的第一帧可能是受阻前预取的旧画面;现在等待超过两个帧间隔时会重新采集。 + After a backpressure stall the first native Wayland frame is captured fresh instead of reusing the stale prefetch. + +两处均由代码审查发现,只做了编译和单元测试,未在真机复现。 +Both found in review; compile- and unit-tested only. + +### 下载 / Download +`uu-remote-linux-v0.1.22-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。 + +**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.** diff --git a/src/wayland.rs b/src/wayland.rs index 4c77152..37bcfc2 100644 --- a/src/wayland.rs +++ b/src/wayland.rs @@ -85,12 +85,17 @@ pub fn capture_stdout() -> Result<(),String> { }).map_err(|e|format!("Capture writer: {e}"))?; let demand=std::env::var("UU_WAYLAND_DEMAND").is_ok_and(|v|v=="1"); let mut stdin=std::io::stdin().lock(); + let mut delivered=std::time::Instant::now(); loop { if demand { stdin.read_exact(&mut [0]).map_err(|_|"Capture demand pipe closed")?; } // Time from buffer availability: a slow encoder read must not shorten the next interval. let Ok(mut frame)=free_rx.recv() else { break }; let start=std::time::Instant::now(); + // The engine prefetches the next frame on delivery; after a backpressure stall that + // prefetch is as old as the stall, so drop it and capture the current screen. + if demand && start.duration_since(delivered)>interval*2 { capture(&mut frame)?; } capture(&mut frame)?; + delivered=std::time::Instant::now(); if full_tx.send(frame).is_err() { break; } if !demand { if let Some(left)=interval.checked_sub(start.elapsed()) { std::thread::sleep(left); }