Compare commits

...
20 Commits
Author SHA1 Message Date
VallierDevandClaude Opus 5.5 9994279b29 Release v0.2.15: aarch64 package, H.264 default on CPU hosts (#58, #59)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 01:33:23 +08:00
VallierDevandClaude Opus 5.5 6733a117a2 CPU hosts default to H.264; aarch64 release package (#59)
libx265 is about ten times slower than libx264 (15 vs 155 fps at 1080p on a 4-core Ampere A1),
so without NVENC/VAAPI the host now picks H.264 even when both sides offer H.265;
UU_VIDEO_CODEC=h265 still forces it. The release workflow builds x86_64 and aarch64 packages
(each with both engine plugins) and publishes them from a single job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 01:28:38 +08:00
Delicious233andCodex e3cab32c75 ci: build and test on linux/arm64 (#58)
Co-authored-by: Codex <[email protected]>
2026-10-20 01:28:17 +08:00
VallierDevandClaude Opus 5.5 57e1a5d07c Release v0.2.14: Hyprland output-bound pointer and monitor switching (#57)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-20 00:33:59 +08:00
ZoranandJuanZoran d90b4bccde Hyprland: bind absolute pointer to the captured output; opt-in monitor switching (#57)
Co-authored-by: JuanZoran <[email protected]>
2026-10-20 00:33:31 +08:00
VallierDevandClaude Opus 5.5 fa7fe733a6 Release v0.2.13: Wayland and portal engines in the release package
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 22:13:27 +08:00
VallierDevandClaude Opus 5.5 65c04e796a One release package for every desktop: Wayland and portal engines as runtime plugins
The release tarball was X11 only, so Hyprland/niri and GNOME/KDE Wayland users had to build from
source (#43, #54). With --features engine-plugins the wayland and portal engines are built as
libuu-wayland.so / libuu-portal.so and dlopen'ed only when the session selects them, so X11 hosts
need none of their libraries. The wayland plugin is built on Ubuntu 22.04 with the main binary;
the portal plugin needs libei >= 1.1 and is built on 24.04 (glibc >= 2.39). Source builds without
engine-plugins keep linking the engines statically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 22:10:11 +08:00
VallierDevandClaude Opus 5.5 3480318089 portal: say how to get a picture when the build lacks portal support (#43)
Release packages are X11 only; on GNOME/KDE Wayland auto selection picks the
portal backend, which then failed every 5 s with the opaque "portal
unavailable (code 2)".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 19:44:13 +08:00
VallierDevandClaude Opus 5.5 949acaac30 docs: niri row, non-template unit name, uinput dedicated-group example (#55)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 16:23:52 +08:00
VallierDevandClaude Opus 5.5 22fb6783a0 Release v0.2.12: pad odd capture sizes (#53)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 14:57:29 +08:00
wen0531andwen0531 10166c66e0 video: pad odd captured frame dimensions to even (#53)
The portal backend reports the compositor's logical desktop size, which is
odd when a scaled monitor's logical extent is odd: two stacked monitors at
150% scale capture 2560x2507. H.264/HEVC 4:2:0 encoders (and NVENC's surface
allocation) reject odd dimensions, so with such a desktop every encoder
failed to open:

  [libx264] height not divisible by 2 (2560x2507)
  [h264_nvenc] InitializeEncoder failed: out of memory (10)
  ERROR Live desktop stream stopped: Encoder output ended

and the official viewer stayed on 正在传输画面 while input still worked.

Pad the odd row/column in the filter chain when the native capture size is
known and no output scaling was requested (a no-op case omitted for even
sizes). The host display mode, the reported capture size and the explicit
分辨率 scaling path are unchanged; the fixed-input probe keeps its chain.

Co-authored-by: wen0531 <[email protected]>
2026-10-19 14:57:02 +08:00
VallierDevandClaude Opus 5.5 b7f9f2aa68 Release v0.2.11: wlroots text_input (#51), proxy bypass by default (#52)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 10:26:55 +08:00
aresbit 6416f75b7f auth: bypass ambient proxies by default; UU_USE_PROXY=1 opts in (#52)
A local HTTP/SOCKS proxy that intercepts TLS caused login to fail with
"tls handshake eof". Build all cloud API clients with no_proxy() unless
UU_USE_PROXY is explicitly truthy, so direct connections are the default
and environments that genuinely need a proxy can still enable it.
2026-10-19 10:25:58 +08:00
70cb5ad57e Wayland/wlroots: type mobile IME text through the virtual keyboard's spare keycodes (#51)
The mobile clients' input method sends `text_input {content}` over CONTROL. Upstream only
implements it for X11, so a Wayland host (Hyprland here) dropped the characters with a
warning. Wire it up: characters the session keymap already produces are pressed as
ordinary keycodes, and characters it cannot produce are carried by spare keycodes (the
keymap has ~33 named but unmapped ones) declared for the duration of one batch, in text
order, then removed again.

The focused client translates keycodes with the keymap the compositor last handed it, and
a keymap uploaded to a keyboard the seat already has is never handed on again: measured on
Hyprland 0.56.2, pressing the remapped keycodes then reproduces the previous message's
text (a space came out as the previous message's first character, and every message
repeated the one before it). Re-attaching the virtual keyboard is what makes the
compositor send the keymap to the client, so each batch does that, waits for the
compositor to install the keymap, and releases held keys first because the new keyboard
starts with none. No timing sleep is needed once the keyboard is re-attached, so there is
none. Plain latin text and spaces never touch the keymap at all. The pristine keymap is
restored after every call, so uu_wl_key keeps its own symbol map and the compositor is
never left with spare keys bound.

`wayland-text-probe` reports how many characters one upload can carry and types a sample;
UU_PROBE_SEQUENCE types one message per |-separated field, the way the phone's input
method sends them, which is what reproduced this locally.

Co-authored-by: Hey Claw <[email protected]>
Co-authored-by: Claude Code <[email protected]>
2026-10-18 21:07:23 +08:00
VallierDevandClaude Opus 5.5 7fcc674440 Release v0.2.10: official device_capability shape and sender_para_info (#49)
The iPhone client ignored our flat forward_setting device_capability and kept
quality and chroma locked. Send it nested under data.device_capability with
type beside it, list the formats the encoder really produces (4:4:4 when
available), and add sender_para_info, as the official Windows host does.
Verified with the UU iPhone app 4.42.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 20:54:34 +08:00
VallierDevandClaude Opus 5.5 19d0563781 desktop: viewer launcher entry and window icon; explicit StartupWMClass (#13)
The viewer's GTK windows had no icon and no desktop entry, so docks showed a
generic icon next to the host's. Add uu-remote-linux-viewer.desktop and use the
host icon for viewer windows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 17:25:14 +08:00
VallierDevandClaude Opus 5.5 edd4c9250c Release v0.2.9: HEVC picture-boundary AUs (#48), VAAPI buffer (#47)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 16:33:33 +08:00
ca49232674 HEVC: split access units by picture boundaries; no -aud for hevc_vaapi (#48)
* HEVC: split access units by picture boundaries, and stop passing -aud to hevc_vaapi

hevc_vaapi with `-aud 1` writes an AUD only at IRAPs and drops every other picture from
the bitstream: a 90-frame 640x360 clip came out as 3 IDRs and no P-frames. The reader
splits access units on AUDs, so each "frame" became one IDR plus a whole GOP, and the
IRAP gate then rejected all of them - the H.265 path sent no video at all (measured
~12 kbit/s outbound against 4-6 Mbit/s for H.264).

HEVC now leaves AUD off and hevc_au_offsets() splits on RFC 7798 picture boundaries (an
AUD, or the first NAL after a VCL NAL that is non-VCL or starts a picture), which also
keeps multi-slice pictures in one unit and covers the libx265/NVENC shapes. Parameter
sets still repeat in-band ahead of every IDR, so no out-of-band sprop is needed.

The fixed-input probe hardcoded H.264 in three places (settings, output muxer, first-unit
check), which is why this path was never measurable; it now follows UU_VIDEO_CODEC.

Verified with desktop-video-probe (90-frame fixed input): hevc_vaapi and libx265 both
emit 90 frames, first unit an IRAP with its parameter sets.

Assisted-by: DeepSeek V4.1 Flash-1017

* HEVC: keep suffix SEI, filler and end markers with the preceding picture

RFC 7798 / H.265 7.4.2.4.4 lets only AUD, VPS/SPS/PPS, prefix SEI and types
41-44/48-55 open an access unit; trailing NALs stay with the picture. Verified on
an RTX 3090 with the fixed-input probe: hevc_nvenc and libx265 both yield 90/90
decodable units with an IRAP first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: VallierDev <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-10-18 16:32:35 +08:00
NuoFang cb8253febf VAAPI: opt-in UU_VAAPI_BUFFER_MS for the VBV buffer (#47)
The 100-500 kbit default keeps NVENC keyframes inside the buffer, but VAAPI quantizes a
whole desktop keyframe when the buffer is that small: on a 2560x1440 H.264 VAAPI stream
capped at 30 Mbit/s the first IDR measured 59,910 bytes and the picture blurred once per
GOP before sharpening back.

UU_VAAPI_BUFFER_MS (10-1000 ms, VAAPI only) sizes the buffer as bitrate x ms/1000. With
250 ms on the same input the first IDR measured 142,397 bytes and the worst-frame Y-SSIM
over 180 static frames went from 0.9492 to 0.9933, with no rise in average bitrate.

Opt-in: unset, out of range or unparsable keeps the old buffer.

Assisted-by: DeepSeek V4.1 Flash-1017
2026-10-18 15:31:00 +08:00
VallierDevandClaude Opus 5.5 696cf10e33 docs: NAS Docker deployment guide; link it and the ghcr image from the READMEs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 11:52:36 +08:00
36 changed files with 1692 additions and 189 deletions

No files matched your search

+39 -1
View File
@@ -24,10 +24,17 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config \
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev \
libwayland-dev libwayland-bin libxkbcommon-dev
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked
# Same as the release job: the wayland plugin is built on 22.04; libei is unavailable here, so
# the portal plugin is skipped with a warning (release builds it on 24.04).
- name: Release feature set
run: |
cargo build --locked --features wayland,portal,engine-plugins --bin uuremote-server
test -f target/debug/libuu-wayland.so
test-viewer:
runs-on: ubuntu-22.04
@@ -56,6 +63,12 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked --features wayland,portal
# Release layout: engines as runtime-loaded plugins; uuremote-server must not link them.
- name: Engine plugins
run: |
cargo build --locked --features wayland,portal,engine-plugins --bin uuremote-server
for lib in libuu-wayland.so libuu-portal.so; do test -f "target/debug/$lib"; done
! readelf -d target/debug/uuremote-server | grep NEEDED | grep -E 'libei|libpipewire|libwayland-client|libxkbcommon'
- name: Native portal and EIS regression tests (ASan/UBSan)
env:
ASAN_OPTIONS: detect_leaks=1
@@ -82,3 +95,28 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked --features inproc-av
test-linux-arm64:
# aarch64 hosts (Ampere A1, arm64 VMs, Apple-silicon VMs) build from source, so keep that
# build honest on a native arm64 runner instead of letting it rot between releases.
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config \
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev \
libwayland-dev libwayland-bin libxkbcommon-dev libglib2.0-dev libpipewire-0.3-dev libei-dev
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --locked
- name: Release binary
run: |
cargo build --locked --release --bin uuremote-server
file target/release/uuremote-server
# The aarch64 release package ships both engine plugins.
- name: Release feature set
run: |
cargo build --locked --features wayland,portal,engine-plugins --bin uuremote-server
for lib in libuu-wayland.so libuu-portal.so; do test -f "target/debug/$lib"; done
+60 -8
View File
@@ -9,29 +9,81 @@ permissions:
packages: write
jobs:
release:
# Built on 22.04 so the binary also runs on Ubuntu 22.04/24.04 and newer Debian (glibc >= 2.35).
runs-on: ubuntu-22.04
# GNOME/KDE Wayland engine: libei >= 1.1 first ships in Ubuntu 24.04, so this plugin needs
# glibc >= 2.39. It is only loaded on portal sessions; X11 and wlroots hosts never open it.
portal-plugin:
strategy:
matrix:
include:
- { arch: x86_64, runner: ubuntu-24.04 }
- { arch: aarch64, runner: ubuntu-24.04-arm }
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config \
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev libsdl2-dev
libx11-dev libxext-dev libxtst-dev libxfixes-dev libglib2.0-dev libpipewire-0.3-dev libei-dev
- uses: dtolnay/rust-toolchain@stable
- run: UU_NO_GTK=1 cargo build --release --locked --features portal,engine-plugins --bin uuremote-server
- uses: actions/upload-artifact@v4
with:
name: libuu-portal-${{ matrix.arch }}
path: target/release/libuu-portal.so
build:
needs: portal-plugin
strategy:
matrix:
include:
- { arch: x86_64, runner: ubuntu-22.04 }
- { arch: aarch64, runner: ubuntu-22.04-arm }
# Built on 22.04 so the binary also runs on Ubuntu 22.04/24.04 and newer Debian (glibc >= 2.35).
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config \
libx11-dev libxext-dev libxtst-dev libxfixes-dev libgtk-3-dev libsdl2-dev \
libwayland-dev libwayland-bin libxkbcommon-dev
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --release --locked
- run: cargo build --release --locked
# Experimental viewer; built after the host so uuremote-server keeps the default features.
# One package for every desktop: Wayland (wlroots) and GNOME/KDE portal engines are plugins
# opened at runtime (engine-plugins), so X11 hosts need none of their libraries.
- run: cargo build --release --locked --features wayland,portal,engine-plugins
- uses: actions/download-artifact@v4
with:
name: libuu-portal-${{ matrix.arch }}
path: target/release
# Experimental viewer; built after the host so uuremote-server keeps the release features.
- run: cargo build --release --locked --features native-viewer,viewer-sdl --bin uuremote-viewer
- name: Package
run: |
name=uu-remote-linux-${GITHUB_REF_NAME}-x86_64-linux
name=uu-remote-linux-${GITHUB_REF_NAME}-${{ matrix.arch }}-linux
mkdir -p "$name"
cp target/release/uuremote-server target/release/uuremote-viewer LICENSE README.md README.en.md config.example.json "$name/"
cp target/release/uuremote-server target/release/uuremote-viewer target/release/libuu-wayland.so target/release/libuu-portal.so \
LICENSE README.md README.en.md config.example.json "$name/"
cp -r contrib "$name/"
tar czf "$name.tar.gz" "$name"
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
- uses: actions/upload-artifact@v4
with:
name: package-${{ matrix.arch }}
path: uu-remote-linux-*.tar.gz*
# One publisher, so the matrix legs never race to create the release.
release:
needs: build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: package-*
merge-multiple: true
- uses: softprops/action-gh-release@v2
with:
body_path: docs/release-notes/${{ github.ref_name }}.md
+3
View File
@@ -116,6 +116,8 @@ viewer does not reconnect them automatically.
| `UU_FFMPEG_ROOT` | FFmpeg prefix (`bin/ffmpeg`, libs in `lib/x86_64-linux-gnu`) |
| `UU_AUDIO=0`, `UU_AUDIO_SOURCE` | disable sound / choose the Pulse source (default `@DEFAULT_MONITOR@`) |
| `UU_LOGIN_WINDOW=0` | don't auto-open the login window |
| `UU_ENGINE_DIR` | directory holding `libuu-wayland.so` / `libuu-portal.so` (`--features engine-plugins`, used by release packages: engines are dlopen'ed only on Wayland sessions; also searched next to the binary, `../lib/uu-remote-linux`, `~/.local/lib/uu-remote-linux`, `/usr/lib/uu-remote-linux`) |
| `UU_USE_PROXY=1` | honor HTTP/SOCKS proxy env vars; cloud API clients bypass env proxies by default |
| `UU_REMOTE_ASSIST=0`, `UU_ASSIST_ALLOW=1`, `UU_ASSIST_UI=tty`, `UU_ASSIST_DEBUG=1` | disable assistance / allow at start / terminal UI for `assist` / include the server's short error message in assist errors |
Token has no expiry field; API code 1120 (HTTP 422) means invalid/expired → re-login. The config is re-read
@@ -142,6 +144,7 @@ every 60 s.
| `src/initialization.rs`, `src/control_protocol.rs`, `src/protocol.rs` | protobuf encoders/decoders for CONTROL |
| `src/session_ice.rs`, `src/network_diagnostics.rs` | cloud ICE servers, address-free path diagnostics |
| `src/desktop_backend.rs`, `src/wayland.rs`, `src/portal*.rs` | backend selection, Hyprland, GNOME/KDE portal |
| `src/engine_plugin.rs` | `engine_ffi!`: engine C functions linked statically, or dlsym-resolved from runtime plugins with `engine-plugins` |
| `c_engine/portal_eis.inc` | scaled GNOME input through the existing Portal session's EIS connection; all input must use EIS once connected |
| `c_engine/x11_engine.c`, `c_engine/clipboard.c` | X11 capture/input/selection |
| `c_engine/wayland_engine.c`, `c_engine/portal_engine.c` | Wayland and portal engines |
Generated
+1 -1
View File
@@ -2741,7 +2741,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uu-remote-linux"
version = "0.2.8"
version = "0.2.15"
dependencies = [
"async-trait",
"base64 0.22.1",
+3 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "uu-remote-linux"
version = "0.2.8"
version = "0.2.15"
edition = "2021"
default-run = "uuremote-server"
authors = ["uu-remote-linux contributors"]
@@ -28,6 +28,8 @@ wayland = []
# Experimental direct linear framebuffer capture; never enabled in release builds.
kms = []
portal = []
# Build the wayland/portal engines as runtime-loaded libuu-wayland.so / libuu-portal.so (release packages).
engine-plugins = []
# In-process capture and encoding through FFmpeg 6 libraries (libavcodec/libavdevice dev packages).
# Off by default so release binaries do not link the build machine's libav.
inproc-av = ["dep:ffmpeg-next", "dep:x11rb"]
+66 -7
View File
@@ -10,6 +10,8 @@
> It now also ships an **experimental Linux viewer**, `uuremote-viewer`, that controls official Windows / Mac hosts or this
> project's host from Linux (desktop, file transfer, terminal, port mapping, remote assistance; see
> [below](#experimental-native-viewer-uuremote-viewer)).
> Desktop-less **Synology / NAS** boxes can run it in Docker: [deployment guide](docs/deploy-nas-docker.md#english), image
> [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux).
>
> This is a personal hobby project. **It is not affiliated with NetEase and is not an official client.**
> If NetEase considers this project infringing or inappropriate, please DM me on X
@@ -71,13 +73,14 @@ authorized session. Independent file/terminal tool peers do not reset input.
| Xfce | X11 | ✅ Tested in a VM | default |
| Cinnamon / MATE | X11 | ✅ Tested in a VM | default |
| Hyprland | Wayland (native wlroots protocols) | 🧪 Experimental, tested in a VM (some features limited, see below) | `--features wayland` |
| niri | Wayland (native wlroots protocols) | 🧪 Experimental; protocol support confirmed from niri sources, not yet tested on hardware (#55) | `--features wayland` |
| GNOME / KDE Plasma | Wayland (xdg-desktop-portal) | 🧪 Experimental; validation scope and limits below | `--features wayland,portal` |
The GNOME Wayland Portal/EIS path has been checked for video and mouse/keyboard input on Ubuntu 26.04, GNOME 50, with one 4K screen at 200% scale; auto unlock after a cold locked connection is verified with the official Mac and iPhone 4.42.0 viewers, while other lock recovery and reconnection still need hardware acceptance testing. Apart from that path and GNOME on X11, desktop testing has primarily used virtual machines. If something goes wrong on
real hardware, please [open an issue](../../issues) with your distribution, desktop, GPU and the relevant lines from
`journalctl --user -u uuremote-native.service`.
Wayland limits: single screen, fixed resolution. The native Hyprland backend now pipelines two shm screencopy buffers and passes the viewer's requested fps to both capture pacing and the encoder. Actual fps remains limited by the compositor, rendering and readback (the old serial path measured about 16–22 fps at 2560x1600; the pipeline is VM-measured only, not a hardware guarantee). The portal backend does not support dynamic resolution; see below for GNOME wake and lock recovery; the clipboard syncs while the viewer's remote window has focus. On the first connection the desktop asks for "Remote Desktop / Screen Sharing"
Wayland limits: captures one screen by default; Hyprland can enable monitor switching as described below. Resolution is fixed. The native Hyprland backend now pipelines two shm screencopy buffers and passes the viewer's requested fps to both capture pacing and the encoder. Actual fps remains limited by the compositor, rendering and readback (the old serial path measured about 16–22 fps at 2560x1600; the pipeline is VM-measured only, not a hardware guarantee). The portal backend does not support dynamic resolution; see below for GNOME wake and lock recovery; 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.
Scaled GNOME desktops using native Portal input use EIS on the same authorized session when `ConnectToEIS` and a screen `mapping_id` are available. Each axis is mapped using the matched region and actual frame dimensions, with no fixed resolution or scale factor. This avoids scaled-coordinate rejection by `NotifyPointerMotionAbsolute`. Portal builds require libei >= 1.1. Missing EIS support retains the legacy input path and its existing scaling limitations; other initialization failures are reported and trigger session recovery. After a successful EIS connection, all input uses EIS. Capture alone and uinput do not initialize EIS; missing optional logical dimensions do not block capture. Keyboard input uses the existing Windows VK to evdev mapping. Recovery keeps the encoder frame dimensions fixed but accepts logical-size changes after scaling. On GNOME, a display-change notification enables earlier recovery when previously streaming Portal capture remains paused without a valid format for a 200 ms grace after both conditions are present. Healthy renegotiation cancels the early check; repeated notifications do not postpone the same interruption. The five-second fallback remains without a related notification. Static video and valid-format pauses do not trigger recovery. Tested while connected on Ubuntu 26.04, GNOME Wayland, one 3840x2160 display: 200% -> 166.67% -> 200%, with continuously updating video and full-screen pointer control after recovery. Switching briefly freezes and goes black before recovering; five seconds is the fallback threshold, not total recovery time. See [#35](../../pull/35) for timing measurements and validation limits. Lock recovery still needs hardware acceptance testing; multi-monitor support, live resolution changes, and rotation/reflection transforms are outside this fix's scope. Capture settings remain at protocol version 4: advertised resolutions use pixel coordinates and DPR 1; Portal logical dimensions are used only for local input mapping.
@@ -100,11 +103,19 @@ failure falls back to SHM. The virgl VM verified fallback only: successful impor
mapping and hardware acceleration remain unverified. This is not zero-copy VAAPI;
`UU_VIDEO_ENCODER=vaapi` still uploads CPU frames through FFmpeg.
### Hyprland monitor switching (experimental)
Native Wayland absolute pointer motion now targets the captured output by default, fixing multi-monitor click offsets. uinput may still handle keyboard, buttons and relative motion.
Set `UU_WAYLAND_MULTISCREEN=1` to select physical monitors from the phone client. `UU_WAYLAND_OUTPUT` chooses the initial output. Capture and absolute pointer targeting switch together across different resolutions, scales and desktop positions.
Switching reuses one video track and pauses input until the new source sends a frame. Capture/encoder failure or a first-frame timeout requests restoration of the previous source. The inventory uses `hyprctl` and supports unrotated outputs; restart the host after monitor hotplug or layout changes. Phone-side switching and clicks were tested on Omarchy / Hyprland with 2560×1440 at 125% and 1920×1080 at 133.33%.
## Not implemented / not supported
| Feature | Status |
|---|---|
| Switching between multiple monitors | In progress |
| Switching between multiple monitors | Experimental on native Hyprland Wayland; see above |
| 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 |
@@ -117,6 +128,28 @@ mapping and hardware acceleration remain unverified. This is not zero-copy VAAPI
## Installation
### 0. Prebuilt release package (recommended, x86_64 / aarch64)
Download `uu-remote-linux-<version>-x86_64-linux.tar.gz` (ARM64: `aarch64-linux`) from [Releases](../../releases/latest), extract it, then:
```sh
install -Dm755 uuremote-server ~/.local/bin/uuremote-server
install -Dm644 libuu-wayland.so libuu-portal.so -t ~/.local/lib/uu-remote-linux/
```
One package covers X11, wlroots compositors (Hyprland, Sway, niri) and GNOME/KDE Wayland: the backend is chosen from the
running session at startup, and the matching `libuu-*.so` is loaded only on Wayland, so X11 hosts need no Wayland libraries.
| Session | Requirements |
|---|---|
| X11 | glibc >= 2.35 (Ubuntu 22.04, Debian 12 and newer) |
| wlroots (Hyprland / Sway / niri) | the same, plus `libwayland-client` and `libxkbcommon` (present on Wayland desktops) |
| GNOME / KDE Wayland | glibc >= 2.39 (Ubuntu 24.04, Fedora 40, Debian 13 and newer), libei >= 1.1 and PipeWire |
Plugins are found next to `uuremote-server`, in `../lib/uu-remote-linux/`, `~/.local/lib/uu-remote-linux/` or
`/usr/lib/uu-remote-linux/` (`UU_ENGINE_DIR` overrides); a missing library or too old glibc is reported in the log.
Continue with step 3 (login). Other architectures: build from source below.
### 1. Dependencies (Ubuntu / Debian)
```sh
@@ -223,6 +256,7 @@ Optional launcher icon:
```sh
install -Dm644 contrib/desktop/uu-remote-linux.svg ~/.local/share/icons/hicolor/scalable/apps/uu-remote-linux.svg
install -Dm644 contrib/desktop/uu-remote-linux.desktop ~/.local/share/applications/uu-remote-linux.desktop
install -Dm644 contrib/desktop/uu-remote-linux-viewer.desktop ~/.local/share/applications/uu-remote-linux-viewer.desktop
```
Verified with the official Mac viewer: guest connections, wrong-code rejection, code rotation, switching assistance off,
@@ -237,7 +271,8 @@ starts at boot without a login. The viewer's remote desktop keeps showing "conne
Log in once with `uuremote-server login --no-gui` (QR in the terminal).
**Synology / NAS (Docker)**: run headless mode in a container on a desktop-less NAS (file transfer, terminal, port
mapping): image `ghcr.io/vallierdev/uu-remote-linux`, see [docker/README.md](docker/README.md). Verified on Synology DSM 7.3 (x86_64).
mapping): image [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux),
see the [NAS deployment guide](docs/deploy-nas-docker.md#english). Verified on Synology DSM 7.3 (x86_64).
**Paste files from a Mac terminal**: when using Ghostty over UU's SSH port mapping,
the optional [Mac SSH paste companion](contrib/macos-ssh/README.md) uploads files
@@ -274,15 +309,19 @@ Common environment variables:
|---|---|
| `UU_CONFIG` | Config file path (default `~/.config/uuremote/config.json`) |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless) |
| `UU_WAYLAND_MULTISCREEN=1` | Enable Hyprland physical monitor switching (off by default) |
| `UU_WAYLAND_OUTPUT` | Initial native Wayland output name, e.g. `HDMI-A-1` |
| `UU_INPUT_BACKEND` | `auto` (default: uinput on Wayland when accessible) / `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | Disable the Ctrl+V paste rewrite in terminal windows |
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: opt-in Intel/AMD; `nvenc`: force NVENC; unset: NVENC only when an NVIDIA driver is loaded, else CPU |
| `UU_VAAPI_BUFFER_MS` | VAAPI VBV buffer in ms (10-1000, VAAPI only); raise it when keyframes are squeezed into a blur at high resolution |
| `UU_FFMPEG_ROOT` | Use FFmpeg from this prefix |
| `UU_AUDIO=0` | Disable sound; `UU_AUDIO_SOURCE` picks the PulseAudio source |
| `UU_REMOTE_ASSIST=0` | Disable remote assistance (no guest assistance before sign-in either) |
| `UU_ASSIST_ALLOW=1` | Allow remote assistance at start (overrides the saved switch) |
| `UU_LOGIN_WINDOW=0` | Do not open the login window automatically when credentials are missing |
| `UU_PORT_MAPPING=0` | Disable port mapping (the official host's controlled-side switch) |
| `UU_USE_PROXY=1` | Honor HTTP/SOCKS proxy environment variables; by default proxies are ignored and NetEase servers are reached directly |
Host settings such as "lock after remote session" and "mute host" are stored in
`~/.config/uuremote/host_settings.json`.
@@ -344,13 +383,22 @@ Released under the [GPL-3.0](LICENSE): you may use, modify and redistribute it,
### H.265 / HEVC
When both sides support H.265 the host uses it (as the official host does: the host picks the codec from both
When both sides support H.265 and the host has a hardware encoder (NVENC / explicit VAAPI), the host uses it (as the official host does: the host picks the codec from both
capability lists; the official Mac viewer lists H265 first in its SDP). The first desktop connection probes a
synthetic frame and announces encoder support with CodecNegotiation. `hevc_nvenc`, `libx265` and explicit
`UU_VIDEO_ENCODER=vaapi` (`hevc_vaapi`); hardware failure falls back to software HEVC, then to H.264.
`UU_VIDEO_CODEC=h264` forces H.264. 8-bit; true color 4:4:4 uses hevc_nvenc `rext` / libx265 `main444-8`.
Verified with the official Mac viewer on an RTX 3090 (hevc_nvenc, including 4:4:4); libx265, hevc_vaapi and
other viewers are not hardware-verified.
Verified with the official Mac viewer on an RTX 3090 (hevc_nvenc, including 4:4:4) and with the official Android
viewer on Intel Alder Lake-P (iHD): 2560x1440 fully hardware-encoded, 58 fps decoded at about 10 ms. libx265 is
still not verified against a real viewer.
With CPU-only encoding the default is H.264: libx265 is about ten times slower than libx264 (measured ~15 vs ~155 fps
at 1080p on a 4-core ARM host, #59); `UU_VIDEO_CODEC=h265` forces H.265. The applied frame rate comes from the viewer's
quality/fps menu; `UU_DISPLAY_FPS` only changes the reported display refresh rate.
HEVC access units are split on RFC 7798 picture boundaries instead of AUDs: `hevc_vaapi` with `-aud 1` writes an
AUD only at IRAPs and drops every other picture from the bitstream, so an AUD-based reader turns a whole GOP into
one "frame" and the IRAP gate then rejects all of them: the connection stalls at "transferring" while the host
sends about 12 kbit/s. `UU_VIDEO_CODEC=h265` selects H.265 explicitly for A/B diagnosis.
### VAAPI (opt-in / 显式启用)
@@ -363,6 +411,13 @@ with a warning. Accepted on Intel UHD 770 (iHD) with the default FFmpeg process
viewer (presets, fps, scaling, reconnect; no fallback, ~40% less CPU than libx264). AMD and the `inproc-av`
VAAPI path are not hardware-verified.
The default VAAPI VBV buffer (100-500 kbit) squeezes keyframes hard at high resolution: on a 2560x1440
H.264 VAAPI stream capped at 30 Mbit/s the first IDR measured 59,910 bytes and the picture blurred at
every GOP before sharpening back. `UU_VAAPI_BUFFER_MS=250` (buffer = bitrate cap x ms/1000) restored that
first IDR to 142,397 bytes and raised the worst-frame Y-SSIM from 0.9492 to 0.9933 without raising the
average bitrate. Off by default; unset or out of the 10-1000 ms range keeps the old buffer. Larger
keyframes can queue briefly on a weak link, so start at 250 ms.
### Virtual audio / 虚拟声卡
The viewer's 静音运行 switch creates the null sink `uu-remote-sink`,
@@ -396,13 +451,17 @@ Omarchy uses Hyprland: run in its user session, select `UU_DESKTOP_BACKEND=wayla
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` (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.
For unattended accounts, explicitly restrict `/dev/uinput` access to a dedicated group, e.g. `z /dev/uinput 0660 root uinput`
in `/etc/tmpfiles.d/uinput.conf` plus `sudo usermod -aG uinput <user>` (dedicated account only).
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`.
Keep the unit name `uuremote-native.service` (not a template `[email protected]`): the desktop icon and
`uuremote-server show` always start that name (override with `UU_SERVICE_UNIT`). `niri --session` also imports
`WAYLAND_DISPLAY` before it is ready, so the same unit applies to niri (#55).
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`.
+64 -8
View File
@@ -8,6 +8,7 @@
> 装上之后,就能用官方的 Mac / Windows / 手机客户端远程控制你的 Linux 电脑。
> 现在还附带一个**实验性 Linux 控制端** `uuremote-viewer`:在 Linux 上用 UU 账号远控官方 Windows / Mac 被控端或本项目主机
> (桌面、文件传输、终端、端口映射、远程协助,详见[下文](#实验性原生控制端uuremote-viewer))。
> 没有桌面的**群晖 / NAS** 也能用 Docker 部署:[部署指南](docs/deploy-nas-docker.md),镜像 [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux)。
>
> 这是个人兴趣项目,**与网易无关,也不是官方客户端**。如果网易认为本项目侵权或有不妥,
> 请在推特私信我 **[@ai_fengshou](https://x.com/ai_fengshou)**,我会第一时间自行下架。
@@ -64,12 +65,15 @@ Portal 仅作用于本服务获授权的会话。文件传输、终端等独立
| Xfce | X11 | ✅ 虚拟机测试通过 | 默认 |
| Cinnamon / MATE | X11 | ✅ 虚拟机测试通过 | 默认 |
| Hyprland | Wayland(wlroots 原生协议) | 🧪 实验性,虚拟机测试(部分功能受限,见下) | `--features wayland` |
| niri | Wayland(wlroots 原生协议) | 🧪 实验性,协议支持已按 niri 源码确认,尚未实机验收(#55) | `--features wayland` |
| GNOME / KDE Plasma | Wayland(xdg-desktop-portal) | 🧪 实验性,验证范围与限制见下 | `--features wayland,portal` |
最后一列是源码编译方式;Release 预编译包已包含全部后端,直接使用即可(见[安装](#0-直接用-release-预编译包推荐x86_64))。
GNOME Wayland 的 Portal/EIS 路径已在 Ubuntu 26.04、GNOME 50、单屏 4K/200% 缩放下验证画面和键鼠;锁屏冷连接自动解锁已用 Mac 和 iPhone 4.42.0 客户端实机验证,其余锁屏恢复及重连仍待验收。除 GNOME 的上述路径和 X11 外,其余桌面目前主要在虚拟机里测试。如果你在真机上遇到问题,欢迎[提交 issue](../../issues),
请附上发行版、桌面环境、显卡型号和 `journalctl --user -u uuremote-native.service` 里的相关日志。
Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持动态分辨率;GNOME 的屏幕唤醒与锁屏恢复见下;剪贴板只在控制端的远控窗口处于前台时同步。
Wayland 下的限制:默认采集单屏,Hyprland 可按上文启用切屏;分辨率固定;Hyprland 原生后端默认使用双缓冲流水线 shm screencopy,控制端帧率设置会同步到采集节拍和编码器,但实际帧率仍受合成器、渲染和读回速度限制(旧串行路径在 2560x1600 曾测得约 16~22 帧;流水线只在虚拟机里测量过,不代表实机保证);portal 后端暂不支持动态分辨率;GNOME 的屏幕唤醒与锁屏恢复见下;剪贴板只在控制端的远控窗口处于前台时同步。
GNOME 缩放桌面在使用 Portal 原生键鼠时,若支持 `ConnectToEIS` 和屏幕 `mapping_id`,通过同一授权会话的 EIS 接口注入输入,按匹配的区域与实际帧尺寸分别映射横纵坐标,没有固定分辨率或缩放倍率,可避免 `NotifyPointerMotionAbsolute` 在缩放时拒绝坐标。Portal 构建需要 libei ≥ 1.1。缺少 EIS 支持时保留旧输入路径及其既有缩放限制;其他初始化错误会明确报告并触发会话恢复。EIS 连接成功后全部输入统一使用 EIS。只采集画面或使用 uinput 时不会初始化 EIS;缺少可选的逻辑尺寸也不阻断采集。键盘沿用项目现有的 Windows VK → evdev 映射。恢复时保持编码器的采集帧尺寸不变,允许缩放后的逻辑尺寸变化。GNOME 显示配置变化后,已推流的 Portal 采集若持续「暂停且无有效格式」,会在关联通知后的 200 毫秒宽限结束后提前进入现有恢复流程;正常重协商恢复会取消提前判定,连续通知不会推迟同次异常的判定。未收到相关通知时保留五秒兜底;静态画面或有效格式下的暂停不会触发恢复。Ubuntu 26.04、GNOME Wayland 单屏 3840×2160 已实测保持连接切换 200%→166.67%→200%,恢复后画面持续更新且鼠标可控制全屏;切换期间会短暂停顿、黑屏后恢复,五秒是兜底判定阈值,并非总恢复时间。提前恢复的测量结果和验证范围见 [#35](../../pull/35)。此路径仍需实机验证锁屏恢复;多屏、连接中改变分辨率及旋转/镜像变换不属于本次修复范围。 捕获设置协议仍为版本 4:对客户端上报的分辨率统一使用像素坐标、DPR 为 1;Portal 逻辑尺寸仅用于本地输入映射。
@@ -86,11 +90,19 @@ GNOME Portal 的控制通道不再等待授权窗口或第一帧画面:先通
原生 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 帧。
首次连接时,桌面会弹窗请求「远程桌面 / 屏幕共享」授权,同意后会记住授权。
### Hyprland 多显示器切换(实验性)
原生 Wayland 的绝对鼠标定位默认绑定正在采集的输出,修复双屏桌面下的点击偏移。uinput 可继续用于键盘、按键和相对移动。
设置 `UU_WAYLAND_MULTISCREEN=1` 后,手机端可选择并切换物理显示器;`UU_WAYLAND_OUTPUT` 指定默认屏幕。画面与绝对鼠标定位同步切换,支持不同分辨率、缩放和桌面位置。
切屏复用同一条视频轨道,过渡期间暂停输入,发送新屏首帧后恢复;采集或编码失败、等待首帧超时会请求恢复原屏。当前通过 `hyprctl` 枚举未旋转的显示器,显示器插拔或布局变化后需重启服务。已在 Omarchy / Hyprland 上用官方手机客户端实测 2560×1440(125%)与 1920×1080(133.33%)双屏切换及点击。
## 尚未实现 / 不支持
| 功能 | 状态 |
|---|---|
| 多显示器切换 | 开发中 |
| 多显示器切换 | Hyprland 原生 Wayland 后端实验性支持,见上文 |
| 真彩(4:4:4) | 支持(v0.1.15):NVENC / libx264 的默认 FFmpeg 管线输出 H.264 High 4:4:4;VAAPI 和 `inproc-av` 管线仍为 4:2:0,并如实回报给客户端 |
| HDR | 未实现 |
| 超级屏 / 虚拟显示器 | 未实现 |
@@ -103,6 +115,27 @@ GNOME Portal 的控制通道不再等待授权窗口或第一帧画面:先通
## 安装
### 0. 直接用 Release 预编译包(推荐,x86_64 / aarch64)
从 [Releases](../../releases/latest) 下载 `uu-remote-linux-<版本>-x86_64-linux.tar.gz`(ARM64 选 `aarch64-linux`),解压后:
```sh
install -Dm755 uuremote-server ~/.local/bin/uuremote-server
install -Dm644 libuu-wayland.so libuu-portal.so -t ~/.local/lib/uu-remote-linux/
```
同一个包支持 X11、Hyprland 等 wlroots 合成器和 GNOME/KDE Wayland:程序启动时按当前会话自动选择后端,只在 Wayland 会话里
才加载对应的 `libuu-*.so`,X11 用户不需要任何 Wayland 库。系统要求:
| 会话 | 要求 |
|---|---|
| X11 | glibc ≥ 2.35(Ubuntu 22.04、Debian 12 及更新) |
| Hyprland / Sway / niri 等 wlroots | 同上,另需 `libwayland-client`、`libxkbcommon`(Wayland 桌面自带) |
| GNOME / KDE Wayland | glibc ≥ 2.39(Ubuntu 24.04、Fedora 40、Debian 13 及更新),以及 libei ≥ 1.1、PipeWire |
插件放在 `uuremote-server` 同目录、`../lib/uu-remote-linux/`、`~/.local/lib/uu-remote-linux/` 或 `/usr/lib/uu-remote-linux/` 都能找到
(`UU_ENGINE_DIR` 可指定)。缺库或版本太旧时日志会写明原因。之后从第 3 步「登录」继续;其他架构请按下面源码编译。
### 1. 依赖(Ubuntu / Debian)
```sh
@@ -198,6 +231,7 @@ X11 默认继续用 XTest,因为它能正确处理网络延迟下按住不放
```sh
install -Dm644 contrib/desktop/uu-remote-linux.svg ~/.local/share/icons/hicolor/scalable/apps/uu-remote-linux.svg
install -Dm644 contrib/desktop/uu-remote-linux.desktop ~/.local/share/applications/uu-remote-linux.desktop
install -Dm644 contrib/desktop/uu-remote-linux-viewer.desktop ~/.local/share/applications/uu-remote-linux-viewer.desktop
```
验证情况:访客身份下的连接、错误验证码拒绝、用完换码、关闭后不可连接、登录与退出登录的切换,已用官方 Mac 客户端实测通过。
@@ -209,8 +243,9 @@ install -Dm644 contrib/desktop/uu-remote-linux.desktop ~/.local/share/applicatio
再执行 `loginctl enable-linger $USER`,这样开机后不用登录,systemd 用户服务(以及 `XDG_RUNTIME_DIR`、用户 D-Bus)也会自动启动。
无头模式下控制端点「远程桌面」会一直显示正在连接,这是正常的。首次登录用 `uuremote-server login --no-gui` 在终端里扫码。
**群晖 / NAS(Docker)**:没有桌面的 NAS 可以用容器运行无头模式(文件传输、终端、端口映射),
镜像 `ghcr.io/vallierdev/uu-remote-linux`,步骤见 [docker/README.md](docker/README.md)。已在群晖 DSM 7.3(x86_64)上实测三项功能。
**群晖 / NAS(Docker)**:没有桌面的 NAS 可以用容器运行无头模式(文件传输、终端、端口映射)。
镜像 [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux),
**部署步骤见 [群晖 / NAS 部署指南](docs/deploy-nas-docker.md)**。已在群晖 DSM 7.3(x86_64)上实测三项功能。
**Mac 终端粘贴文件**:使用 Ghostty 通过 UU 端口映射连接 SSH 时,可安装
[Mac SSH 粘贴助手](contrib/macos-ssh/README.md)。在 Finder 复制文件后按 Command-V,
@@ -245,15 +280,19 @@ systemctl --user restart uuremote-native.service
|---|---|
| `UU_CONFIG` | 配置文件路径(默认 `~/.config/uuremote/config.json`) |
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms`(实验性特性) / `none`(无头模式) |
| `UU_WAYLAND_MULTISCREEN=1` | 启用 Hyprland 物理显示器切换(默认关闭) |
| `UU_WAYLAND_OUTPUT` | 原生 Wayland 默认采集输出名称,例如 `HDMI-A-1` |
| `UU_INPUT_BACKEND` | `auto`(默认,Wayland 下可用时用 uinput)/ `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | 关闭终端窗口里的 Ctrl+V 粘贴转换 |
| `UU_VIDEO_ENCODER` | `cpu` 强制 CPU;`vaapi` 显式启用 Intel/AMD 硬编;`nvenc` 强制 NVENC;未设置时检测到 NVIDIA 驱动才用 NVENC,否则用 CPU |
| `UU_VAAPI_BUFFER_MS` | VAAPI 的 VBV 缓冲(10–1000 ms,仅 `UU_VIDEO_ENCODER=vaapi` 时生效);高分辨率下关键帧被压糊时用它换稳定画质 |
| `UU_FFMPEG_ROOT` | 使用指定目录下的 FFmpeg |
| `UU_AUDIO=0` | 关闭声音转发;`UU_AUDIO_SOURCE` 指定 PulseAudio 采集源 |
| `UU_LOGIN_WINDOW=0` | 凭证缺失时不自动弹出登录窗口 |
| `UU_REMOTE_ASSIST=0` | 关闭远程协助(未登录时也不再以访客身份提供协助) |
| `UU_ASSIST_ALLOW=1` | 启动时就允许他人远程协助(覆盖窗口里保存的开关状态) |
| `UU_PORT_MAPPING=0` | 关闭端口映射(对应官方被控端的开关) |
| `UU_USE_PROXY=1` | 使用环境变量里的 HTTP/SOCKS 代理;默认忽略代理、直连网易服务器 |
「远程结束后自动锁屏」「静音运行」等设置保存在 `~/.config/uuremote/host_settings.json`。
@@ -307,11 +346,17 @@ flowchart LR
### H.265 / HEVC
控制端和主机都支持 H.265 时,主机自动使用 H.265(与官方主机一致,由主机按双方能力选择;官方 Mac 客户端在 SDP
中优先列出 H.265)。首次桌面连接会用合成帧探测实际编码能力,并通过 CodecNegotiation 告知客户端。支持 `hevc_nvenc`、
控制端和主机都支持 H.265、且主机使用硬件编码器(NVENC / 显式 VAAPI)时,主机自动使用 H.265(与官方主机一致,由主机按双方能力选择;官方 Mac 客户端在 SDP
中优先列出 H.265)。**只有 CPU 编码时默认用 H.264**:libx265 比 libx264 慢约 10 倍(4 核 ARM 上 1080p 实测约 15 帧对 155 帧,#59),
可用 `UU_VIDEO_CODEC=h265` 强制 H.265。实际帧率由控制端的「画质/帧率」菜单决定;`UU_DISPLAY_FPS` 只改上报的显示器刷新率。首次桌面连接会用合成帧探测实际编码能力,并通过 CodecNegotiation 告知客户端。支持 `hevc_nvenc`、
`libx265`、显式 `UU_VIDEO_ENCODER=vaapi` 的 `hevc_vaapi`;硬件失败先回落软件 HEVC,再回落 H.264。
`UU_VIDEO_CODEC=h264` 强制使用 H.264。8-bit;真彩 4:4:4 使用 hevc_nvenc `rext` / libx265 `main444-8`。
已用官方 Mac 客户端在 RTX 3090(hevc_nvenc,含 4:4:4)实机验收;libx265、hevc_vaapi 及其他客户端尚未实机验证。
已用官方 Mac 客户端在 RTX 3090(hevc_nvenc,含 4:4:4)实机验收;`hevc_vaapi` 配官方 Android 客户端也已实机验收
(Intel Alder Lake-P / iHD,2560×1440 全程硬件编码,客户端 58 fps 解码、约 10 ms 延迟);`libx265` 仍未经控制端验收。
HEVC 的访问单元按 RFC 7798 的图片边界切分,不依赖 AUD:`hevc_vaapi` 带 `-aud 1` 时只在 IRAP 处写 AUD,并把其余
画面从码流里丢掉,读取端按 AUD 切分就会把整个 GOP 当成一帧,再被 IRAP 门控全部拒绝——对外表现为连接停在
「正在传输画面」,而主机侧只有约 12 kbit/s。`UU_VIDEO_CODEC=h265` 可显式选中 H.265,便于对照排查。
### VAAPI 硬件编码(显式启用)
@@ -321,6 +366,12 @@ flowchart LR
VBR 使用控制端码率预设及 CQ 对应的最小 QP,无 B 帧、async depth=1,并保留现有 GOP/VFR 规则。
Intel 核显(UHD 770,iHD 驱动)已实机验收:默认的外部 FFmpeg 管线用官方 Mac 控制端测试了各档画质、帧率、缩放和重连,全程硬件编码、无回退,CPU 占用比 libx264 低约 40%。**AMD 显卡和 `--features inproc-av` 管线的 VAAPI 尚未实机验证。**
高分辨率下 VAAPI 的默认 VBV 缓冲(100–500 kbit)会把关键帧压得过狠:2560×1440 H.264 VAAPI、30M
上限、静止画面上实测首个 IDR 只有 59,910 字节,画面每隔一个 GOP 糊一下再慢慢恢复。设
`UU_VAAPI_BUFFER_MS=250`(按 `码率上限 × 毫秒 / 1000` 放大 VBV)后首个 IDR 为 142,397 字节,
最低帧 Y-SSIM 从 0.9492 升到 0.9933,平均码率没有上升。默认不启用,未设置或超出 10–1000 ms
仍用原缓冲;代价是关键帧变大,弱网下可能出现瞬时排队,建议从 250 ms 试起。
### 静音运行与虚拟声卡
控制端开启「静音运行」后,程序创建虚拟输出 `uu-remote-sink`,保存原默认输出,
@@ -349,7 +400,8 @@ cargo build --release --features wayland
Omarchy 使用 Hyprland:在其用户会话中运行,设置 `UU_DESKTOP_BACKEND=wayland`,保留
`WAYLAND_DISPLAY` 和 `XDG_RUNTIME_DIR`。其他合成器可能需要 `--features wayland,portal`。
uinput 需加载内核模块(开机自动加载:`echo uinput | sudo tee /etc/modules-load.d/uinput.conf`)并应用上文 uaccess 规则;无人登录账号需要专用组的受限授权。
uinput 需加载内核模块(开机自动加载:`echo uinput | sudo tee /etc/modules-load.d/uinput.conf`)并应用上文 uaccess 规则;无人登录账号需要专用组的受限授权,
例如 `/etc/tmpfiles.d/uinput.conf` 写入 `z /dev/uinput 0660 root uinput`,再 `sudo usermod -aG uinput <用户>`(只加专用账号)。
该权限能向整个 seat(包括锁屏/登录界面)注入输入。设置 `UU_INPUT_BACKEND=uinput` 后,
仍须确认启动日志实际选择了 uinput。
@@ -370,6 +422,10 @@ Environment=UU_DESKTOP_BACKEND=wayland
WantedBy=graphical-session.target
```
单元名请保持 `uuremote-native.service`,不要写成模板单元 `[email protected]`:桌面图标和 `uuremote-server show`
固定启动这个名字(`UU_SERVICE_UNIT` 可覆盖),systemd 不会把它解析到模板实例。niri 的 `niri --session` 同样会在就绪前导入
`WAYLAND_DISPLAY`,上面的写法也适用(#55)。
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`。
+44 -5
View File
@@ -50,7 +50,15 @@ fn main() {
}
None => println!("cargo:warning=gtk+-3.0 not found: building without the login window"),
}
if std::env::var_os("CARGO_FEATURE_PORTAL").is_some() {
let plugins = std::env::var_os("CARGO_FEATURE_ENGINE_PLUGINS").is_some();
if plugins && std::env::var_os("CARGO_FEATURE_PORTAL").is_some() {
// Runtime-loaded libuu-portal.so; skipped (with a warning) where libei >= 1.1 is unavailable.
for file in ["portal_engine.c", "portal_engine.h", "portal_eis.inc", "desktop_power.c"] { println!("cargo:rerun-if-changed=c_engine/{file}"); }
match pkg_config(&["gio-2.0", "gio-unix-2.0", "libpipewire-0.3", "libei-1.0 >= 1.1"]) {
Some((cflags, libs)) => shared_engine("libuu-portal.so", &["c_engine/portal_engine.c", "c_engine/desktop_power.c"], &[], &cflags, &libs),
None => println!("cargo:warning=GIO/PipeWire/libei >= 1.1 not found: libuu-portal.so not built"),
}
} else if std::env::var_os("CARGO_FEATURE_PORTAL").is_some() {
println!("cargo:rerun-if-changed=c_engine/portal_engine.c");
println!("cargo:rerun-if-changed=c_engine/portal_engine.h");
println!("cargo:rerun-if-changed=c_engine/portal_eis.inc");
@@ -76,6 +84,7 @@ fn main() {
let mut build = cc::Build::new();
build.flag_if_supported("-Wno-unused-parameter"); // protocol listener signatures
build.file("c_engine/wayland_engine.c").include(&out);
let mut sources = vec!["c_engine/wayland_engine.c".to_owned()];
for name in ["wlr-screencopy-unstable-v1", "wlr-virtual-pointer-unstable-v1", "virtual-keyboard-unstable-v1", "wlr-output-power-management-unstable-v1", "linux-dmabuf-unstable-v1"] {
let xml = format!("c_engine/wayland-protocols/{name}.xml");
println!("cargo:rerun-if-changed={xml}");
@@ -84,13 +93,43 @@ fn main() {
let status = std::process::Command::new("wayland-scanner").args([mode, &xml]).arg(&target).status()
.expect("Install wayland-scanner to build the Wayland backend");
assert!(status.success(), "wayland-scanner failed");
if mode == "private-code" { build.file(target); }
if mode == "private-code" { sources.push(target.to_string_lossy().into_owned()); build.file(target); }
}
}
println!("cargo:rerun-if-changed=c_engine/wayland_engine.c");
build.compile("uu_wayland_engine");
println!("cargo:rustc-link-lib=wayland-client");
println!("cargo:rustc-link-lib=xkbcommon");
if plugins {
let sources: Vec<&str> = sources.iter().map(String::as_str).collect();
match pkg_config(&["wayland-client", "xkbcommon"]) {
Some((cflags, libs)) => shared_engine("libuu-wayland.so", &sources, &[out.as_path()], &cflags, &libs),
None => println!("cargo:warning=wayland-client/xkbcommon not found: libuu-wayland.so not built"),
}
} else {
build.compile("uu_wayland_engine");
println!("cargo:rustc-link-lib=wayland-client");
println!("cargo:rustc-link-lib=xkbcommon");
}
}
}
}
/// `pkg-config --cflags` / `--libs` for `packages`, or None when any is missing.
fn pkg_config(packages: &[&str]) -> Option<(String, String)> {
let run = |kind: &str| std::process::Command::new("pkg-config").arg(kind).args(packages).output().ok()
.filter(|o| o.status.success()).map(|o| String::from_utf8_lossy(&o.stdout).into_owned());
run("--cflags").zip(run("--libs"))
}
/// Builds an engine as a shared library for engine-plugins and places it next to the binaries
/// (target/<profile>/), where the release workflow packages it. Not linked into uuremote-server.
fn shared_engine(name: &str, sources: &[&str], includes: &[&std::path::Path], cflags: &str, libs: &str) {
let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let library = out.join(name);
let mut command = cc::Build::new().pic(true).opt_level(2).get_compiler().to_command();
command.args(["-shared", "-fPIC", "-Wno-unused-parameter", "-Wl,-z,defs"]).arg(format!("-Wl,-soname,{name}")).arg("-o").arg(&library);
for include in includes { command.arg("-I").arg(include); }
command.args(cflags.split_whitespace()).args(sources).args(libs.split_whitespace()).arg("-lpthread");
let status = command.status().expect("C compiler for the engine plugin");
assert!(status.success(), "building {name} failed");
// OUT_DIR = target/<profile>/build/<package>-<hash>/out
if let Some(profile) = out.ancestors().nth(3) { std::fs::copy(&library, profile.join(name)).expect("copy engine plugin"); }
}
+1
View File
@@ -474,6 +474,7 @@ static gboolean show_window(gpointer d) {
static void *ui_thread(void *d) {
(void)d;
if (!gtk_init_check(NULL, NULL)) { pthread_mutex_lock(&init_lock); init_state = -1; pthread_cond_signal(&init_cond); pthread_mutex_unlock(&init_lock); return NULL; }
gtk_window_set_default_icon_name("uu-remote-linux"); // same taskbar icon as the host (#13)
// Light palette in CSS; keep a dark system theme from making unstyled text white on white (#43).
g_object_set(gtk_settings_get_default(), "gtk-theme-name", "Adwaita", "gtk-application-prefer-dark-theme", FALSE, NULL);
show_window(NULL); gtk_main(); return NULL;
+1
View File
@@ -590,6 +590,7 @@ static gboolean on_delete(GtkWidget *w, GdkEvent *e, gpointer d) { (void)w; (voi
static void *run(void *arg) {
(void)arg;
int ok = gtk_init_check(NULL, NULL);
if (ok) { gtk_window_set_default_icon_name("uu-remote-linux"); } // same taskbar icon as the host (#13)
// The CSS hard-codes a light palette; a dark system theme would turn unstyled text white on white (#43).
if (ok) g_object_set(gtk_settings_get_default(), "gtk-theme-name", "Adwaita", "gtk-application-prefer-dark-theme", FALSE, NULL);
if (ok) {
+202 -8
View File
@@ -58,6 +58,14 @@ static struct xkb_context *xkb;
static struct xkb_keymap *keymap;
static struct xkb_state *key_state;
static unsigned char held_keys[768];
/* Mobile input-method text (#13/#46). The protocol has no per-key remap request, but
zwp_virtual_keyboard_v1_keymap may be re-sent at any time, so the pristine keymap text is kept
and a spare keycode is pointed at one character's keysym at a time. Never logs the text. */
#define UU_TEXT_SPARE 32
static char *keymap_text;
static size_t keymap_text_len, keymap_insert;
static xkb_keycode_t spare_codes[UU_TEXT_SPARE];
static unsigned spare_count;
struct output { struct wl_output *handle; char name[128]; int transform,scale; uint32_t width,height; };
static struct output outputs[32];
static unsigned output_count, selected;
@@ -116,6 +124,164 @@ static int sync_display(void) {
if (!ready) wl_callback_destroy(cb);
return result;
}
/* Hand a keymap to the virtual keyboard. The compositor dups the fd, so it is closed here. */
static int upload_keymap(const char *text,size_t length) {
int fd=memfd_create("uuremote-keymap",MFD_CLOEXEC);
if(fd<0) return -1;
if(ftruncate(fd,(off_t)length)!=0 || write(fd,text,length)!=(ssize_t)length) { close(fd); return -1; }
zwp_virtual_keyboard_v1_keymap(keyboard,WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,fd,(uint32_t)length);
close(fd);
return 0;
}
/* A keymap uploaded to a keyboard the seat already has is never handed to the focused client again,
so pressing the remapped keycodes would still be translated with the keymap it has - which is how
every message came out as the one before it. Re-attaching the keyboard is what makes the
compositor send the keymap to the client (measured 2026-10-18 on Hyprland 0.56.2). */
static int rekey_keyboard(void) {
if(!keyboard_manager || !seat) return -1;
if(keyboard) zwp_virtual_keyboard_v1_destroy(keyboard);
keyboard=zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(keyboard_manager,seat);
return keyboard?0:-1;
}
/* Offset of the '}' that closes the xkb_symbols section, so extra keys can be declared there.
Pairing the braces is enough because the bodies are balanced; looking for the last "};" is not,
the keymap's own brace follows, and an optional xkb_geometry section may too. */
static size_t symbols_close(const char *text) {
const char *section=strstr(text,"xkb_symbols");
if(!section) return 0;
const char *open=strchr(section,'{');
if(!open) return 0;
int depth=0;
for(const char *p=open;*p;p++) {
if(*p=='{') depth++;
else if(*p=='}' && --depth==0) return (size_t)(p-text);
}
return 0;
}
/* Named keycodes the keymap gives no symbol to. Reading the compositor's own list is the only
portable way: pressing an unmapped keycode types nothing, and uu_wl_key never matches one
because it searches by keysym. Highest first, since uu_wl_key takes the lowest match. */
static unsigned find_spare_codes(xkb_keycode_t *out,unsigned limit) {
unsigned count=0;
xkb_keycode_t min=xkb_keymap_min_keycode(keymap);
for(xkb_keycode_t code=xkb_keymap_max_keycode(keymap);code>min && count<limit;code--) {
if(code<8 || code>=sizeof(held_keys) || !xkb_keymap_key_get_name(keymap,code)) continue;
int mapped=0;
for(xkb_level_index_t level=0;level<xkb_keymap_num_levels_for_key(keymap,code,0) && !mapped;level++) {
const xkb_keysym_t *syms;
if(xkb_keymap_key_get_syms_by_level(keymap,code,0,level,&syms)>0) mapped=1;
}
if(!mapped) out[count++]=code;
}
return count;
}
/* A keycode the session keymap already produces this symbol with, unshifted. Typing through it
needs no upload, so no client can mistranslate it - and it is how plain latin text and spaces
arrive without touching the keymap at all. Spares never match: the pristine keymap leaves them
unmapped. */
static xkb_keycode_t existing_keycode(xkb_keysym_t symbol) {
for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) {
if(code<8 || code>=sizeof(held_keys)) continue;
const xkb_keysym_t *syms;
if(xkb_keymap_key_get_syms_by_level(keymap,code,0,0,&syms)==1 && syms[0]==symbol) return code;
}
return 0;
}
static void press_keycode(xkb_keycode_t code) {
zwp_virtual_keyboard_v1_key(keyboard,timestamp(),code-8,WL_KEYBOARD_KEY_STATE_PRESSED);
zwp_virtual_keyboard_v1_key(keyboard,timestamp(),code-8,WL_KEYBOARD_KEY_STATE_RELEASED);
held_keys[code]=0;
}
/* The replaced keyboard starts with nothing held, and a keycode held_keys still calls held would be
skipped by uu_wl_key's next press of it. */
static void release_held_keys_locked(void) {
for(xkb_keycode_t code=xkb_keymap_min_keycode(keymap);code<=xkb_keymap_max_keycode(keymap);code++) {
if(code<8 || code>=sizeof(held_keys) || !held_keys[code]) continue;
zwp_virtual_keyboard_v1_key(keyboard,timestamp(),code-8,WL_KEYBOARD_KEY_STATE_RELEASED);
xkb_state_update_key(key_state,code,XKB_KEY_UP);
}
memset(held_keys,0,sizeof(held_keys));
}
/* Upload one batch: re-attach the keyboard so the client takes the keymap, point spare keycodes at
these symbols, wait for the compositor to install it, then press them. Spares are left out of
key_state and held_keys: pressed and released here. */
static int flush_batch(char *buffer,size_t capacity,const char names[][64],const xkb_keycode_t *codes,unsigned count,int *typed) {
release_held_keys_locked();
if(rekey_keyboard()!=0) return -1;
size_t at=keymap_insert;
memcpy(buffer,keymap_text,at);
for(unsigned i=0;i<count;i++) {
int wrote=snprintf(buffer+at,capacity-at,"\tkey <%s> { [ %s ] };\n",xkb_keymap_key_get_name(keymap,codes[i]),names[i]);
if(wrote<0 || (size_t)wrote>=capacity-at) return -1;
at+=(size_t)wrote;
}
memcpy(buffer+at,keymap_text+keymap_insert,keymap_text_len-keymap_insert);
if(upload_keymap(buffer,at+(keymap_text_len-keymap_insert))!=0) return -1;
if(sync_display()!=0) return -1;
for(unsigned i=0;i<count;i++) { press_keycode(codes[i]); (*typed)++; }
return 0;
}
/* Type UTF-8 like xdotool type does on X11, but on Wayland: characters the session keymap already
has go out as ordinary keycodes, the rest share the spares of one keymap upload (~70 KB, so one
batch per upload), in text order. Never logs the text. */
static int type_utf8_locked(const char *text) {
size_t capacity=keymap_text_len+(size_t)UU_TEXT_SPARE*96+64;
char *buffer=malloc(capacity);
if(!buffer) return -1;
char names[UU_TEXT_SPARE][64];
xkb_keycode_t codes[UU_TEXT_SPARE];
unsigned count=0;
int typed=0, failed=0;
const unsigned char *p=(const unsigned char *)text;
while(*p && !failed) {
unsigned cp=0; int n=0;
if(*p<0x80) { cp=*p; n=1; }
else if((*p&0xE0)==0xC0 && (p[1]&0xC0)==0x80) { cp=((p[0]&0x1F)<<6)|(p[1]&0x3F); n=2; }
else if((*p&0xF0)==0xE0 && (p[1]&0xC0)==0x80 && (p[2]&0xC0)==0x80) { cp=((p[0]&0x0F)<<12)|((p[1]&0x3F)<<6)|(p[2]&0x3F); n=3; }
else if((*p&0xF8)==0xF0 && (p[1]&0xC0)==0x80 && (p[2]&0xC0)==0x80 && (p[3]&0xC0)==0x80) { cp=((p[0]&0x07)<<18)|((p[1]&0x3F)<<12)|((p[2]&0x3F)<<6)|(p[3]&0x3F); n=4; }
else { p++; continue; }
p+=n;
xkb_keysym_t sym;
if(cp=='\n') sym=0xff0d; /* Return */
else if(cp=='\t') sym=0xff09; /* Tab */
else if(cp<0x20 || cp==0x7f || (cp>=0x80 && cp<0xa0)) continue; /* controls carry no text */
else if(cp<0x100) sym=cp; /* Latin-1 keysyms equal the code point */
else sym=(xkb_keysym_t)(0x1000000|cp); /* Unicode keysym */
xkb_keycode_t existing=existing_keycode(sym);
if(existing) {
if(count && flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
count=0;
press_keycode(existing); typed++;
continue;
}
if(count==UU_TEXT_SPARE) {
if(flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
count=0;
}
/* The name is what the keymap parser reads back; an unnamed keysym cannot be spelled. */
if(xkb_keysym_get_name(sym,names[count],sizeof(names[count]))<=0) continue;
codes[count]=spare_codes[count];
count++;
}
if(!failed && count) failed=flush_batch(buffer,capacity,names,codes,count,&typed)!=0;
free(buffer);
/* Restore the pristine keymap whatever happened above, so uu_wl_key keeps its own symbol map. */
if(upload_keymap(keymap_text,keymap_text_len)!=0) return -1;
return failed && !typed?-1:typed;
}
int uu_wl_type_utf8(const char *text) {
pthread_mutex_lock(&lock);
int typed=-1;
if(initialized && text && keymap_text && keymap_insert && spare_count) typed=type_utf8_locked(text);
if(typed>=0 && wl_display_flush(display)<0) typed=-1;
pthread_mutex_unlock(&lock); return typed;
}
/* Diagnostic: how many characters one keymap upload can carry, 0 when this keymap has no spare. */
int uu_wl_text_ready(void) {
pthread_mutex_lock(&lock);
int ready=initialized && keymap_text && keymap_insert ? (int)spare_count : 0;
pthread_mutex_unlock(&lock); return ready;
}
static void output_geometry(void*d,struct wl_output*o,int32_t x,int32_t y,int32_t w,int32_t h,int32_t sub,const char*m,const char*model,int32_t transform) { ((struct output*)d)->transform=transform; }
static void output_mode(void*d,struct wl_output*o,uint32_t f,int32_t w,int32_t h,int32_t rate) {
if(f&WL_OUTPUT_MODE_CURRENT) { ((struct output*)d)->width=w; ((struct output*)d)->height=h; }
@@ -357,6 +523,7 @@ static void reset(void) {
dmabuf=NULL; dmabuf_requested=dmabuf_disabled=dmabuf_reported=0; dmabuf_linear_formats=0;
pending=0; output_count=0; initialized=0; memset(outputs,0,sizeof(outputs));
memset(held_keys,0,sizeof(held_keys));
free(keymap_text); keymap_text=NULL; keymap_text_len=keymap_insert=0; spare_count=0;
}
int uu_wl_init(int32_t *w,int32_t *h) {
pthread_mutex_lock(&lock);
@@ -390,20 +557,47 @@ int uu_wl_init(int32_t *w,int32_t *h) {
keymap=xkb_keymap_new_from_names(xkb,&names,XKB_KEYMAP_COMPILE_NO_FLAGS);
if(!keymap) goto end;
key_state=xkb_state_new(keymap); if(!key_state) goto end;
char *map=xkb_keymap_get_as_string(keymap,XKB_KEYMAP_FORMAT_TEXT_V1);
if(!map) goto end;
size_t length=strlen(map)+1;
int fd=memfd_create("uuremote-keymap",MFD_CLOEXEC);
if(fd<0) { free(map); goto end; }
if(ftruncate(fd,(off_t)length)!=0 || write(fd,map,length)!=(ssize_t)length) { free(map); close(fd); goto end; }
free(map);
zwp_virtual_keyboard_v1_keymap(keyboard,WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,fd,length); close(fd);
keymap_text=xkb_keymap_get_as_string(keymap,XKB_KEYMAP_FORMAT_TEXT_V1);
if(!keymap_text) goto end;
keymap_text_len=strlen(keymap_text)+1;
if(upload_keymap(keymap_text,keymap_text_len)!=0) goto end;
if(sync_display()!=0) goto end;
/* Text typing needs unmapped keycodes and a place to declare them. A keymap without either
only costs that path - uu_wl_type_utf8 refuses and the caller keeps its own fallback. */
keymap_insert=symbols_close(keymap_text);
spare_count=find_spare_codes(spare_codes,sizeof(spare_codes)/sizeof(spare_codes[0]));
initialized=1; *w=width; *h=height; result=0;
end:
if(result!=0) reset();
pthread_mutex_unlock(&lock); return result;
}
/* Switch the pointer binding and main-process capture atomically; encoder subprocesses
select their own output via UU_WAYLAND_OUTPUT. Keyboard identity stays unchanged. */
int uu_wl_select_output(const char *name,uint32_t expected_w,uint32_t expected_h) {
pthread_mutex_lock(&lock); int result=-1;
if(!initialized || !name || sync_display()!=0) goto end;
unsigned target;
for(target=0;target<output_count;target++) if(!strcmp(outputs[target].name,name)) break;
if(target==output_count || outputs[target].transform!=WL_OUTPUT_TRANSFORM_NORMAL) goto end;
uint32_t w=outputs[target].width,h=outputs[target].height;
if(w!=expected_w || h!=expected_h || !w || !h || w>16384 || h>16384 || (uint64_t)w*h*4>256*1024*1024) goto end;
struct zwlr_virtual_pointer_v1 *next=zwlr_virtual_pointer_manager_v1_create_virtual_pointer_with_output(pointer_manager,seat,outputs[target].handle);
if(!next) goto end;
if(sync_display()!=0) {zwlr_virtual_pointer_v1_destroy(next);goto end;}
for(unsigned i=0;i<2;i++) { frame_clear(&frames[i]); dma_clear(&frames[i]); shm_clear(&frames[i]); }
pending=0;
if(pointer) zwlr_virtual_pointer_v1_destroy(pointer);
pointer=next; selected=target; width=w; height=h;
if(power) { zwlr_output_power_v1_destroy(power); power=NULL; }
power_failed=0;
if(power_manager) {
power=zwlr_output_power_manager_v1_get_output_power(power_manager,outputs[selected].handle);
zwlr_output_power_v1_add_listener(power,&power_listener,NULL);
}
result=0;
end:
pthread_mutex_unlock(&lock); return result;
}
int uu_wl_wake(void) {
pthread_mutex_lock(&lock); int result=-1;
/* Output power management is optional; missing it must not block screencopy. */
@@ -0,0 +1,14 @@
[Desktop Entry]
Type=Application
Name=UU 远程 Linux 控制端
Name[en]=UU Remote Linux Viewer
GenericName=Remote desktop viewer
Comment=非官方 UU 远程控制端(实验性):远控你的 Windows / Mac / Linux 设备
Comment[en]=Unofficial NetEase UU Remote viewer (experimental)
Exec=uuremote-viewer ui
Icon=uu-remote-linux
Terminal=false
Categories=Network;RemoteAccess;
Keywords=remote;desktop;viewer;UU;远程;控制;
StartupNotify=false
StartupWMClass=uuremote-viewer
+2
View File
@@ -11,3 +11,5 @@ Terminal=false
Categories=Network;RemoteAccess;
Keywords=remote;assist;UU;远程;协助;
StartupNotify=false
# Matches the GTK window class so docks/taskbars show this icon for the host window (#13).
StartupWMClass=uu-remote-linux
+1 -1
View File
@@ -1,7 +1,7 @@
# Unofficial UU Remote Linux host in a container, for NAS boxes (Synology DSM, etc.) without a desktop.
# Headless mode: file transfer, terminal and port mapping; no remote desktop. Uses the published release binary.
FROM ubuntu:24.04
ARG VERSION=v0.2.8
ARG VERSION=v0.2.15
LABEL org.opencontainers.image.source="https://github.com/VallierDev/uu-remote-linux" \
org.opencontainers.image.description="Unofficial UU Remote Linux host, headless (file transfer, terminal, port mapping)" \
org.opencontainers.image.licenses="GPL-3.0"
+6 -60
View File
@@ -1,63 +1,9 @@
# 群晖 / NAS 容器部署(无桌面)
# Docker(群晖 / NAS,无桌面)
**简体中文** | [English](#english)
本目录是 [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux) 镜像的构建文件。
**部署和使用步骤见 [docs/deploy-nas-docker.md](../docs/deploy-nas-docker.md)。**
在没有桌面的 NAS(群晖 DSM 等,x86_64)上,用容器运行本项目主机,供官方 UU 远程客户端使用:
This directory builds the `ghcr.io/vallierdev/uu-remote-linux` image; see
[docs/deploy-nas-docker.md](../docs/deploy-nas-docker.md#english) for deployment.
- **文件传输**:收发 `/data` 里的文件(把你的共享文件夹挂到 `/data`)。
- **终端**:进入容器内的 bash,当前目录为 `/data`。
- **端口映射**:在外网经 UU 访问家里局域网的服务(NAS 管理页、路由器、其他电脑……)。
不提供远程桌面(NAS 没有图形界面)。容器里运行的是 GitHub 发布包中的同一个 `uuremote-server`。
## 安装
在 NAS 上(SSH 登录后用 root 或 `sudo`),进入本目录:
```sh
mkdir -p config data && chmod 700 config
docker compose build # 或者直接使用 ghcr.io/vallierdev/uu-remote-linux 镜像
```
**首次登录**(只需一次):在你自己的终端里运行,用手机 UU 远程扫描终端里显示的二维码并确认。
二维码等同于登录凭据,不要截图或发给别人。
```sh
docker compose run --rm uu-remote login --no-gui
```
登录信息保存在 `config/config.json`(权限 0600),请妥善保管 `config` 目录。然后启动:
```sh
docker compose up -d
docker compose logs -f # 看到 availability=Some("ready") 即可在客户端设备列表里找到它
```
**群晖 Container Manager**:也可以在「项目」里新建项目,选本目录的 `compose.yaml`;首次登录仍需在 SSH 里执行上面的 `login` 命令。
## 说明
- `network_mode: host` 让 WebRTC 走直连;改用默认桥接网络也能用,但更常走中转,延迟更高。
- 把 `compose.yaml` 里的 `./data` 改成要开放的共享文件夹,例如 `/volume1/homes/你的用户名`。只挂需要远程访问的目录。
- 终端操作的是容器而不是 NAS 系统本身;需要操作 NAS 本机时请用 DSM 自带的 SSH。
- 升级:重新 `docker compose build --pull`(或拉取新镜像)后 `docker compose up -d`;`config` 保留即可免再登录。
---
## English
Run this project's host in a container on a desktop-less NAS (Synology DSM, x86_64) for the official UU Remote clients:
file transfer (`/data`), terminal (bash inside the container) and port mapping into your LAN. No remote desktop.
```sh
mkdir -p config data && chmod 700 config
docker compose build
docker compose run --rm uu-remote login --no-gui # scan the terminal QR with the UU mobile app (the QR is a credential)
docker compose up -d
docker compose logs -f # wait for availability=Some("ready")
```
Credentials are kept in `config/config.json`. Mount only the folders you want to reach as `/data`.
Host networking gives WebRTC direct paths; bridge networking works but relays more often.
**Unofficial project, not affiliated with NetEase.**
自行构建 / build locally: `docker compose build`(`Dockerfile` 从 GitHub 发布包安装 `uuremote-server`,可用 `--build-arg VERSION=vX.Y.Z` 指定版本)。
+133
View File
@@ -0,0 +1,133 @@
# 群晖 / NAS 部署指南(Docker,无桌面)
**简体中文** | [English](#english)
镜像:[`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux)
(标签 `latest` 或具体版本如 `v0.2.8`)
把本项目主机跑在没有桌面的 NAS 上之后,就能在外面用官方 UU 远程客户端(手机 / Mac / Windows):
| 功能 | 说明 |
|---|---|
| 文件传输 | 收发 NAS 上的文件(只开放你挂进容器的文件夹) |
| 终端 | 打开容器里的命令行(bash) |
| 端口映射 | 经 UU 访问家里局域网的服务:NAS 管理页、路由器、其他电脑的 SSH / 远程桌面等 |
**不提供远程桌面**(NAS 没有图形界面,点「远程桌面」会一直显示正在连接,属正常)。
## 准备
- x86_64 的 NAS(群晖 DSM 7.2 及以上已安装「Container Manager」,或任意装了 Docker 的 Linux NAS)。ARM 机型暂不支持。
- 能 SSH 登录 NAS(群晖:控制面板 → 终端机和 SNMP → 启用 SSH),并有管理员权限(`sudo`)。
- 手机上的 UU 远程 App,用于扫码登录。
## 第一步:建目录和配置
SSH 登录 NAS,新建一个目录(下面以 `/volume1/docker/uu-remote` 为例):
```sh
sudo mkdir -p /volume1/docker/uu-remote/config
sudo chmod 700 /volume1/docker/uu-remote/config
cd /volume1/docker/uu-remote
```
新建 `compose.yaml`,内容如下。把 `/volume1/共享文件夹` 改成你想远程访问的文件夹(可以写多行挂多个):
```yaml
services:
uu-remote:
image: ghcr.io/vallierdev/uu-remote-linux:latest
container_name: uu-remote
network_mode: host # 让远程连接尽量走直连,速度更快
restart: unless-stopped
volumes:
- ./config:/config # 登录信息,请勿外传
- /volume1/共享文件夹:/data # 文件传输和终端看到的目录
```
## 第二步:扫码登录(只需一次)
```sh
sudo docker compose pull
sudo docker compose run --rm uu-remote login --no-gui
```
终端里会显示一个二维码:用手机 UU 远程扫码并确认。看到登录成功的提示后,按 `Ctrl+C` 退出(如果没有自动退出)。
> 二维码等同于你的登录凭据,**不要截图或发给别人**。登录信息保存在 `config/config.json`。
> 一定要用上面的 `docker compose run`(主机网络),这样设备在列表里显示的是 NAS 的名字;
> 若用普通 `docker run` 登录,设备名会是一串随机字符。
## 第三步:启动
```sh
sudo docker compose up -d
sudo docker compose logs -f
```
日志里出现 `availability=Some("ready")` 就说明上线了,按 `Ctrl+C` 退出日志查看(容器继续在后台运行)。
之后 NAS 开机会自动启动它。
**用群晖界面管理**:Container Manager → 项目 → 新增,路径选 `/volume1/docker/uu-remote`,会自动读取 `compose.yaml`。
首次登录仍需在 SSH 里执行第二步。
## 使用
打开官方 UU 远程客户端,在「我的设备」里找到你的 NAS(显示为 Windows 设备,这是正常的):
- **文件传输**:浏览、上传、下载 `/data` 里的文件。
- **终端**:进入容器的命令行,当前目录是 `/data`。注意这是容器而不是 NAS 系统本身。
- **端口映射**:例如目标填 `127.0.0.1`、端口 `5000`,就能在本地浏览器打开 NAS 的 DSM 管理页;
填局域网里其他设备的地址和端口(如 `192.168.1.10:22`)即可访问那台设备的服务。
## 更新
```sh
cd /volume1/docker/uu-remote
sudo docker compose pull && sudo docker compose up -d
```
`config` 目录保留即可,不用重新登录。
## 停用与移除
```sh
sudo docker compose down # 停止并删除容器
```
再在官方客户端的设备列表里删除这台设备;如需彻底清除登录信息,删除 `config` 目录。
## 常见问题
- **设备名是一串随机字符**:登录时没有用主机网络。删除 `config/config.json`,按第二步用 `docker compose run` 重新登录。
- **一直不上线**:`sudo docker compose logs --tail 100` 查看日志;确认 NAS 能访问外网。
- **连接慢、经常卡**:确认 `network_mode: host` 没有被去掉。
- **想要远程桌面**:NAS 上不支持;请在有桌面的 Linux 电脑上安装主机端(见主 README)。
安全提示:只挂需要远程访问的文件夹;端口映射可以访问 NAS 所在局域网,请保管好 UU 账号。
---
## English
Image: [`ghcr.io/vallierdev/uu-remote-linux`](https://github.com/VallierDev/uu-remote-linux/pkgs/container/uu-remote-linux)
Runs this project's host headless on a desktop-less NAS (x86_64, e.g. Synology DSM 7.2+ with Container Manager) for the
official UU Remote clients: **file transfer** (folders you mount at `/data`), **terminal** (bash inside the container) and
**port mapping** into your LAN. No remote desktop.
```sh
sudo mkdir -p /volume1/docker/uu-remote/config && sudo chmod 700 /volume1/docker/uu-remote/config
cd /volume1/docker/uu-remote
# compose.yaml: image ghcr.io/vallierdev/uu-remote-linux:latest, network_mode: host,
# volumes ./config:/config and /volume1/your-share:/data (see the Chinese section above)
sudo docker compose pull
sudo docker compose run --rm uu-remote login --no-gui # scan the QR with the UU mobile app; the QR is a credential
sudo docker compose up -d
sudo docker compose logs -f # wait for availability=Some("ready")
```
Update with `docker compose pull && docker compose up -d` (keep `config/`). Remove with `docker compose down`, then delete
the device in the official client.
**Unofficial project, not affiliated with NetEase.**
+18
View File
@@ -0,0 +1,18 @@
修复 iPhone 上「超清 / 原画」「常规 / 真彩」点不动。/ Fix iPhone quality and chroma choices being locked.
### 修复 / Fixed
- **iPhone 无法切换画质与真彩**(#49,感谢 @RiverOnVenus 的细致排查):连接本项目主机时,iPhone 的「超清」「原画」
以及「常规 / 真彩」按钮点了没反应,只有帧率能改。原因是主机发出的设备能力消息(`forward_setting` 的 `device_capability`)
格式与官方 Windows 被控端不一致,iPhone 无法识别,于是锁定在默认值。现在按官方格式发送设备能力(含 4:4:4 等真实支持的格式),
并补发发送参数 `sender_para_info`。
已实测:iPhone(UU 远程 4.42.0)连接修复后的主机,可以切换画质(主机收到新的画质请求)。Mac 客户端不依赖这条消息,此前即正常。
- Device capability is now sent in the official nested shape (and `sender_para_info` is added), so the iPhone client unlocks
quality and chroma choices. Verified with the UU iPhone app 4.42.0.
### 其他 / Other
- 控制端窗口与主机使用同一图标,并新增控制端启动项 `contrib/desktop/uu-remote-linux-viewer.desktop`(#13)。
### 下载 / Download
`uu-remote-linux-v0.2.10-x86_64-linux.tar.gz`(主机 `uuremote-server` + 控制端 `uuremote-viewer`,附带 `contrib/`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.10`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+20
View File
@@ -0,0 +1,20 @@
Wayland(wlroots)手机输入法上屏;登录默认直连,不走环境代理。/ Mobile IME text on wlroots Wayland; cloud API ignores ambient proxies by default.
### 新增 / Added
- **wlroots Wayland 支持手机输入法 `text_input`**(#51,感谢 @hiclaw):手机端输入法提交的文字,
在 Hyprland / Sway 等 wlroots 合成器上通过虚拟键盘的备用键码上屏。仅在 Hyprland 0.56.2 上实测;
KWin / GNOME(门户后端)仍不支持,见 #50。
- Mobile IME `text_input` now types through the virtual keyboard's spare keycodes on wlroots compositors.
Tested on Hyprland 0.56.2 only; KWin/GNOME (portal backend) are not covered yet.
### 变更 / Changed
- **云端接口默认忽略代理环境变量**(#52,感谢 @aresbit):本地有拦截 TLS 的 HTTP/SOCKS 代理时,登录会报
`tls handshake eof`。现在主机和控制端访问网易服务器默认直连,忽略 `http_proxy` / `https_proxy` / `all_proxy`;
确实需要经代理上网的环境请设置 `UU_USE_PROXY=1`。未在拦截代理环境中实机验证,CI 测试通过。
- Cloud API clients now bypass `http_proxy` / `https_proxy` / `all_proxy` by default; set `UU_USE_PROXY=1` if your
network requires a proxy. Not verified against an intercepting proxy; CI passes.
### 下载 / Download
`uu-remote-linux-v0.2.11-x86_64-linux.tar.gz`(主机 `uuremote-server` + 控制端 `uuremote-viewer`,附带 `contrib/`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.11`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+15
View File
@@ -0,0 +1,15 @@
修复缩放桌面尺寸为奇数时画面一直「正在传输」。/ Fix the stream never starting when the captured desktop has an odd size.
### 修复 / Fixed
- **奇数尺寸桌面无法出画面**(#53,感谢 @wen0531):KDE Plasma(Wayland,门户后端)150% 缩放、两块屏上下排列时,
逻辑桌面为 2560x2507,H.264/HEVC 编码器要求偶数宽高,全部启动失败,客户端一直停在「正在传输画面」。
现在原生分辨率采集遇到奇数宽高时,在右/下补齐 1 像素黑边再编码;偶数尺寸、「其他分辨率」缩放不受影响。
贡献者已在 KDE Plasma 6.7 / Wayland / NVENC + 官方安卓客户端上实测。进程内编码(`inproc-av`)路径未覆盖。
- When the native capture size is odd (e.g. scaled stacked monitors), the encoder input is padded by one black
row/column so every H.264/HEVC encoder can open. Verified by the contributor on KDE Plasma 6.7 (Wayland, NVENC).
The optional `inproc-av` path is not covered.
### 下载 / Download
`uu-remote-linux-v0.2.12-x86_64-linux.tar.gz`(主机 `uuremote-server` + 控制端 `uuremote-viewer`,附带 `contrib/`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.12`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+25
View File
@@ -0,0 +1,25 @@
一个包支持所有桌面:Wayland 和 GNOME/KDE 不再需要源码编译。/ One package for every desktop: no source build needed for Wayland or GNOME/KDE.
### 新增 / Added
- **预编译包内置 Wayland 与 GNOME/KDE 支持**(#43、#54):Release 包新增 `libuu-wayland.so`(Hyprland / Sway / niri 等 wlroots)
和 `libuu-portal.so`(GNOME / KDE Wayland)。程序按当前会话自动选择后端,只在 Wayland 会话里加载对应插件,X11 用户不需要任何
Wayland 库。安装:
```sh
install -Dm755 uuremote-server ~/.local/bin/uuremote-server
install -Dm644 libuu-wayland.so libuu-portal.so -t ~/.local/lib/uu-remote-linux/
```
系统要求:X11 与 wlroots 为 glibc ≥ 2.35;GNOME/KDE 插件为 glibc ≥ 2.39(Ubuntu 24.04、Fedora 40、Debian 13 及更新)及 libei ≥ 1.1。
缺库或版本过旧时日志会写明原因。**验证范围**:插件加载、回退与报错在 Hyprland 虚拟机(ARM)实测,wlroots 采集正常;
预编译的 GNOME/KDE 插件尚未在真机上完成画面/键鼠验收(引擎代码本身未改动)。Wayland 仍为实验性。
- The release now ships `libuu-wayland.so` and `libuu-portal.so`, loaded at runtime only on Wayland sessions; X11 hosts need no
Wayland libraries. The portal plugin requires glibc >= 2.39 and libei >= 1.1. Plugin loading was tested on a Hyprland VM;
the prebuilt GNOME/KDE plugin has not yet been accepted on real hardware.
### 改进 / Improved
- 在 GNOME/KDE Wayland 上缺少 portal 支持时,不再反复报看不懂的 `portal unavailable (code 2)`,而是直接说明原因和解决办法(#43)。
- README:支持表加入 niri(实验性,协议已按源码确认、未实机验收);systemd 单元名须为 `uuremote-native.service`;uinput 无人值守授权示例(#55)。
### 下载 / Download
`uu-remote-linux-v0.2.13-x86_64-linux.tar.gz`(`uuremote-server`、`uuremote-viewer`、`libuu-wayland.so`、`libuu-portal.so`、`contrib/`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.13`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+20
View File
@@ -0,0 +1,20 @@
Hyprland 双屏点击偏移修复,并可在手机端切换显示器(实验性)。/ Hyprland dual-monitor pointer fix and opt-in monitor switching.
### 修复 / Fixed
- **Hyprland 双屏点击偏移**(#57,感谢 @JuanZoran):原生 Wayland 后端的绝对鼠标定位改为绑定正在采集的输出
(此前 uinput 绝对坐标映射到整个桌面,双屏时点击位置偏移)。uinput 仍用于键盘、按键和相对移动。
**影响所有 Hyprland 用户的默认路径**;单屏下映射结果与之前等价。贡献者已在双屏真机(2560×1440@125% + 1920×1080@133%)
上验证落点误差 ≤ 2 像素;维护者未另行复测。
- Absolute pointer motion on the native Wayland backend is now bound to the captured output (it previously spanned the whole
desktop through uinput, offsetting clicks on multi-monitor setups). Verified by the contributor on real dual-monitor hardware.
### 新增 / Added
- **Hyprland 多显示器切换(实验性,默认关闭)**:设置 `UU_WAYLAND_MULTISCREEN=1` 后,手机端可以选择物理显示器,画面与
鼠标定位同步切换;`UU_WAYLAND_OUTPUT` 指定默认屏幕。通过 `hyprctl` 枚举未旋转的显示器,插拔或布局变化后需重启服务;
切换失败会恢复原屏。由贡献者用官方手机客户端在 Omarchy / Hyprland 双屏上实测。
- Opt-in Hyprland monitor switching (`UU_WAYLAND_MULTISCREEN=1`), accepted by the contributor with the official phone client.
### 下载 / Download
`uu-remote-linux-v0.2.14-x86_64-linux.tar.gz`(含 `libuu-wayland.so` / `libuu-portal.so`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.14`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+18
View File
@@ -0,0 +1,18 @@
ARM64 预编译包;无硬件编码器时默认 H.264。/ aarch64 release package; CPU-only hosts default to H.264.
### 新增 / Added
- **aarch64 预编译包**(#59,感谢 @DeliciousBuding):新增 `uu-remote-linux-v0.2.15-aarch64-linux.tar.gz`,与 x86_64 包相同,
含 `uuremote-server`、`uuremote-viewer` 和两个桌面引擎插件;ARM64 主机不再需要源码编译。CI 新增 ARM64 原生构建与测试(#58)。
aarch64 包由 GitHub ARM runner 构建,尚未在真实 ARM 主机上运行验收。
- New aarch64 release package (same contents as x86_64), built on GitHub ARM runners; not yet run on real ARM hardware.
### 变更 / Changed
- **只有 CPU 编码时默认使用 H.264**(#59):libx265 比 libx264 慢约 10 倍(4 核 Ampere A1 上 1080p 约 15 帧对 155 帧),
原先 CPU 主机默认 H.265 会掉到十几帧。现在只有使用硬件编码器(NVENC / 显式 VAAPI)时才自动选 H.265;
`UU_VIDEO_CODEC=h265` 仍可强制 H.265。NVENC / VAAPI 主机行为不变。
- Without NVENC/VAAPI the host now picks H.264 even when both sides offer H.265; `UU_VIDEO_CODEC=h265` forces H.265.
### 下载 / Download
`uu-remote-linux-v0.2.15-x86_64-linux.tar.gz` / `uu-remote-linux-v0.2.15-aarch64-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.15`(x86_64)。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+19
View File
@@ -0,0 +1,19 @@
修复 H.265 + VAAPI 时手机卡在「正在传输」;VAAPI 可选加大编码缓冲。/ Fix H.265 + VAAPI stalling at "transferring"; optional VAAPI VBV buffer.
### 修复 / Fixed
- **H.265 用 VAAPI 硬件编码时没有画面**(#48,感谢 @NuoFang6):`hevc_vaapi` 只在关键帧处写帧分隔符,主机按分隔符切帧,
把整组画面当成一帧后全部被拦下,被控端几乎不发画面,手机停在「正在传输」。现在按图像边界切分 H.265 访问单元,
不再依赖帧分隔符;维护者补充了后缀 SEI 等尾随单元的处理。
已实测:作者在 Intel 核显 + 官方安卓客户端上(2560×1440,约 58 fps);维护者在 RTX 3090 上用固定输入探针验证
`hevc_nvenc` 与 `libx265` 均 90/90 帧可解码、首帧为关键帧。
- H.265 access units are now split on picture boundaries (RFC 7798), fixing hevc_vaapi sessions that sent almost nothing.
### 新增 / Added
- **`UU_VAAPI_BUFFER_MS`**(#47,感谢 @NuoFang6,源自 #42):可选加大 VAAPI 的编码缓冲(10–1000 ms),缓解高分辨率下
关键帧被压糊、画面周期性模糊。默认不启用。⚠️ 仅在一台机器上实测,代价是关键帧变大,建议从 250 ms 试起。
- Optional VAAPI VBV buffer `UU_VAAPI_BUFFER_MS` (off by default; verified on one machine only).
### 下载 / Download
`uu-remote-linux-v0.2.9-x86_64-linux.tar.gz`(主机 `uuremote-server` + 控制端 `uuremote-viewer`,附带 `contrib/`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.9`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+22 -1
View File
@@ -121,9 +121,24 @@ fn redact_urls(text: &str) -> String {
out
}
/// Cloud API clients ignore ambient HTTP/SOCKS proxy settings by default: a local
/// proxy that intercepts TLS breaks login and signaling. `UU_USE_PROXY=1` opts back
/// into reqwest's standard proxy environment handling.
pub fn http_client_builder() -> reqwest::ClientBuilder {
let builder = reqwest::Client::builder();
if std::env::var("UU_USE_PROXY").ok().as_deref().is_some_and(proxy_requested) {
builder
} else {
builder.no_proxy()
}
}
fn proxy_requested(value: &str) -> bool {
matches!(value.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on")
}
impl UUAuthClient {
pub fn new(creds: Credentials) -> Self {
let http = reqwest::Client::builder()
let http = http_client_builder()
.timeout(std::time::Duration::from_secs(12))
.build()
.unwrap();
@@ -346,4 +361,10 @@ mod guest_tests {
let text = super::redact_urls("proxy http://user:[email protected]:3128 failed for (https://api.example/p?token=abc)");
assert_eq!(text, "proxy http://proxy.example:3128 failed for (https://api.example/p)");
}
#[test]
fn proxy_opt_in_accepts_only_explicit_truthy_values() {
for value in ["1", "true", "TRUE", " yes ", "On"] { assert!(super::proxy_requested(value)); }
for value in ["", "0", "false", "no", "off", "2"] { assert!(!super::proxy_requested(value)); }
}
}
+58 -22
View File
@@ -27,21 +27,49 @@ pub fn h264_device_capability(
fps: i32,
codec_impl: i32,
) -> Value {
device_capability(client_id, ice_id, display_id, fps, codec_impl, false)
device_capability(client_id, ice_id, display_id, fps, codec_impl, false, false)
}
pub fn device_capability(client_id: &str, ice_id: &str, display_id: i32, fps: i32, codec_impl: i32, hevc: bool) -> Value {
let mut codecs = vec![json!({"video_codec": VIDEO_CODEC_H264, "chroma_sampling": 1,
"codec_impl": codec_impl, "bit_depth": 8})];
// Official VideoCodecCapability::SerializeJson uses the same fields for CodecType H265=2.
if hevc { codecs.push(json!({"video_codec": 2, "chroma_sampling": 1, "codec_impl": codec_impl, "bit_depth": 8})); }
/// Shape of the official Windows host's `forward_setting` (observed from a live 4.37 host):
/// `{client_id, data: {device_capability: {display_info, ice_id, video_codec_capability}, type}}`.
/// The payload sits under `data.device_capability` with `type` beside it. The earlier flat shape
/// (`type` at the top, fields directly in `data`) was not recognised by the iPhone client, which
/// then kept quality and chroma locked at their defaults (#49). Only 8-bit and the chroma formats
/// the encoder really produces are listed; the first entry carries the maximum size as officially.
pub fn device_capability(client_id: &str, ice_id: &str, display_id: i32, fps: i32, codec_impl: i32, hevc: bool, full_chroma: bool) -> Value {
let mut codecs = Vec::new();
for codec in [VIDEO_CODEC_H264].into_iter().chain(hevc.then_some(2)) {
for chroma in [1].into_iter().chain(full_chroma.then_some(3)) {
let (width, height) = if codecs.is_empty() { (3840, 2160) } else { (0, 0) };
codecs.push(json!({"video_codec": codec, "chroma_sampling": chroma, "codec_impl": codec_impl,
"bit_depth": 8, "width": width, "height": height}));
}
}
json!({
"client_id": client_id,
"type": "device_capability",
"data": {
"display_info": [{"id": display_id, "fps": fps, "type": 0, "hdr": 0}],
"video_codec_capability": codecs,
"ice_id": ice_id
"device_capability": {
"display_info": [{"id": display_id, "fps": fps, "type": 0, "hdr": -1}],
"video_codec_capability": codecs,
"ice_id": ice_id
},
"type": "device_capability"
}
})
}
/// Official `sender_para_info` (capture and encoder names; the Windows host sends "DXGI" /
/// "NVIDIA NVENC") for the single video track.
pub fn sender_para_info(client_id: &str, ice_id: &str, capture_impl: &str, encoder_impl: &str) -> Value {
json!({
"client_id": client_id,
"data": {
"sender_para_info": {
"capture_impl": capture_impl, "encoder_impl": encoder_impl, "ice_id": ice_id,
"sender_media_infos": [{"capture_impl": capture_impl, "encoder_impl": encoder_impl, "video_track_index": 0}],
"video_track_index": 0
},
"type": "sender_para_info"
}
})
}
@@ -51,12 +79,20 @@ mod tests {
use super::*;
#[test]
fn hevc_capability_uses_official_codec_enum_and_420_only() {
let payload = device_capability("client-example", "ice-example", 0, 60, 5, true);
assert_eq!(payload["data"]["video_codec_capability"], json!([
{"video_codec":1,"chroma_sampling":1,"codec_impl":5,"bit_depth":8},
{"video_codec":2,"chroma_sampling":1,"codec_impl":5,"bit_depth":8}]));
assert_eq!(device_capability("c", "i", 0, 60, 5, false)["data"]["video_codec_capability"].as_array().unwrap().len(), 1);
fn capability_uses_the_official_nested_shape_and_real_formats() {
let payload = device_capability("client-example", "ice-example", 0, 60, 5, true, true);
assert_eq!(payload["data"]["type"], "device_capability");
assert!(payload.get("type").is_none());
let caps = &payload["data"]["device_capability"]["video_codec_capability"];
assert_eq!(caps.as_array().unwrap().len(), 4);
assert_eq!(caps[0], json!({"video_codec":1,"chroma_sampling":1,"codec_impl":5,"bit_depth":8,"width":3840,"height":2160}));
assert_eq!(caps[3], json!({"video_codec":2,"chroma_sampling":3,"codec_impl":5,"bit_depth":8,"width":0,"height":0}));
assert_eq!(payload["data"]["device_capability"]["display_info"][0]["hdr"], -1);
let h264_420 = device_capability("c", "i", 0, 60, 5, false, false);
assert_eq!(h264_420["data"]["device_capability"]["video_codec_capability"].as_array().unwrap().len(), 1);
let sender = sender_para_info("c", "i", "X11", "NVIDIA NVENC");
assert_eq!(sender["data"]["type"], "sender_para_info");
assert_eq!(sender["data"]["sender_para_info"]["sender_media_infos"][0]["encoder_impl"], "NVIDIA NVENC");
}
#[test]
@@ -71,15 +107,15 @@ mod tests {
#[test]
fn device_capability_uses_object_data_and_string_ice_id() {
let payload = h264_device_capability("client-example", "ice-example", 11, 60, 0);
assert_eq!(payload["type"], "device_capability");
assert!(payload["data"].is_object());
assert_eq!(payload["data"]["ice_id"], "ice-example");
let display = &payload["data"]["display_info"][0];
let capability = &payload["data"]["device_capability"];
assert!(capability.is_object());
assert_eq!(capability["ice_id"], "ice-example");
let display = &capability["display_info"][0];
assert_eq!(display.as_object().unwrap().len(), 4);
assert_eq!(display["id"], 11);
assert_eq!(display["fps"], 60);
let codec = &payload["data"]["video_codec_capability"][0];
assert_eq!(codec.as_object().unwrap().len(), 4);
let codec = &capability["video_codec_capability"][0];
assert_eq!(codec.as_object().unwrap().len(), 6);
assert_eq!(codec["video_codec"], 1);
assert_eq!(codec["codec_impl"], 0);
assert_eq!(codec["bit_depth"], 8);
+70 -5
View File
@@ -40,6 +40,8 @@ impl VideoCodec {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct VideoSettings {
pub source_id: usize,
pub source_generation: u64,
pub fps: u32,
pub codec: VideoCodec,
pub quality: u64,
@@ -52,7 +54,7 @@ pub struct VideoSettings {
}
impl Default for VideoSettings {
fn default() -> Self { Self { codec: VideoCodec::H264, fps: 60, quality: QUALITY_AUTO, custom_mbps: 0, output: None, chroma: CHROMA_420 } }
fn default() -> Self { let (source_id,source_generation)=crate::wayland::selection(); Self { source_id,source_generation, codec: VideoCodec::H264, 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).
@@ -115,10 +117,16 @@ pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, na
}
/// Initial codec once the m-line is negotiated: H.265 when both sides support it (the Mac viewer
/// lists H265 first in its offer), unless UU_VIDEO_CODEC=h264.
/// lists H265 first in its offer) and a hardware encoder is selected. Software libx265 is about ten
/// times slower than libx264 (measured 15 vs 155 fps at 1080p on a 4-core ARM host, #59), so CPU
/// hosts default to H.264. UU_VIDEO_CODEC=h264 / h265 overrides.
pub fn preferred_codec(h264: bool, h265: bool) -> VideoCodec {
let forced_h264 = std::env::var("UU_VIDEO_CODEC").is_ok_and(|v| v.eq_ignore_ascii_case("h264"));
if h265 && !(forced_h264 && h264) { VideoCodec::H265 } else { VideoCodec::H264 }
let forced = std::env::var("UU_VIDEO_CODEC").ok().map(|v| v.to_ascii_lowercase());
pick_codec(h264, h265, forced.as_deref(), crate::video::Encoder::requested() != crate::video::Encoder::Cpu)
}
fn pick_codec(h264: bool, h265: bool, forced: Option<&str>, hardware: bool) -> VideoCodec {
let wants_h265 = match forced { Some("h264") => false, Some("h265" | "hevc") => true, _ => hardware };
if h265 && (wants_h265 || !h264) { VideoCodec::H265 } else { VideoCodec::H264 }
}
pub fn handle_rpc_with_codecs(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native: (u32, u32), h264: bool, h265: bool) -> Option<Vec<u8>> {
@@ -180,9 +188,37 @@ fn apply_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native:
Some(out)
}
/// CaptureSettingResponse.errors (Error fields 1 code / 2 message, rpc_main.proto).
pub fn rejected_request(data:&[u8],reason:&str)->Option<Vec<u8>> {
let outer=decode_wire(data).ok()?;
let rpc=decode_wire(message(&outer,21)?).ok()?;
message(&rpc,2)?;
let mut error=Vec::new();
put_varint(1,(-1i64) as u64,&mut error);
put_bytes(2,reason.as_bytes(),&mut error);
let mut errors=Vec::new();put_bytes(1,&error,&mut errors);
let mut response=Vec::new();
put_bytes(1,message(&rpc,1).unwrap_or(&[]),&mut response);
put_bytes(2,&errors,&mut response);
Some(response)
}
/// Message 7 ScreenSources in pixels for capture-setting v4: native, choices, current size.
pub fn screen_sources(seq: u64, timestamp: u64, native: (u32, u32), output: Option<(u32, u32)>, name: &str) -> Result<Vec<u8>, String> {
use crate::initialization::{Screen, WinRect};
let outputs=crate::wayland::outputs();
if !outputs.is_empty() {
let current=crate::wayland::selected();
let choices:Vec<Vec<(i32,i32)>>=outputs.iter().map(|m|scaled_sizes((m.width,m.height)).into_iter().map(|(w,h)|(w as i32,h as i32)).collect()).collect();
let screens:Vec<Screen<'_>>=outputs.iter().enumerate().map(|(id,m)| Screen {
id:id as i32, fps:m.fps,
resolution:WinRect {left:0,top:0,width:m.width as i32,height:m.height as i32,pixel_width:m.width as i32,pixel_height:m.height as i32},
primary:id==0,dpr:1.0,display_name:&m.name,video_track_index:if id==current {0} else {-1},
screen_type:0,builtin_screen_type:if m.name.starts_with("eDP") {1} else {2},scaled:&choices[id],
current:if id==current {output.map(|(w,h)|(w as i32,h as i32))} else {None},
}).collect();
return crate::initialization::encode_screen_sources(seq,timestamp,&screens,current as i32);
}
let (w, h) = (native.0 as i32, native.1 as i32);
let scaled: Vec<(i32, i32)> = scaled_sizes(native).into_iter().map(|(w, h)| (w as i32, h as i32)).collect();
// DPI_SCALE starts at version 5; the observed v4 request uses fields 5/6 as pixels.
@@ -248,7 +284,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 { codec: VideoCodec::H264, fps: 30, quality: QUALITY_GENERAL, custom_mbps: 0, output: None, chroma: CHROMA_420 });
assert_eq!(*rx.borrow(), VideoSettings { source_id:0,source_generation:0, codec: VideoCodec::H264, 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][..]));
@@ -469,4 +505,33 @@ mod codec_tests {
assert_eq!(rx.borrow().codec, VideoCodec::H265);
assert_eq!(preferred_codec(true, false), VideoCodec::H264);
}
#[test]
fn software_hosts_default_to_h264_unless_forced() {
assert_eq!(pick_codec(true, true, None, true), VideoCodec::H265);
assert_eq!(pick_codec(true, true, None, false), VideoCodec::H264);
assert_eq!(pick_codec(true, true, Some("h265"), false), VideoCodec::H265);
assert_eq!(pick_codec(true, true, Some("h264"), true), VideoCodec::H264);
// Only one codec bound in the SDP: use it whatever the preference.
assert_eq!(pick_codec(false, true, None, false), VideoCodec::H265);
assert_eq!(pick_codec(true, false, Some("h265"), true), VideoCodec::H264);
}
}
#[cfg(test)]
mod screen_error_tests {
use super::*;
#[test]
fn failed_switch_returns_correlated_error_not_success() {
let header=[10,4,b't',b'e',b's',b't'];
let mut rpc=Vec::new();put_bytes(1,&header,&mut rpc);put_bytes(2,&[32,99],&mut rpc);
let request=crate::initialization::envelope(1,2,21,&rpc);
let response=rejected_request(&request,"Unknown screen").unwrap();
let fields=decode_wire(&response).unwrap();
assert_eq!(message(&fields,1),Some(header.as_slice()));
let result=decode_wire(message(&fields,2).unwrap()).unwrap();
let error=decode_wire(message(&result,1).unwrap()).unwrap();
assert_eq!(number(&error,1),Some(u64::MAX));
assert_eq!(message(&error,2),Some(b"Unknown screen".as_slice()));
assert!(rejected_request(b"invalid","failure").is_none());
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
mod native {
use std::{ffi::c_void, ptr::NonNull};
extern "C" {
crate::engine_ffi! { crate::engine_plugin::Engine::Portal;
fn uu_desktop_power_wake() -> i32;
fn uu_desktop_idle_inhibitor_acquire(error: *mut i32) -> *mut c_void;
fn uu_desktop_idle_inhibitor_release(inhibitor: *mut c_void);
+121
View File
@@ -0,0 +1,121 @@
//! Optional desktop engines loaded at runtime (`--features engine-plugins`).
//!
//! The Wayland (wlroots) and GNOME/KDE portal engines link libwayland/libxkbcommon and
//! GIO/PipeWire/libei. Linking them into `uuremote-server` would stop it from starting on X11 hosts
//! without those libraries, and libei is missing on older distributions. With engine-plugins they
//! are built as `libuu-wayland.so` / `libuu-portal.so`, shipped next to the binary, and opened with
//! dlopen only when the session needs them, so one release package serves every backend.
//! Without the feature the engines are linked statically as before and nothing here is used.
#![cfg_attr(not(feature = "engine-plugins"), allow(dead_code))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Engine { Wayland, Portal }
impl Engine {
pub fn file(self) -> &'static str { match self { Self::Wayland => "libuu-wayland.so", Self::Portal => "libuu-portal.so" } }
fn index(self) -> usize { self as usize }
}
/// Directories searched for engine libraries, in order.
fn search_dirs() -> Vec<std::path::PathBuf> {
let mut dirs = Vec::new();
if let Some(dir) = std::env::var_os("UU_ENGINE_DIR").filter(|d| !d.is_empty()) { dirs.push(dir.into()); }
if let Some(exe_dir) = std::env::current_exe().ok().and_then(|exe| exe.parent().map(|d| d.to_path_buf())) {
dirs.push(exe_dir.join("../lib/uu-remote-linux"));
dirs.push(exe_dir.clone());
}
if let Some(home) = std::env::var_os("HOME") { dirs.push(std::path::Path::new(&home).join(".local/lib/uu-remote-linux")); }
dirs.extend(["/usr/local/lib/uu-remote-linux", "/usr/lib/uu-remote-linux"].map(std::path::PathBuf::from));
dirs
}
#[cfg(all(target_os = "linux", feature = "engine-plugins"))]
mod native {
use super::Engine;
use std::sync::OnceLock;
static HANDLES: [OnceLock<Result<usize, String>>; 2] = [OnceLock::new(), OnceLock::new()];
fn dlerror() -> String {
let message = unsafe { libc::dlerror() };
if message.is_null() { return "unknown dlopen error".into(); }
unsafe { std::ffi::CStr::from_ptr(message) }.to_string_lossy().into_owned()
}
fn open(engine: Engine) -> Result<usize, String> {
for dir in super::search_dirs() {
let path = dir.join(engine.file());
if !path.is_file() { continue; }
use std::os::unix::ffi::OsStrExt;
let Ok(c_path) = std::ffi::CString::new(path.as_os_str().as_bytes()) else { continue };
let handle = unsafe { libc::dlopen(c_path.as_ptr(), libc::RTLD_NOW | libc::RTLD_LOCAL) };
if handle.is_null() {
// Usually a missing system library (e.g. libei.so.1) or a too old glibc.
return Err(format!("{} could not be loaded: {}", path.display(), dlerror()));
}
log::info!("Desktop engine loaded: {}", path.display());
return Ok(handle as usize);
}
Err(format!("{} not found (looked next to uuremote-server, in ../lib/uu-remote-linux, ~/.local/lib/uu-remote-linux, /usr/lib/uu-remote-linux; UU_ENGINE_DIR overrides)", engine.file()))
}
pub fn load(engine: Engine) -> Result<(), String> {
HANDLES[engine.index()].get_or_init(|| open(engine)).as_ref().map(|_| ()).map_err(Clone::clone)
}
/// Address of `name` (NUL-terminated) in the engine, or 0 when the engine or symbol is missing.
pub fn symbol(engine: Engine, name: &'static str) -> usize {
let Ok(handle) = HANDLES[engine.index()].get_or_init(|| open(engine)) else { return 0 };
let address = unsafe { libc::dlsym(*handle as *mut libc::c_void, name.as_ptr().cast()) };
if address.is_null() { log::warn!("Desktop engine {} lacks {}", engine.file(), name.trim_end_matches('\0')); }
address as usize
}
}
/// Loads `engine`, or explains why it is unavailable. Always Ok when the engines are linked in.
pub fn load(engine: Engine) -> Result<(), String> {
#[cfg(all(target_os = "linux", feature = "engine-plugins"))]
{ native::load(engine) }
#[cfg(not(all(target_os = "linux", feature = "engine-plugins")))]
{ let _ = engine; Ok(()) }
}
#[cfg(all(target_os = "linux", feature = "engine-plugins"))]
pub use native::symbol;
/// Value returned by an engine call whose library could not be loaded (callers check `load` first).
pub trait Missing { fn missing() -> Self; }
impl Missing for () { fn missing() -> Self {} }
impl Missing for i32 { fn missing() -> Self { -1 } }
impl<T> Missing for *mut T { fn missing() -> Self { std::ptr::null_mut() } }
/// Declares engine C functions: an `extern "C"` block when linked statically, or dlsym-resolved
/// wrappers with the same names and signatures with `engine-plugins`.
#[macro_export]
macro_rules! engine_ffi {
($engine:expr; $(fn $name:ident($($arg:ident: $ty:ty),* $(,)?) $(-> $ret:ty)?;)*) => {
#[cfg(not(feature = "engine-plugins"))]
extern "C" { $(fn $name($($arg: $ty),*) $(-> $ret)?;)* }
$(
#[cfg(feature = "engine-plugins")]
unsafe fn $name($($arg: $ty),*) $(-> $ret)? {
static ADDRESS: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
let address = *ADDRESS.get_or_init(|| $crate::engine_plugin::symbol($engine, concat!(stringify!($name), "\0")));
if address == 0 { return $crate::engine_plugin::Missing::missing(); }
let function: unsafe extern "C" fn($($ty),*) $(-> $ret)? = unsafe { std::mem::transmute(address) };
unsafe { function($($arg),*) }
}
)*
};
}
#[cfg(test)]
mod tests {
#[test]
fn search_prefers_override_then_package_layout() {
let dirs = super::search_dirs();
let exe_dir = std::env::current_exe().unwrap().parent().unwrap().to_path_buf();
assert!(dirs.iter().position(|d| *d == exe_dir.join("../lib/uu-remote-linux")) < dirs.iter().position(|d| *d == exe_dir));
assert_eq!(dirs.last().unwrap(), std::path::Path::new("/usr/lib/uu-remote-linux"));
}
}
+14 -3
View File
@@ -77,8 +77,8 @@ pub struct Screen<'a> {
}
impl Screen<'_> {
fn encode(&self) -> Result<Vec<u8>, String> {
if self.id < 0 || self.fps <= 0 || self.video_track_index < 0 {
return Err("Screen id/track must be nonnegative and fps positive".into());
if self.id < 0 || self.fps <= 0 || self.video_track_index < -1 {
return Err("Screen id must be nonnegative, track >= -1 and fps positive".into());
}
if !self.dpr.is_finite() || self.dpr <= 0.0 {
return Err("Screen dpr must be positive and finite".into());
@@ -118,7 +118,7 @@ pub fn encode_screen_sources(seq: u64, timestamp: u64, screens: &[Screen<'_>], c
let mut tracks = std::collections::HashSet::new();
let mut payload = Vec::new();
for screen in screens {
if !ids.insert(screen.id) || !tracks.insert(screen.video_track_index) {
if !ids.insert(screen.id) || (screen.video_track_index >= 0 && !tracks.insert(screen.video_track_index)) {
return Err("Screen ids and video track indices must be unique".into());
}
bytes(1, &screen.encode()?, &mut payload);
@@ -295,3 +295,14 @@ mod tests {
assert!(encode_capture_change(1, 2, 4, 1, "").is_err());
}
}
#[cfg(test)]
mod inactive_track_tests {
use super::*;
#[test]
fn multiple_inactive_screens_share_minus_one_but_active_track_is_unique() {
let screen=|id,track| Screen {id,fps:60,resolution:WinRect {left:0,top:0,width:1920,height:1080,pixel_width:1920,pixel_height:1080},primary:id==0,dpr:1.0,display_name:"test",video_track_index:track,screen_type:0,builtin_screen_type:0,scaled:&[],current:None};
assert!(encode_screen_sources(1,2,&[screen(0,0),screen(1,-1),screen(2,-1)],0).is_ok());
assert!(encode_screen_sources(1,2,&[screen(0,0),screen(1,0)],0).is_err());
}
}
+73 -1
View File
@@ -325,6 +325,12 @@ impl InputInjector {
}
}
fn inject_move(&self,x:i32,y:i32,relative:bool)->i32 {
// uinput ABS axes span the compositor's whole desktop. A captured output
// uses its own pixel space; bind absolute motion to that Wayland output,
// including when uinput remains in use for keyboard/buttons/relative input.
if !relative && self.backend==crate::desktop_backend::DesktopBackend::Wayland {
return crate::wayland::move_pointer(x,y,false);
}
if let Some(uinput)=&self.uinput {
if relative { return Self::uinput_result(uinput.move_relative(x,y)); }
let (w,h)=*self.screen.lock().unwrap();
@@ -360,13 +366,27 @@ impl InputInjector {
if self.backend==crate::desktop_backend::DesktopBackend::Wayland { crate::wayland::key(symbol,pressed) }
else { unsafe { x11_key_symbol(symbol as libc::c_ulong,i32::from(pressed)) } }
}
/// Mobile input-method text (`text_input`). X11 only for now; other backends log once.
/// Mobile input-method text (`text_input`). X11 types it directly; Wayland re-maps a spare
/// keycode in the virtual keyboard's keymap. Other backends log once.
pub fn text_input(&self, text: &str) {
let _serial=self.serial.lock().unwrap();
let Ok(c_text)=std::ffi::CString::new(text.replace('\0',"")) else { return };
if self.backend==crate::desktop_backend::DesktopBackend::X11 {
let typed=unsafe { x11_type_utf8(c_text.as_ptr()) };
log::info!("Desktop text input: chars={} result={}", text.chars().count(), typed);
} else if self.backend==crate::desktop_backend::DesktopBackend::Wayland {
// Escape hatch: keep the old behaviour without rebuilding.
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v|v=="0") { return; }
let typed=crate::wayland::type_utf8(text);
if typed>=0 {
log::info!("Desktop text input: chars={} result={}", text.chars().count(), typed);
return;
}
// A keymap whose keycodes are all mapped cannot carry text; report it once.
static WARNED:std::sync::atomic::AtomicBool=std::sync::atomic::AtomicBool::new(false);
if !WARNED.swap(true,std::sync::atomic::Ordering::Relaxed) {
log::warn!("Mobile text input unavailable on the Wayland backend (no spare keycode in this keymap)");
}
} else {
static WARNED:std::sync::atomic::AtomicBool=std::sync::atomic::AtomicBool::new(false);
if !WARNED.swap(true,std::sync::atomic::Ordering::Relaxed) {
@@ -625,3 +645,55 @@ mod lifecycle_tests {
session.with_input(||panic!("late event after disconnect"));
}
}
#[cfg(all(test,target_os="linux",feature="wayland"))]
mod output_pointer_tests {
use super::*;
#[test]
#[ignore="requires unlocked Hyprland, UU_WAYLAND_MULTISCREEN=1 and accessible uinput; moves pointer only"]
fn absolute_pointer_stays_on_capture_output_with_uinput_enabled() {
fn cursor()->serde_json::Value {
let output=std::process::Command::new("hyprctl").args(["cursorpos","-j"]).output().unwrap();
assert!(output.status.success());serde_json::from_slice(&output.stdout).unwrap()
}
struct Restore(serde_json::Value);
impl Drop for Restore {
fn drop(&mut self) {
let _=std::process::Command::new("hyprctl").args(["dispatch","movecursor",&self.0["x"].to_string(),&self.0["y"].to_string()]).output();
}
}
let _restore=Restore(cursor());
crate::wayland::init().unwrap();
let input=InputInjector::new();
assert!(input.uinput.is_some(),"test must exercise the uinput/native hybrid path");
// libinput discovers the newly created virtual devices asynchronously.
std::thread::sleep(std::time::Duration::from_secs(1));
let output=std::process::Command::new("hyprctl").args(["monitors","-j"]).output().unwrap();
let monitors:Vec<serde_json::Value>=serde_json::from_slice(&output.stdout).unwrap();
let outputs=crate::wayland::outputs();assert!(outputs.len()>=2,"needs at least two outputs");
for (id,output) in outputs.iter().enumerate().chain(outputs.iter().enumerate().rev()) {
crate::wayland::select(id).unwrap();
let monitor=monitors.iter().find(|m|m["name"].as_str()==Some(output.name.as_str())).unwrap();
let scale=monitor["scale"].as_f64().unwrap();
for (x,y) in [(0.1,0.1),(0.5,0.5),(0.9,0.9),(0.1,0.9),(0.9,0.1)] {
let size=(output.width,output.height);
let pixels=crate::input_mapping::normalized_pointer(x,y,size.0,size.1).unwrap();
assert_eq!(input.backend,crate::desktop_backend::DesktopBackend::Wayland);
input.mouse_absolute_normalized(x,y,size);input.flush_pointer();
let expected=(monitor["x"].as_f64().unwrap()+f64::from(pixels.0)/scale,
monitor["y"].as_f64().unwrap()+f64::from(pixels.1)/scale);
// Motion is asynchronous; observe its first arrival instead of a
// later position potentially changed by another input device.
let deadline=std::time::Instant::now()+std::time::Duration::from_millis(250);
loop {
let actual=cursor();
let matched=(actual["x"].as_f64().unwrap()-expected.0).abs()<=2.0
&& (actual["y"].as_f64().unwrap()-expected.1).abs()<=2.0;
if matched {break;}
assert!(std::time::Instant::now()<deadline,"pointer offset: output={} normalized=({},{}) actual={} expected={:?}",output.name,x,y,actual,expected);
std::thread::sleep(std::time::Duration::from_millis(5));
}
}
}
}
}
+9 -3
View File
@@ -1,6 +1,7 @@
//! UU Remote Pure Native Linux Server (Rust Edition)
//! Zero-Wine, Zero-Python, Single-Binary, 5 Native Tools Integrated
mod engine_plugin;
mod desktop_backend;
mod desktop_session;
mod desktop_power;
@@ -190,8 +191,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.filter_module("uuremote_server", log::LevelFilter::Info).init();
} else { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); }
// An unknown argument must never fall through to starting a second full host server.
const SUBCOMMANDS: [&str; 13] = ["show", "assist", "desktop-input-probe", "virtual-audio-probe", "login", "unlock-check", "desktop-probe", "desktop-video-probe", "desktop-audio-probe", "wayland-capture",
"wayland-input-probe", "clipboard-acceptance", "portal-acceptance"];
const SUBCOMMANDS: [&str; 14] = ["show", "assist", "desktop-input-probe", "virtual-audio-probe", "login", "unlock-check", "desktop-probe", "desktop-video-probe", "desktop-audio-probe", "wayland-capture",
"wayland-input-probe", "wayland-text-probe", "clipboard-acceptance", "portal-acceptance"];
if let Some(arg) = std::env::args().nth(1).filter(|a| !SUBCOMMANDS.contains(&a.as_str())) {
let usage = format!("usage: uuremote-server [{}]\n (no argument: run the host)", SUBCOMMANDS.join(" | "));
if matches!(arg.as_str(), "help" | "-h" | "--help") { println!("{usage}"); return Ok(()); }
@@ -353,6 +354,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if std::env::args().nth(1).as_deref() == Some("wayland-input-probe") {
return wayland::input_probe().map_err(|e|e.into());
}
if std::env::args().nth(1).as_deref() == Some("wayland-text-probe") {
return wayland::text_probe().map_err(|e|e.into());
}
if std::env::args().nth(1).as_deref() == Some("wayland-capture") {
return wayland::capture_stdout().map_err(|e| e.into());
}
@@ -409,7 +413,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let capture = Arc::new((if desktop_backend::headless() {
Err("headless mode (UU_DESKTOP_BACKEND=none)".to_owned())
} else if desktop_backend::detect()?==desktop_backend::DesktopBackend::Portal {
Err("Portal capture waits for a desktop CONTROL connection".to_owned())
Err(if !cfg!(feature = "portal") { portal::NOT_BUILT.to_owned() }
else if let Err(reason) = engine_plugin::load(engine_plugin::Engine::Portal) { format!("GNOME/KDE Wayland (portal) engine unavailable: {reason}") }
else { "Portal capture waits for a desktop CONTROL connection".to_owned() })
} else { ScreenCapture::new() }).unwrap_or_else(|error| {
log::warn!("Desktop unavailable; terminal and file tools remain available: {error}");
ScreenCapture::unavailable(error)
+20 -9
View File
@@ -22,7 +22,7 @@ mod permissions;
#[cfg(all(target_os = "linux", feature = "portal"))]
mod native {
use std::{ffi::c_void, ptr::NonNull, sync::{Mutex, MutexGuard, TryLockError}};
extern "C" {
crate::engine_ffi! { crate::engine_plugin::Engine::Portal;
fn uu_portal_open_persist(restore: *const libc::c_char, save: extern "C" fn(*const libc::c_char, *mut c_void), data: *mut c_void, error: *mut i32, width: *mut u32, height: *mut u32) -> *mut c_void;
fn uu_portal_open_persist_cancellable(restore: *const libc::c_char, save: extern "C" fn(*const libc::c_char, *mut c_void), save_data: *mut c_void, cancelled: extern "C" fn(*mut c_void) -> i32, cancel_data: *mut c_void, error: *mut i32, width: *mut u32, height: *mut u32) -> *mut c_void;
fn uu_portal_clipboard_supported(portal: *mut c_void) -> i32;
@@ -116,6 +116,8 @@ mod native {
if cancelled.is_some_and(|value| value.load(std::sync::atomic::Ordering::Acquire)) {
return Err(super::PortalError { code: 13 });
}
// engine-plugins: libuu-portal.so (or one of its libraries) may be missing on this host.
crate::engine_plugin::load(crate::engine_plugin::Engine::Portal).map_err(|_| super::PortalError { code: 15 })?;
let (mut error, mut width, mut height) = (0, 0, 0);
let directory = super::permissions::directory();
let key = super::permissions::desktop_key();
@@ -584,12 +586,20 @@ fn error(code: i32) -> String {
8 => "unsupported frame format or size", 9 => "session closed or stream lost",
10 => "frame unavailable", 11 => "invalid input or frame buffer",
13 => "operation cancelled", 14 => "dimensions changed; reconnect required",
15 => return match crate::engine_plugin::load(crate::engine_plugin::Engine::Portal) {
Err(reason) if cfg!(feature = "portal") => format!("GNOME/KDE Wayland (portal) engine unavailable: {reason}"),
_ => NOT_BUILT.into(),
},
_ => "operation failed",
};
format!("Portal {reason} (code {code})")
}
fn check(code: i32) -> Result<(), String> { if code == 0 { Ok(()) } else { Err(error(code)) } }
/// GNOME/KDE Wayland selected the portal backend, but this binary was built without it (the release
/// package is X11 only): say how to get a picture instead of an opaque "portal unavailable".
pub const NOT_BUILT: &str = "this build has no GNOME/KDE Wayland (portal) support: choose the Xorg session \
(\"GNOME on Xorg\" / \"Plasma (X11)\") at the login screen, or build with --features wayland,portal";
#[cfg(all(target_os = "linux", feature = "portal"))]
pub use native::Session as PortalSession;
#[cfg(not(all(target_os = "linux", feature = "portal")))]
@@ -598,24 +608,24 @@ pub struct PortalSession { pub width: u32, pub height: u32 }
impl PortalSession {
pub fn clipboard_supported(&self) -> bool { false }
pub fn clipboard_ready(&self) -> bool { false }
pub fn clipboard_set(&self, _: &str) -> Result<(), String> { Err(error(2)) }
pub fn clipboard_set(&self, _: &str) -> Result<(), String> { Err(error(15)) }
pub fn clipboard_poll(&self) -> Option<String> { None }
pub fn is_alive(&self) -> bool { false }
pub fn open() -> Result<Self, String> { Err("Portal backend requires Linux and --features portal".into()) }
pub fn open_cancellable(cancelled: &std::sync::atomic::AtomicBool) -> Result<Self, PortalError> {
if cancelled.load(std::sync::atomic::Ordering::Acquire) { Err(PortalError { code: 13 }) }
else { Err(PortalError { code: 2 }) }
else { Err(PortalError { code: 15 }) }
}
pub fn recover(&self, cancelled: &std::sync::atomic::AtomicBool) -> Result<bool, PortalError> {
if cancelled.load(std::sync::atomic::Ordering::Acquire) { Err(PortalError { code: 13 }) }
else { Err(PortalError { code: 2 }) }
else { Err(PortalError { code: 15 }) }
}
pub fn pause(&self) {}
pub fn capture(&self, _: &mut [u8]) -> Result<(), String> { Err(error(2)) }
pub fn capture_changed(&self, _: &mut [u8], _: &mut Option<FrameVersion>) -> Result<bool, String> { Err(error(2)) }
pub fn move_pointer(&self, _: f64, _: f64, _: bool) -> Result<(), String> { Err(error(2)) }
pub fn button(&self, _: i32, _: bool) -> Result<(), String> { Err(error(2)) }
pub fn key(&self, _: u64, _: bool) -> Result<(), String> { Err(error(2)) }
pub fn capture(&self, _: &mut [u8]) -> Result<(), String> { Err(error(15)) }
pub fn capture_changed(&self, _: &mut [u8], _: &mut Option<FrameVersion>) -> Result<bool, String> { Err(error(15)) }
pub fn move_pointer(&self, _: f64, _: f64, _: bool) -> Result<(), String> { Err(error(15)) }
pub fn button(&self, _: i32, _: bool) -> Result<(), String> { Err(error(15)) }
pub fn key(&self, _: u64, _: bool) -> Result<(), String> { Err(error(15)) }
}
/// Forward frames in-process into encoder stdin. Cancellation drops the Arc;
@@ -641,6 +651,7 @@ mod tests {
fn errors_never_include_remote_messages_or_identifiers() {
assert!(super::check(4).unwrap_err().contains("cancelled or denied"));
assert!(super::check(9).unwrap_err().contains("closed or stream lost"));
assert!(super::check(15).unwrap_err().contains("--features wayland,portal"));
}
#[test]
fn portal_error_display_is_fixed_and_sanitized() {
+220 -31
View File
@@ -94,16 +94,57 @@ fn nal_offsets_for(bytes: &[u8], kind: u8, codec: VideoCodec) -> Vec<usize> {
let matches = match codec {
VideoCodec::H264 => header < bytes.len() && bytes[header] & 31 == kind,
// HEVC has a two-byte header: forbidden_zero_bit=0, temporal_id_plus1 != 0.
VideoCodec::H265 => header + 1 < bytes.len() && bytes[header] & 128 == 0
&& bytes[header + 1] & 7 != 0 && (bytes[header] >> 1) & 63 == kind,
VideoCodec::H265 => hevc_nal_kind(bytes, header) == Some(kind),
};
if matches { result.push(i); }
i += prefix;
}
result
}
fn aud_offsets_for(bytes: &[u8], codec: VideoCodec) -> Vec<usize> {
nal_offsets_for(bytes, if codec == VideoCodec::H265 { 35 } else { 9 }, codec)
/// Validated HEVC NAL unit type from the two-byte header (`None` when it is incomplete or the
/// forbidden bit is set or temporal_id_plus1 is zero).
fn hevc_nal_kind(bytes: &[u8], header: usize) -> Option<u8> {
(header + 1 < bytes.len() && bytes[header] & 128 == 0 && bytes[header + 1] & 7 != 0)
.then(|| (bytes[header] >> 1) & 63)
}
/// Access-unit starts for H.265, independent of where the encoder puts its AUDs. VAAPI writes an
/// AUD only at IRAPs, so splitting on AUD alone groups a whole GOP into one "frame" (and that
/// frame then fails the IRAP gate, so nothing is sent). RFC 7798 §3.1 puts the boundary at the
/// first NAL after a VCL NAL that is either non-VCL (AUD/VPS/SPS/PPS/SEI) or starts a picture
/// (first_slice_segment_in_pic_flag), which also keeps multi-slice pictures in one unit.
fn hevc_au_offsets(bytes: &[u8]) -> Vec<usize> {
let mut result = Vec::new();
let mut previous_vcl = false;
let mut first = true;
let mut i = 0;
while i + 3 < bytes.len() {
let prefix = if bytes[i..].starts_with(&[0, 0, 0, 1]) { 4 }
else if bytes[i..].starts_with(&[0, 0, 1]) { 3 } else { i += 1; continue };
let header = i + prefix;
if let Some(kind) = hevc_nal_kind(bytes, header) {
let vcl = kind < 32;
let starts_picture = vcl && bytes.get(header + 2).is_some_and(|byte| byte & 0x80 != 0);
// RFC 7798 / H.265 7.4.2.4.4: only these non-VCL types may open the next access unit.
// Suffix SEI (40), filler (38) and end of sequence/bitstream (36, 37) stay with the
// picture they follow.
let opens_unit = matches!(kind, 32..=35 | 39 | 41..=44 | 48..=55);
if first || (previous_vcl && (opens_unit || starts_picture)) { result.push(i); }
// Trailing NALs (suffix SEI, filler, end markers) do not end "after a VCL NAL".
if vcl || opens_unit { previous_vcl = vcl; }
first = false;
}
i += prefix;
}
result
}
fn au_offsets_for(bytes: &[u8], codec: VideoCodec) -> Vec<usize> {
match codec {
VideoCodec::H264 => nal_offsets_for(bytes, 9, codec),
VideoCodec::H265 => hevc_au_offsets(bytes),
}
}
fn is_independent_frame_for(bytes: &[u8], codec: VideoCodec) -> bool {
match codec {
@@ -114,11 +155,13 @@ fn is_independent_frame_for(bytes: &[u8], codec: VideoCodec) -> bool {
}
}
#[cfg(test)]
fn aud_offsets(bytes: &[u8]) -> Vec<usize> { aud_offsets_for(bytes, VideoCodec::H264) }
fn aud_offsets(bytes: &[u8]) -> Vec<usize> { au_offsets_for(bytes, VideoCodec::H264) }
fn is_independent_frame(bytes: &[u8]) -> bool { is_independent_frame_for(bytes, VideoCodec::H264) }
#[derive(Debug)]
struct CompleteFrame {
source_id: usize,
source_generation: u64,
codec: VideoCodec,
sequence: u64,
completed_at: Instant,
@@ -126,6 +169,12 @@ struct CompleteFrame {
_permit: Option<OwnedSemaphorePermit>,
}
impl CompleteFrame {
fn matches(&self,settings:&VideoSettings)->bool {
self.codec==settings.codec && self.source_id==settings.source_id && self.source_generation==settings.source_generation
}
}
const RTP_CLOCK: u64 = 90_000;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -178,10 +227,17 @@ fn vaapi_options(settings: &VideoSettings, gop: &str) -> Vec<String> {
let (maxrate, buffer) = rate_args(settings, Encoder::Vaapi);
// QVBR is not uniformly available on Intel/AMD drivers. VBR + qmin sets a quality
// floor while retaining the viewer's bitrate cap; unsupported drivers fall back to CPU.
["-c:v", Encoder::Vaapi.name_for(settings.codec), "-profile:v", profile_for(settings.codec, true), "-g", gop, "-bf", "0",
"-rc_mode", "VBR", "-b:v", &settings.max_kbps().map_or("16M".into(), |k| format!("{}k",k*3/4)),
"-maxrate", &maxrate, "-bufsize", &buffer, "-qmin", &settings.cq().to_string(), "-async_depth", "1", "-aud", "1"]
.into_iter().map(str::to_owned).collect()
let mut options: Vec<String> = ["-c:v", Encoder::Vaapi.name_for(settings.codec), "-profile:v", profile_for(settings.codec, true),
"-g", gop, "-bf", "0", "-rc_mode", "VBR", "-b:v", &settings.max_kbps().map_or("16M".into(), |k| format!("{}k",k*3/4)),
"-maxrate", &maxrate, "-bufsize", &buffer, "-qmin", &settings.cq().to_string(), "-async_depth", "1"]
.into_iter().map(str::to_owned).collect();
// h264_vaapi writes an AUD per picture and the reader splits access units on it. hevc_vaapi
// does not: with `-aud 1` it writes an AUD only at IRAPs and drops every other picture from
// the bitstream (a 90-frame clip encoded to 3 IDRs and no P-frames), so HEVC leaves AUD off
// and hevc_au_offsets() splits pictures by their own boundaries. Parameter sets are still
// repeated in-band ahead of every IDR.
if settings.codec == VideoCodec::H264 { options.extend(["-aud".into(), "1".into()]); }
options
}
fn profile_for(codec: VideoCodec, vaapi: bool) -> &'static str {
@@ -238,8 +294,22 @@ fn encoder_options(settings: &VideoSettings, encoder: Encoder, gop: &str, rgb: O
options.into_iter().map(str::to_owned).collect()
}
fn scale_options(settings: &VideoSettings, encoder: Encoder) -> Vec<String> {
if encoder == Encoder::Vaapi { return vec!["-vf".into(), vaapi_filter(settings.output)]; }
/// Filter chain for a capture of `source` size (None when the input size is not known yet, e.g.
/// the fixed-input probe). H.264/HEVC 4:2:0 encoders — and NVENC's surface allocation — require
/// even frame dimensions, but the captured size is not always even: the portal backend reports the
/// compositor's logical desktop size, so two stacked monitors at 150% scale capture 2560x2507 and
/// every encoder failed to open ("height not divisible by 2 (2560x2507)" from libx264,
/// "InitializeEncoder failed: out of memory (10)" from h264_nvenc), leaving the viewer stuck on the
/// 正在传输画面 spinner. When the native capture size is odd, pad the odd row/column; the host
/// display mode and every reported capture setting stay untouched.
fn scale_options(settings: &VideoSettings, encoder: Encoder, source: Option<(u32,u32)>) -> Vec<String> {
const EVEN_PAD: &str = "pad=ceil(iw/2)*2:ceil(ih/2)*2:0:0:black";
let odd_capture = settings.output.is_none() && source.is_some_and(|(w,h)| w % 2 != 0 || h % 2 != 0);
if encoder == Encoder::Vaapi {
let filtered = if odd_capture { format!("{EVEN_PAD},{}", vaapi_filter(None)) } else { vaapi_filter(settings.output) };
return vec!["-vf".into(), filtered];
}
if odd_capture { return vec!["-vf".into(), EVEN_PAD.into()]; }
settings.output.map_or_else(Vec::new, |(w,h)| vec!["-vf".into(), format!("scale={w}:{h}:flags=bilinear")])
}
@@ -465,7 +535,7 @@ async fn read_inprocess(
let mut gate = DependencyGate::default();
while let Some(unit) = units.recv().await {
let sequence = sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
gate.submit(&latest, Arc::new(CompleteFrame { codec, sequence, completed_at: unit.completed_at, data: unit.data, _permit: Some(unit.permit) }));
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: 0, source_id: 0, codec, sequence, completed_at: unit.completed_at, data: unit.data, _permit: Some(unit.permit) }));
if latest.is_closed() { break; }
}
// Dropping the receiver also unblocks the encoder if it is waiting to send.
@@ -480,7 +550,21 @@ async fn read_inprocess(
/// whole IDR frame, otherwise large desktops get near-grey keyframes that sharpen over the GOP (#8).
/// Half a second of bitrate still starved repeated 0.5 s-GOP keyframes at 3296x2036/2M; one second did not.
fn buffer_kbits(max_kbps: u32, encoder: Encoder) -> u32 {
if encoder == Encoder::Cpu { max_kbps.clamp(500, 8000) } else { (max_kbps / 8).clamp(100, 500) }
if encoder == Encoder::Cpu { max_kbps.clamp(500, 8000) }
else if encoder == Encoder::Vaapi {
let requested = std::env::var("UU_VAAPI_BUFFER_MS").ok();
vaapi_buffer_kbits(max_kbps, requested.as_deref()).unwrap_or((max_kbps / 8).clamp(100, 500))
}
else { (max_kbps / 8).clamp(100, 500) }
}
/// Opt-in VAAPI VBV buffer: `码率上限 × 毫秒 / 1000` for `UU_VAAPI_BUFFER_MS` in 10-1000 ms.
/// The 100-500 kbit default is sized for NVENC; VAAPI quantizes a whole desktop keyframe when
/// the buffer is that small, which reads as a blur that sharpens over each GOP (#42).
/// Unset, out of range or unparsable values keep the default buffer.
fn vaapi_buffer_kbits(max_kbps: u32, value: Option<&str>) -> Option<u32> {
let ms = value?.trim().parse::<u32>().ok().filter(|ms| (10..=1000).contains(ms))?;
Some((max_kbps.saturating_mul(ms) / 1000).max(1))
}
fn buffer_for(settings: &VideoSettings, encoder: Encoder) -> u32 {
@@ -498,6 +582,8 @@ async fn read_encoder_with(
size: (u32,u32),display:String,portal:Option<Arc<crate::portal::PortalSession>>,latest:mpsc::Sender<Arc<CompleteFrame>>,encoder:Encoder,sequence:Arc<std::sync::atomic::AtomicU64>,
settings: VideoSettings, #[cfg_attr(not(feature = "inproc-av"), allow(unused_variables))] idr: Arc<AtomicBool>, budget: Arc<Semaphore>,
)->Result<(),String>{
let selected_output=if display.starts_with("wayland:") {crate::wayland::source(settings.source_id)} else {None};
let size=selected_output.map_or(size,|s|(s.width,s.height));
let kms=display.starts_with("kms:");
let wayland=kms || display.starts_with("wayland:");
let (permits_tx,mut permits_rx)=mpsc::channel::<OwnedSemaphorePermit>(4);
@@ -520,6 +606,7 @@ async fn read_encoder_with(
display,size.0,size.1,settings.output,settings.fps,config.cq,max_kbps,encoder.name_for(settings.codec));
return read_inprocess(config, latest, sequence, idr, budget).await;
}
let source_size = size;
let size = format!("{}x{}", size.0, size.1);
let fps = settings.fps.to_string();
// Keep the IDR interval at 2 s whatever the frame rate.
@@ -543,7 +630,7 @@ async fn read_encoder_with(
"-video_size",&size,"-i",&display,"-an"]);
}
// 其他分辨率: scale the captured desktop (the host display mode is left untouched).
command.args(scale_options(&settings, encoder));
command.args(scale_options(&settings, encoder, Some(source_size)));
command.args(encoder_options(&settings, encoder, &gop, rgb));
// x11grab paces against an absolute schedule; after a capture stall it grabs
// back-to-back to "catch up" (measured 69 frames in 200ms). vfr on a 1/FPS
@@ -560,7 +647,9 @@ async fn read_encoder_with(
let executable=std::path::PathBuf::from("/proc/self/exe");
#[cfg(not(target_os="linux"))]
let executable=std::env::current_exe().map_err(|e|format!("Capture executable: {e}"))?;
let mut capture=wayland_capture_command(&executable,settings.fps)
let mut capture_command=wayland_capture_command(&executable,settings.fps);
if let Some(output)=selected_output {capture_command.env("UU_WAYLAND_OUTPUT",&output.name);}
let mut capture=capture_command
.env("UU_WAYLAND_DEMAND","1")
.kill_on_drop(true).stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::inherit())
.spawn().map_err(|e|format!("Start Wayland capture: {e}"))?;
@@ -651,14 +740,14 @@ async fn read_encoder_with(
pending.extend_from_slice(&chunk[..count]);
// A chunk can include the next AUD, so split before enforcing the bound.
loop {
let aud = aud_offsets_for(&pending, settings.codec);
let aud = au_offsets_for(&pending, settings.codec);
if aud.len() < 2 { break; }
let next = aud[1];
if next > MAX_ACCESS_UNIT { return Err("Encoder access unit exceeds limit".into()); }
let frame: Vec<u8> = pending.drain(..next).collect();
let sequence = sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
let permit=if wayland {Some(permits_rx.recv().await.ok_or("Capture producer stopped")?)} else {None};
gate.submit(&latest, Arc::new(CompleteFrame {
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: settings.source_generation, source_id: settings.source_id,
codec: settings.codec, sequence, completed_at: Instant::now(), data: frame, _permit: permit,
}));
if latest.is_closed() { return Ok(()); }
@@ -686,7 +775,16 @@ fn probe_settings() -> Result<VideoSettings,String> {
None=>crate::capture_setting::QUALITY_AUTO,
Some(v)=>v.parse::<u64>().ok().filter(|q|(1..=5).contains(q)).ok_or("UU_PROBE_QUALITY must be 1-5")?,
};
Ok(VideoSettings {fps,quality,..VideoSettings::default()})
Ok(VideoSettings {fps,quality,codec:probe_codec(),..VideoSettings::default()})
}
/// The probe follows `UU_VIDEO_CODEC` so the HEVC path can be measured at all (H.264 otherwise),
/// and its first access unit is then checked against that codec instead of always H.264.
fn probe_codec() -> VideoCodec {
match std::env::var("UU_VIDEO_CODEC").ok().as_deref().map(str::to_ascii_lowercase).as_deref() {
Some("h265") | Some("hevc") => VideoCodec::H265,
_ => VideoCodec::H264,
}
}
fn probe_input_command(spec:&FfmpegSpec,input:&std::ffi::OsStr,loop_input:bool,settings:&VideoSettings,
@@ -697,10 +795,10 @@ fn probe_input_command(spec:&FfmpegSpec,input:&std::ffi::OsStr,loop_input:bool,s
if loop_input { command.args(["-stream_loop","-1"]); }
// Override source timestamps so clips and image sequences use the same nominal probe rate.
command.args(["-r",&settings.fps.to_string(),"-i"]).arg(input).args(["-map","0:v:0","-an"]);
command.args(scale_options(settings,encoder));
command.args(scale_options(settings,encoder,None));
command.args(encoder_options(settings,encoder,&gop_frames(settings.fps,false).to_string(),None));
command.args(timing_args(timing,settings.fps));
command.args(["-frames:v",&wanted.to_string(),"-f","h264","pipe:1"]);
command.args(["-frames:v",&wanted.to_string(),"-f",if settings.codec==VideoCodec::H265 {"hevc"} else {"h264"},"pipe:1"]);
command
}
@@ -749,10 +847,10 @@ pub async fn probe_input(input:OsString,path:Option<String>)->Result<(),String>
let n=stdout.read(&mut chunk).await.map_err(|e|format!("Encoder read: {e}"))?;
pending.extend_from_slice(&chunk[..n]);
loop {
let aud=aud_offsets_for(&pending,settings.codec);
let aud=au_offsets_for(&pending,settings.codec);
let end=if aud.len()>1 { aud[1] } else if n==0 && !pending.is_empty() { pending.len() } else { break; };
if end>MAX_ACCESS_UNIT { return Err("Encoder access unit exceeds limit".into()); }
if count==0 && !is_independent_frame(&pending[..end]) { return Err("Video probe did not begin with IDR".into()); }
if count==0 && !is_independent_frame_for(&pending[..end], settings.codec) { return Err("Video probe did not begin with IDR".into()); }
if let Some(file)=file.as_mut() { file.write_all(&pending[..end]).map_err(|e|e.to_string())?; }
bytes+=end; count+=1;
pending.drain(..end);
@@ -787,7 +885,7 @@ pub async fn probe(size:(u32,u32),display:String,portal:Option<Arc<crate::portal
tokio::time::timeout(Duration::from_secs(15+wanted/30),async {
while count<wanted {
let frame=rx.recv().await.ok_or("Video probe encoder ended")?;
if count==0 && !is_independent_frame(&frame.data) { return Err("Video probe did not begin with IDR".to_owned()); }
if count==0 && !is_independent_frame_for(&frame.data, settings.codec) { return Err("Video probe did not begin with IDR".to_owned()); }
if let Some(file)=file.as_mut() { file.write_all(&frame.data).map_err(|e|e.to_string())?; }
bytes+=frame.data.len(); count+=1;
}
@@ -835,7 +933,7 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
'stream: loop {
let next = *settings.borrow_and_update();
if next != current || send_interrupted {
let discard = next.codec != current.codec || send_interrupted;
let discard = next.codec != current.codec || next.source_generation != current.source_generation || next.source_id != current.source_id || send_interrupted;
current = next;
timeline.fps = u64::from(next.fps);
if discard {
@@ -859,6 +957,19 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
reader.0 = tokio::spawn(read_encoder(size, display.clone(), portal.clone(), latest.clone(), current, sequence.clone(), idr.clone(), budget.clone()));
continue;
}
if result.is_err() && !crate::wayland::outputs().is_empty() && !crate::wayland::input_ready() {
// Leave the stream task alive so the request worker can roll back
// a failed capture/encoder and restart the previous source.
crate::wayland::failed(current.source_id,current.source_generation);
loop {
tokio::select! {
changed=settings.changed()=>{if changed.is_err(){return result;}break;},
_=health.tick()=>{if transport_closed(&pc){return Ok(());}},
}
}
send_interrupted=true;
continue;
}
return result;
},
_ = health.tick() => { if transport_closed(&pc) { return Ok(()); } },
@@ -869,7 +980,7 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
frame = receiver.recv() => {
// A closed queue means the reader ended; its JoinHandle carries the reason.
let Some(frame) = frame else { return (&mut reader.0).await.map_err(|e| format!("Encoder reader task: {e}"))?; };
if frame.codec != current.codec { continue; }
if !frame.matches(&current) { continue; }
let duration = timeline.duration_after(frame.completed_at);
if let Some(last) = previous { skipped += frame.sequence.saturating_sub(last + 1); }
max_age_ms = max_age_ms.max(frame.completed_at.elapsed().as_millis());
@@ -878,6 +989,7 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
data: frame.data.clone().into(), duration, ..Default::default()
};
let extensions = [crate::rtp_metadata::capture_index(0), crate::rtp_metadata::new_frame()];
let sent_before=track.revision();
let send = track.write_sample_with_extensions(frame.codec, &sample, &extensions);
let send_started=Instant::now();
tokio::pin!(send);
@@ -891,6 +1003,9 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
},
}
}
if !crate::wayland::outputs().is_empty() && track.revision()>sent_before {
crate::wayland::presented(current.source_id,current.source_generation);
}
previous = Some(frame.sequence);
max_send_ms=max_send_ms.max(send_started.elapsed().as_millis());
frames += 1;
@@ -910,6 +1025,28 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
#[cfg(test)]
mod tests {
#[test]
fn native_frame_dimensions_are_padded_to_even() {
// A scaled compositor can report an odd logical desktop (e.g. two stacked 150% monitors →
// 2560x2507); H.264/HEVC 4:2:0 encoders reject odd dimensions, so a native-size capture
// with a known odd size gets a pad filter. Even sizes, explicit output scaling and the
// fixed-input probe (size unknown) keep their existing filter chains.
let native = VideoSettings { output: None, ..Default::default() };
let pad = "pad=ceil(iw/2)*2:ceil(ih/2)*2:0:0:black";
for encoder in [Encoder::Cpu, Encoder::Nvenc] {
assert_eq!(scale_options(&native, encoder, Some((2560, 2507))), vec!["-vf".to_string(), pad.to_string()]);
assert!(scale_options(&native, encoder, Some((2560, 2508))).is_empty());
assert!(scale_options(&native, encoder, None).is_empty());
}
assert_eq!(scale_options(&native, Encoder::Vaapi, Some((2560, 2507))),
vec!["-vf".to_string(), format!("{pad},format=nv12,hwupload")]);
assert_eq!(scale_options(&native, Encoder::Vaapi, Some((2560, 2508))),
vec!["-vf".to_string(), "format=nv12,hwupload".to_string()]);
let scaled = VideoSettings { output: Some((1280, 720)), ..Default::default() };
assert_eq!(scale_options(&scaled, Encoder::Cpu, Some((2560, 2507))),
vec!["-vf".to_string(), "scale=1280:720:flags=bilinear".to_string()]);
}
#[test]
fn fixed_input_arguments_share_production_encoding_options() {
let spec=FfmpegSpec {program:"ffmpeg".into(),ld_library_path:None,path:None};
@@ -922,7 +1059,7 @@ mod tests {
let args:Vec<_>=command.as_std().get_args().map(|a|a.to_str().unwrap().to_owned()).collect();
let expected=encoder_options(&settings,encoder,&gop_frames(30,false).to_string(),None);
assert!(args.windows(expected.len()).any(|w|w==expected));
let scale=scale_options(&settings,encoder);
let scale=scale_options(&settings,encoder,None);
assert!(args.windows(scale.len()).any(|w|w==scale));
assert!(args.windows(4).any(|w|w==["-r","30","-i","frames/%05d.png"]));
assert!(args.windows(2).any(|w|w==["-frames:v","17"]));
@@ -974,7 +1111,7 @@ mod tests {
let mut gate=DependencyGate::default();
for sequence in 1..=2 {
let permit=budget.clone().acquire_owned().await.unwrap();
gate.submit(&tx,Arc::new(CompleteFrame {codec:VideoCodec::H264,sequence,completed_at:Instant::now(),
gate.submit(&tx,Arc::new(CompleteFrame { source_generation: 0, source_id: 0,codec:VideoCodec::H264,sequence,completed_at:Instant::now(),
data:vec![0,0,1,5,42],_permit:Some(permit)}));
}
let sending=rx.recv().await.unwrap();
@@ -1066,6 +1203,20 @@ mod tests {
assert_eq!(buffer_kbits(30_000, Encoder::Cpu), 8000);
}
#[test]
fn vaapi_buffer_env_is_opt_in_and_bounded() {
assert_eq!(vaapi_buffer_kbits(30_000, None), None);
assert_eq!(vaapi_buffer_kbits(30_000, Some("250")), Some(7500));
assert_eq!(vaapi_buffer_kbits(30_000, Some(" 10 ")), Some(300));
assert_eq!(vaapi_buffer_kbits(30_000, Some("1000")), Some(30_000));
// Out of the documented range, empty or unparsable keeps the default buffer.
for value in ["", "9", "1001", "0", "abc", "-250", "250ms"] {
assert_eq!(vaapi_buffer_kbits(30_000, Some(value)), None, "{value}");
}
// A tiny cap must not produce a zero-sized buffer.
assert_eq!(vaapi_buffer_kbits(1, Some("10")), Some(1));
}
#[test]
fn vaapi_is_explicit_and_upload_follows_scale() {
assert_eq!(Encoder::from_setting(None, true), Encoder::Nvenc);
@@ -1094,7 +1245,7 @@ mod tests {
let (tx, mut rx) = mpsc::channel(4);
let old_tx = tx.clone();
let (started_tx, started_rx) = tokio::sync::oneshot::channel();
let frame = |sequence, idr| Arc::new(CompleteFrame { _permit: None,
let frame = |sequence, idr| Arc::new(CompleteFrame { source_generation: 0, source_id: 0, _permit: None,
sequence, codec: VideoCodec::H264, completed_at: Instant::now(),
data: vec![0, 0, 1, 9, 240, 0, 0, 1, if idr { 5 } else { 1 }, 42],
});
@@ -1189,7 +1340,7 @@ mod tests {
async fn bounded_queue_never_sends_broken_prediction_chain_after_overload(){
let(tx,mut rx)=mpsc::channel(1);
let mut gate=DependencyGate::default();
let frame=|sequence,idr|Arc::new(CompleteFrame{_permit:None,sequence,codec:VideoCodec::H264,completed_at:Instant::now(),data:vec![0,0,1,9,240,0,0,1,if idr{5}else{1},42]});
let frame=|sequence,idr|Arc::new(CompleteFrame{source_generation:0,source_id:0,_permit:None,sequence,codec:VideoCodec::H264,completed_at:Instant::now(),data:vec![0,0,1,9,240,0,0,1,if idr{5}else{1},42]});
gate.submit(&tx,frame(1,false));assert!(rx.try_recv().is_err()); // no IDR yet
gate.submit(&tx,frame(2,true));
gate.submit(&tx,frame(3,false)); // queue full: P3 lost
@@ -1207,7 +1358,7 @@ mod tests {
#[test]
fn hevc_annex_b_boundaries_and_irap_use_two_byte_headers() {
let bytes = [0,0,0,1,70,1,80,0,0,1,64,1,42,0,0,1,38,1,42,0,0,1,70,1,80];
assert_eq!(aud_offsets_for(&bytes, VideoCodec::H265), vec![0,19]);
assert_eq!(au_offsets_for(&bytes, VideoCodec::H265), vec![0,19]);
assert!(is_independent_frame_for(&bytes[..19], VideoCodec::H265));
for kind in 16..=21 {
assert!(is_independent_frame_for(&[0,0,1,kind << 1,1,42], VideoCodec::H265));
@@ -1218,11 +1369,32 @@ mod tests {
assert!(!is_independent_frame_for(&[0,0,1,166,1,42], VideoCodec::H265));
assert!(!is_independent_frame_for(&[0,0,1,38,1,42,0,0,1,2,1,42], VideoCodec::H265));
}
#[test]
fn hevc_access_units_do_not_depend_on_aud_placement() {
// VAAPI writes an AUD only at IRAPs: AUD VPS SPS PPS IDR, then one P per picture.
let vaapi = [0,0,0,1,70,1,0x80, 0,0,0,1,64,1,0x42, 0,0,0,1,66,1,0x42,
0,0,0,1,68,1,0x42, 0,0,0,1,38,1,0x80, 0,0,0,1,2,1,0x80, 0,0,0,1,2,1,0x80];
assert_eq!(hevc_au_offsets(&vaapi), vec![0, 35, 42]);
// x265/nvenc style: an AUD in front of every picture.
let with_aud = [0,0,0,1,70,1,0x80, 0,0,0,1,64,1,0x42, 0,0,0,1,38,1,0x80,
0,0,0,1,70,1,0x80, 0,0,0,1,2,1,0x80, 0,0,0,1,70,1,0x80, 0,0,0,1,2,1,0x80];
assert_eq!(hevc_au_offsets(&with_aud), vec![0, 21, 35]);
// A picture split over several slices stays one access unit.
let multi_slice = [0,0,0,1,38,1,0x80, 0,0,0,1,38,1,0x00, 0,0,0,1,2,1,0x80];
assert_eq!(hevc_au_offsets(&multi_slice), vec![0, 14]);
// Truncated/invalid NALs must not invent boundaries. An invalid header is skipped, and
// the first valid NAL after it still opens the first unit.
assert_eq!(hevc_au_offsets(&[0,0,1,70]), Vec::<usize>::new());
assert_eq!(hevc_au_offsets(&[0,0,1,128,1,0x80]), Vec::<usize>::new());
assert_eq!(hevc_au_offsets(&[0,0,1,128,1,0x80, 0,0,1,2,1,0x80]), vec![6]);
// A suffix SEI (40) after a picture stays in that picture's unit; the next slice opens the next one.
assert_eq!(hevc_au_offsets(&[0,0,1,0x26,1,0x80, 0,0,1,0x50,1,0x05, 0,0,1,0x02,1,0x80]), vec![0, 12]);
}
#[tokio::test]
async fn hevc_dependency_gate_recovers_only_at_irap_after_overflow() {
let (tx, mut rx) = mpsc::channel(1);
let mut gate = DependencyGate::default();
let frame = |sequence, irap| Arc::new(CompleteFrame { _permit: None, codec: VideoCodec::H265,
let frame = |sequence, irap| Arc::new(CompleteFrame { source_generation: 0, source_id: 0, _permit: None, codec: VideoCodec::H265,
sequence, completed_at: Instant::now(), data: vec![0,0,1,if irap { 38 } else { 2 },1,42] });
gate.submit(&tx, frame(1, false));
assert!(rx.try_recv().is_err());
@@ -1250,6 +1422,8 @@ mod tests {
for pair in [["-c:v", "hevc_vaapi"], ["-profile:v", "main"], ["-bf", "0"], ["-bufsize", "500k"]] {
assert!(vaapi.windows(2).any(|window| window == pair));
}
// hevc_vaapi with -aud drops every non-IRAP picture, so H.265 must not ask for AUDs.
assert!(!vaapi.iter().any(|option| option == "-aud"));
assert_eq!(Encoder::Nvenc.name_for(VideoCodec::H265), "hevc_nvenc");
assert_eq!(Encoder::Cpu.name_for(VideoCodec::H264), "libx264");
}
@@ -1261,3 +1435,18 @@ mod tests {
assert!(!is_independent_frame(&[0,0,0,1,9,48,0,0,1,1,154]));
}
}
#[cfg(test)]
mod screen_frame_tests {
use super::*;
#[test]
fn source_restart_rejects_queued_frames_even_with_same_screen_and_codec() {
let frame=CompleteFrame {source_id:0,source_generation:7,codec:VideoCodec::H264,sequence:1,completed_at:Instant::now(),data:vec![],_permit:None};
let mut settings=VideoSettings {source_id:0,source_generation:7,..Default::default()};
assert!(frame.matches(&settings));
settings.source_generation=9;assert!(!frame.matches(&settings));
settings.source_generation=7;settings.source_id=1;assert!(!frame.matches(&settings));
settings.source_id=0;settings.codec=VideoCodec::H265;assert!(!frame.matches(&settings));
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ pub struct Api {
}
impl Api {
pub fn new(signer: UUAuthClient, base: &str) -> Self {
Self { signer, base: base.trim_end_matches('/').into(), http: reqwest::Client::builder().timeout(Duration::from_secs(12)).build().unwrap() }
Self { signer, base: base.trim_end_matches('/').into(), http: crate::auth::http_client_builder().timeout(Duration::from_secs(12)).build().unwrap() }
}
pub async fn join_share(&self, connect_id: &str, connect_code: &str) -> Result<JoinData, Error> {
if connect_id.trim().is_empty() || connect_code.trim().is_empty() || connect_id.chars().chain(connect_code.chars()).any(char::is_control) { return Err(Error::InvalidAssist); }
+211 -1
View File
@@ -1,6 +1,7 @@
//! Hyprland/wlroots native backend. No XWayland fallback and no input logging.
#[cfg(all(target_os="linux", feature="wayland"))]
extern "C" {
crate::engine_ffi! { crate::engine_plugin::Engine::Wayland;
fn uu_wl_select_output(name: *const libc::c_char, width: u32, height: u32) -> i32;
fn uu_wl_init(out_w: *mut i32, out_h: *mut i32) -> i32;
fn uu_wl_capture(buffer: *mut u8, length: usize) -> i32;
fn uu_wl_move(x: i32, y: i32, relative: i32) -> i32;
@@ -8,6 +9,26 @@ extern "C" {
fn uu_wl_key(symbol: u64, pressed: i32) -> i32;
fn uu_wl_wake() -> i32;
fn uu_wl_release_all() -> i32;
fn uu_wl_type_utf8(text: *const libc::c_char) -> i32;
fn uu_wl_text_ready() -> i32;
}
/// How many characters one keymap upload can carry; 0 means this keymap has no spare keycode.
pub fn text_ready()->i32 {
#[cfg(all(target_os="linux",feature="wayland"))]
{ return unsafe { uu_wl_text_ready() }; }
#[cfg(not(all(target_os="linux",feature="wayland")))]
-1
}
/// Mobile input-method text (#13/#46). Returns the number of characters typed, or a negative code
/// when this keymap has no spare keycode to carry them. Never logs the text.
pub fn type_utf8(text:&str)->i32 {
#[cfg(all(target_os="linux",feature="wayland"))]
{
let Ok(c_text)=std::ffi::CString::new(text.replace('\0',"")) else { return -1 };
return unsafe { uu_wl_type_utf8(c_text.as_ptr()) };
}
#[cfg(not(all(target_os="linux",feature="wayland")))]
{ let _=text; -1 }
}
pub fn release_all()->i32 {
#[cfg(all(target_os="linux",feature="wayland"))]
@@ -18,11 +39,19 @@ pub fn release_all()->i32 {
pub fn init() -> Result<(u32,u32),String> {
#[cfg(all(target_os="linux", feature="wayland"))]
{
crate::engine_plugin::load(crate::engine_plugin::Engine::Wayland).map_err(|reason| format!("Wayland engine unavailable: {reason}"))?;
let (mut w,mut h)=(0,0);
let result=unsafe { uu_wl_init(&mut w,&mut h) };
if result != 0 || w <= 0 || h <= 0 {
return Err(format!("Wayland initialization failed ({result}); requires screencopy, virtual keyboard and virtual pointer. Check UU_WAYLAND_OUTPUT and session environment."));
}
// The compositor registry and hyprctl need not enumerate outputs in the
// same order. Bind the initial engine to the inventory's selected output.
static BINDING: std::sync::OnceLock<Result<(),String>>=std::sync::OnceLock::new();
if !outputs().is_empty() {
BINDING.get_or_init(||select(0)).as_ref().map_err(Clone::clone)?;
return Ok(input_size((w as u32,h as u32)));
}
return Ok((w as u32,h as u32));
}
#[cfg(not(all(target_os="linux", feature="wayland")))]
@@ -144,3 +173,184 @@ pub fn input_probe()->Result<(),String> {
println!("Wayland test events sent; verify the native GTK acceptance report.");
Ok(())
}
/// Local diagnostic for the mobile-text path: report the keymap's capacity for it, then type a
/// sample into the focused window. Only the built-in sample is echoed; UU_PROBE_TEXT stays private.
pub fn text_probe()->Result<(),String> {
init()?;
let ready=text_ready();
if ready<=0 { return Err("this keymap has no spare keycode: mobile text input cannot be carried".into()); }
const SAMPLE:&str="uu remote abc 你好世界";
let (sample,builtin)=match std::env::var("UU_PROBE_TEXT") {
Ok(value)=>(value,false), Err(_)=>(SAMPLE.to_owned(),true),
};
println!("Wayland text probe: spare keycodes={ready} characters={} bytes={}",sample.chars().count(),sample.len());
if builtin { println!("Sample: {sample}"); }
// UU_PROBE_SEQUENCE types each |-separated field as its own call - one text_input message each,
// the way the phone's input method sends them - with UU_PROBE_STEP_MS between the calls. One
// process means one virtual keyboard, exactly as the host has.
let step=std::env::var("UU_PROBE_STEP_MS").ok().and_then(|v|v.parse::<u64>().ok()).unwrap_or(0);
let sequence=std::env::var("UU_PROBE_SEQUENCE").unwrap_or_else(|_|sample.clone());
let mut typed=0;
for (index,message) in sequence.split('|').enumerate() {
if index>0 && step>0 { std::thread::sleep(std::time::Duration::from_millis(step)); }
let one=type_utf8(message);
if one<0 { return Err(format!("Wayland text typing failed ({one})")); }
typed+=one;
}
if typed<0 { return Err(format!("Wayland text typing failed ({typed})")); }
println!("Typed {typed} of {} characters in {} calls; check that they match.",
sequence.chars().filter(|character|*character!='|').count(),sequence.split('|').count());
Ok(())
}
// Opt-in single-track monitor switching for Hyprland. The existing native engine owns
// capture/pointer binding; no compositor layout or user credentials are modified.
#[derive(Clone, Debug)]
pub struct Output { pub name:String, pub width:u32, pub height:u32, pub fps:i32 }
static OUTPUTS: std::sync::OnceLock<Vec<Output>> = std::sync::OnceLock::new();
#[derive(Default)]
struct Selection { id:usize, generation:u64, presented:Option<u64>, failed:bool }
impl Selection {
fn begin(&mut self,id:usize) {
self.id=id; self.generation+=1; self.presented=None; self.failed=false;
}
fn sent(&mut self,id:usize,generation:u64) {
if (self.id,self.generation)==(id,generation) {self.presented=Some(generation);}
}
fn ready(&self)->bool {self.presented==Some(self.generation)}
}
static SELECTION:std::sync::Mutex<Selection>=std::sync::Mutex::new(Selection {id:0,generation:0,presented:None,failed:false});
pub fn outputs() -> &'static [Output] {
OUTPUTS.get_or_init(|| {
if !cfg!(all(target_os="linux",feature="wayland"))
|| std::env::var("UU_WAYLAND_MULTISCREEN").ok().as_deref()!=Some("1")
|| crate::desktop_backend::detect().ok()!=Some(crate::desktop_backend::DesktopBackend::Wayland) {return Vec::new();}
let output=std::process::Command::new("hyprctl").args(["monitors","-j"]).output();
let result=output.map_err(|_|"hyprctl unavailable").and_then(|output| {
if !output.status.success() {return Err("hyprctl failed");}
parse_outputs(&output.stdout,&std::env::var("UU_WAYLAND_OUTPUT").unwrap_or_default())
});
match result {Ok(outputs)=>outputs,Err(reason)=>{log::warn!("Wayland multi-screen disabled: {}",reason);Vec::new()}}
})
}
fn parse_outputs(json:&[u8],preferred:&str)->Result<Vec<Output>,&'static str> {
let monitors=serde_json::from_slice::<Vec<serde_json::Value>>(json).map_err(|_|"Invalid monitor inventory")?;
let mut seen=std::collections::HashSet::new();
let mut outputs:Vec<Output>=monitors.into_iter().filter_map(|m| {
if m["disabled"].as_bool()==Some(true) || m["transform"].as_u64()!=Some(0) {return None;}
let name=m["name"].as_str()?;
let width=u32::try_from(m["width"].as_u64()?).ok()?;
let height=u32::try_from(m["height"].as_u64()?).ok()?;
if name.is_empty() || name.len()>127 || name.contains('\0') || !seen.insert(name.to_owned())
|| width<2 || height<2 || width>16384 || height>16384 || u64::from(width)*u64::from(height)*4>256*1024*1024 {return None;}
Some(Output {name:name.into(),width,height,fps:m["refreshRate"].as_f64()?.round().clamp(1.0,240.0) as i32})
}).collect();
outputs.sort_by_key(|m| (m.name!=preferred,m.name.clone()));
outputs.truncate(16);
if outputs.is_empty() || (!preferred.is_empty() && outputs[0].name!=preferred) {return Err("No capturable preferred output");}
Ok(outputs)
}
pub fn selection()->(usize,u64) {let s=SELECTION.lock().unwrap();(s.id,s.generation)}
pub fn selected()->usize {selection().0}
pub fn source(id:usize)->Option<&'static Output> {outputs().get(id)}
pub fn input_size(fallback:(u32,u32))->(u32,u32) {source(selected()).map_or(fallback,|s|(s.width,s.height))}
pub fn input_ready()->bool {outputs().is_empty() || SELECTION.lock().unwrap().ready()}
pub fn switch_failed()->bool {SELECTION.lock().unwrap().failed}
pub fn presented(id:usize,generation:u64) {SELECTION.lock().unwrap().sent(id,generation);}
pub fn failed(id:usize,generation:u64) {
let mut state=SELECTION.lock().unwrap();
if (state.id,state.generation)==(id,generation) {state.failed=true;}
}
pub fn select(id:usize)->Result<(),String> {
let output=source(id).ok_or("Unknown Wayland screen")?;
#[cfg(all(target_os="linux",feature="wayland"))]
{
let name=std::ffi::CString::new(output.name.as_str()).map_err(|_|"Invalid output name")?;
let mut state=SELECTION.lock().unwrap();
if unsafe {uu_wl_select_output(name.as_ptr(),output.width,output.height)}!=0 {return Err("Wayland output switch failed".into());}
state.begin(id);
log::info!("Wayland screen selected: id={} source={}x{}",id,output.width,output.height);
Ok(())
}
#[cfg(not(all(target_os="linux",feature="wayland")))]
{let _=output;Err("Wayland output switching unavailable".into())}
}
/// CaptureSettingRequest.screen_id is field 4 (rpc_main.proto); official desktop
/// activation also uses SimpleAction 8 {"screen_id":id}. Reference: openuuyc main
/// a87b8e7, stream_control/wire.rs and publisher/displays.rs (Windows S456070).
/// https://github.com/djkcyl/openuuyc/tree/a87b8e772c238e542215ab039f1b1d2ca4a9ef46/src/features/stream_control
/// Official phone acceptance on Hyprland: field 4 selected each advertised id;
/// current-source settings used the signed value -1.
pub fn requested_output(data:&[u8]) -> Option<usize> {
use crate::protocol::{decode_wire,WireValue};
let outer=decode_wire(data).ok()?;
fn bytes<'a>(fields:&[crate::protocol::WireField<'a>],n:u32)->Option<&'a [u8]> {fields.iter().find_map(|f|match f.value {WireValue::Bytes(b) if f.number==n=>Some(b),_=>None})}
if let Some(rpc)=bytes(&outer,21) {
let rpc=decode_wire(rpc).ok()?;
let request=decode_wire(bytes(&rpc,2)?).ok()?;
let id=request.iter().find_map(|f|match f.value {WireValue::Varint(v) if f.number==4=>Some(v as i64),_=>None}).unwrap_or(0);
return usize::try_from(id).ok();
}
let action=decode_wire(bytes(&outer,3)?).ok()?;
let kind=action.iter().find_map(|f|match f.value {WireValue::Varint(v) if f.number==1=>Some(v),_=>None})?;
if kind!=8 {return None;}
let args:serde_json::Value=serde_json::from_slice(bytes(&action,2)?).ok()?;
usize::try_from(args["screen_id"].as_i64()?).ok()
}
#[cfg(test)]
mod monitor_switch_tests {
use super::*;
#[test]
fn capture_setting_screen_zero_and_signed_current_target() {
// Message.rpc_request(21), RpcRequest.capture_setting(2), screen_id(4).
let request=|payload:&[u8]| {let mut rpc=vec![18,payload.len() as u8];rpc.extend(payload);crate::initialization::envelope(1,2,21,&rpc)};
assert_eq!(requested_output(&request(&[32,1])),Some(1));
assert_eq!(requested_output(&request(&[])),Some(0));
assert_eq!(requested_output(&request(&[32,255,255,255,255,255,255,255,255,255,1])),None);
assert_eq!(requested_output(b"not protobuf"),None);
}
#[test]
fn only_explicit_desktop_restart_selects_an_output() {
let request=|action:u8,args:&str| {let mut sa=vec![8,action,18,args.len() as u8];sa.extend(args.bytes());crate::initialization::envelope(1,2,3,&sa)};
assert_eq!(requested_output(&request(8,r#"{"screen_id":1}"#)),Some(1));
assert_eq!(requested_output(&request(8,r#"{"screen_id":-1}"#)),None);
assert_eq!(requested_output(&request(7,r#"{"screen_id":1}"#)),None);
}
}
#[cfg(test)]
mod selection_regressions {
use super::*;
#[test]
fn old_frames_cannot_unlock_a_return_to_the_same_screen() {
let mut s=Selection::default();
s.begin(0);let old=s.generation;s.sent(0,old);assert!(s.ready());
s.begin(1);assert!(!s.ready());s.sent(0,old);assert!(!s.ready());
s.begin(0);let current=s.generation;
s.sent(0,old);assert!(!s.ready());
s.sent(1,current);assert!(!s.ready());
s.sent(0,current);assert!(s.ready());
}
#[test]
fn mixed_scale_inventory_preserves_pixel_sizes_and_preferred_output() {
let json=br#"[{"name":"eDP-1","width":1920,"height":1080,"scale":1.3333334,"transform":0,"refreshRate":144},
{"name":"HDMI-A-1","width":2560,"height":1440,"scale":1.25,"transform":0,"refreshRate":75}]"#;
let outputs=parse_outputs(json,"HDMI-A-1").unwrap();
assert_eq!(outputs.iter().map(|m|(m.name.as_str(),m.width,m.height)).collect::<Vec<_>>(),
vec![("HDMI-A-1",2560,1440),("eDP-1",1920,1080)]);
assert!(parse_outputs(json,"missing-output").is_err());
}
#[test]
fn unusable_outputs_are_not_advertised() {
let json=br#"[{"name":"rotated","width":1920,"height":1080,"transform":1,"refreshRate":60},
{"name":"too-large","width":16000,"height":16000,"transform":0,"refreshRate":60},
{"name":"off","width":1920,"height":1080,"disabled":true,"transform":0,"refreshRate":60},
{"name":"normal","width":1920,"height":1080,"transform":0,"refreshRate":60}]"#;
let outputs=parse_outputs(json,"").unwrap();
assert_eq!(outputs.len(),1);assert_eq!(outputs[0].name,"normal");
assert!(parse_outputs(b"not JSON","").is_err());
}
}
+97 -11
View File
@@ -177,10 +177,27 @@ impl WebRtcSession {
tokio::spawn(async move {
let ctx = ctx.lock().await.clone();
if let (Some(client), Some(ice)) = (&ctx.client_id, ctx.ice_id.as_ref().and_then(|v| v.as_str())) {
let payload = crate::capability::device_capability(client, ice, 0, crate::video::display_fps() as i32, 5, hevc);
let encoder = crate::video::Encoder::requested();
let codec_impl = if encoder == crate::video::Encoder::Nvenc { crate::capability::CODEC_IMPL_NVENC } else { 5 };
let payload = crate::capability::device_capability(client, ice, 0, crate::video::display_fps() as i32, codec_impl,
hevc, crate::video::full_chroma_available());
if let Err(e) = sig.emit_event(crate::capability::FORWARD_SETTING_EVENT, payload).await {
log::error!("Device capability notification failed: {}", e);
}
let capture_impl = match crate::desktop_backend::detect() {
Ok(crate::desktop_backend::DesktopBackend::Portal) => "PipeWire",
Ok(crate::desktop_backend::DesktopBackend::Wayland) => "Wayland",
_ => "X11",
};
let encoder_impl = match encoder {
crate::video::Encoder::Nvenc => "NVIDIA NVENC",
crate::video::Encoder::Vaapi => "VAAPI",
crate::video::Encoder::Cpu => "Software",
};
if let Err(e) = sig.emit_event(crate::capability::FORWARD_SETTING_EVENT,
crate::capability::sender_para_info(client, ice, capture_impl, encoder_impl)).await {
log::error!("Sender parameter notification failed: {}", e);
}
if let Some(control) = ctx.app_control_id.as_ref().and_then(|v| v.as_str()) {
if let Err(e) = sig.emit_event(crate::capability::ICE_FINISHED_EVENT,
crate::capability::ice_finished(ice, control)).await {
@@ -374,11 +391,14 @@ impl WebRtcSession {
});
}
// Settings arrive on CONTROL or TEXT; serialize both queues for this peer.
let settings_serial=Arc::new(Mutex::new(()));
// 监听 DataChannel
pc.on_data_channel(Box::new(move |d: Arc<RTCDataChannel>| {
let label = d.label().to_string();
log::info!("New DataChannel received: {}", label);
let peer_settings_serial=settings_serial.clone();
let input_inst = input_clone.clone();
let channel_input_session=input_session.clone();
let screen = control_capture.clone();
@@ -428,7 +448,7 @@ impl WebRtcSession {
});
}
let (capture_tx, mut capture_rx) = tokio::sync::mpsc::channel::<Vec<u8>>(16);
if label == "CONTROL_DATA_CHANNEL" {
if matches!(label.as_str(),"CONTROL_DATA_CHANNEL"|"TEXT_DATA_CHANNEL") {
let settings = channel_video_settings.clone();
let track = peer_video_track.clone();
let response_tx = outbound.clone();
@@ -436,6 +456,8 @@ impl WebRtcSession {
let manager = portal_desktop.clone();
let channel = Arc::downgrade(&d);
let initial_screen = screen.clone();
let switch_owner=channel_input_session.clone();
let settings_serial=peer_settings_serial.clone();
tokio::spawn(async move {
let mut health = tokio::time::interval(std::time::Duration::from_millis(100));
loop {
@@ -450,6 +472,36 @@ impl WebRtcSession {
continue;
}
};
let _serial=settings_serial.lock().await;
if desktop && switch_owner.as_ref().is_none_or(|owner|!owner.is_current()) {continue;}
let reject=|reason:&str| {
if let Some(response)=crate::capture_setting::rejected_request(&request,reason) {
let ts=std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs();
let _=response_tx.send(crate::initialization::envelope(sequence.fetch_add(1,std::sync::atomic::Ordering::Relaxed),ts,22,&response));
}
};
let source_before=crate::wayland::selected();
let settings_before=*settings.borrow();
if desktop && !crate::wayland::outputs().is_empty() {
if let Some(id)=crate::wayland::requested_output(&request) {
if crate::wayland::source(id).is_none() {reject("Unknown screen");continue;}
if id!=source_before {
let mut changed=false;
if let Some(owner)=&switch_owner {owner.with_current(|| {
owner.release_input();
match crate::wayland::select(id) {
Ok(())=>{
let (source_id,source_generation)=crate::wayland::selection();
settings.send_modify(|s|{s.source_id=source_id;s.source_generation=source_generation;s.output=None;});
changed=true;
},
Err(error)=>{log::warn!("Screen switch rejected: {}",error);reject(&error);},
}
});}
if !changed {continue;}
}
}
}
let active_screen = if desktop {
if let Some(manager) = &manager {
loop {
@@ -475,6 +527,33 @@ impl WebRtcSession {
let input_size = if active_screen.init_error.is_none() {
(active_screen.width, active_screen.height)
} else { (1920, 1080) };
let input_size=crate::wayland::input_size(input_size);
let source_changed=source_before!=crate::wayland::selected();
if source_changed {
let target=crate::wayland::selection();
let deadline=tokio::time::Instant::now()+std::time::Duration::from_secs(10);
while crate::wayland::selection()==target && !crate::wayland::input_ready()
&& !crate::wayland::switch_failed() && tokio::time::Instant::now()<deadline {
if channel.upgrade().is_none_or(|c|c.ready_state()!=webrtc::data_channel::data_channel_state::RTCDataChannelState::Open)
|| switch_owner.as_ref().is_none_or(|owner|!owner.is_current()) {return;}
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
if switch_owner.as_ref().is_none_or(|owner|!owner.is_current()) || crate::wayland::selection()!=target {continue;}
if !crate::wayland::input_ready() {
if let Some(owner)=&switch_owner {owner.with_current(|| {
if crate::wayland::selection()==target && crate::wayland::select(source_before).is_ok() {
let (source_id,source_generation)=crate::wayland::selection();
settings.send_replace(crate::capture_setting::VideoSettings {source_id,source_generation,..settings_before});
}
});}
log::warn!("Screen switch failed; previous source requested");
reject("Screen switch failed; restoring previous screen");
continue;
}
let ts=std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs();
if let Ok(message)=crate::capture_setting::screen_sources(sequence.fetch_add(1,std::sync::atomic::Ordering::Relaxed),ts,input_size,None,"Linux desktop") {let _=response_tx.send(message);}
if let Ok(message)=crate::initialization::encode_capture_change(sequence.fetch_add(1,std::sync::atomic::Ordering::Relaxed),ts,0,crate::wayland::selected() as i32,"Linux desktop") {let _=response_tx.send(message);}
}
let Ok(fields) = crate::protocol::decode_wire(&request) else { continue; };
use crate::protocol::WireValue;
let Some(rpc) = fields.iter().find_map(|f| match (f.number, &f.value) {
@@ -484,10 +563,14 @@ impl WebRtcSession {
let before = *settings.borrow();
let output_before = before.output;
let revision = track.revision();
let Some(response) = crate::capture_setting::handle_rpc_with_codecs(
let apply=|| crate::capture_setting::handle_rpc_with_codecs(
&rpc_fields, &settings, input_size,
track.supports(crate::capture_setting::VideoCodec::H264),
track.supports(crate::capture_setting::VideoCodec::H265)) else { continue; };
track.supports(crate::capture_setting::VideoCodec::H265));
let response=if let Some(owner)=&switch_owner {
let mut response=None;owner.with_current(||response=apply());response
} else {apply()};
let Some(response)=response else {continue;};
let codec_changed = settings.borrow().codec != before.codec;
if desktop && codec_changed && !track.wait_for_applied(revision, &settings).await {
log::warn!("Codec switch did not produce a transmitted frame; success reply withheld");
@@ -628,7 +711,7 @@ impl WebRtcSession {
.duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs();
let message = crate::initialization::encode_capture_change(
sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
timestamp, 0, 0, "Linux desktop").expect("desktop capture type");
timestamp, 0, crate::wayland::selected() as i32, "Linux desktop").expect("desktop capture type");
if let Err(error) = channel.send(&bytes::Bytes::from(message)).await {
log::error!("CONTROL desktop selection failed: {error}");
return;
@@ -716,9 +799,9 @@ impl WebRtcSession {
} else { crate::system_metrics::Permission::Reject };
// Without a desktop (headless/portal before consent) the port-mapping tool still waits
// for ScreenSources/CaptureChange and aborts otherwise: tool peers get a nominal screen.
let screen_size=if screen.init_error.is_none() { (screen.width, screen.height) } else { (1920, 1080) };
let screen_size=crate::wayland::input_size(if screen.init_error.is_none() { (screen.width, screen.height) } else { (1920, 1080) });
let messages = [
(8, crate::initialization::encode_capture_change(next_seq(), timestamp, 0, 0, "Linux desktop")),
(8, crate::initialization::encode_capture_change(next_seq(), timestamp, 0, crate::wayland::selected() as i32, "Linux desktop")),
(13, Ok(crate::initialization::envelope(next_seq(), timestamp, 13, &init_actions.metrics_payload(desktop_sound, desktop_permission)))),
(26, Ok(crate::initialization::envelope(next_seq(), timestamp, 26,
&crate::system_metrics::remote_download_path(&home)))),
@@ -805,11 +888,12 @@ impl WebRtcSession {
let capture_requests = capture_tx.clone();
Box::pin(async move {
let input_size = (screen.width, screen.height);
let input_size = crate::wayland::input_size((screen.width, screen.height));
if let Some(term) = &terminal_worker {
if crate::terminal::is_frame(&msg.data) { term.handle(&msg.data); return; }
}
if channel_name == "CONTROL_DATA_CHANNEL" && is_capture_setting_message(&msg.data) {
if matches!(channel_name.as_str(),"CONTROL_DATA_CHANNEL"|"TEXT_DATA_CHANNEL")
&& (is_capture_setting_message(&msg.data) || (!crate::wayland::outputs().is_empty() && crate::wayland::requested_output(&msg.data).is_some())) {
// Back-pressure like the old inline handler instead of dropping the latest setting.
if capture_requests.send(msg.data.to_vec()).await.is_err() {
log::warn!("Capture setting queue closed; request dropped");
@@ -1053,7 +1137,7 @@ impl WebRtcSession {
}
}
if let Ok(crate::control_protocol::ControlMessage::Input(crate::control_protocol::ControlInput::TextInput {text})) = crate::control_protocol::decode_control(&msg.data) {
if let Some(session)=message_input_session.as_ref() { session.with_input(|| input_worker.text_input(&text)); }
if let Some(session)=message_input_session.as_ref() { session.with_input(|| {if crate::wayland::input_ready() {input_worker.text_input(&text);}}); }
}
}
if channel_name.contains("CONTROL") {
@@ -1061,6 +1145,7 @@ impl WebRtcSession {
Ok(crate::control_protocol::ControlMessage::Input(event)) => {
if screen.backend == crate::desktop_backend::DesktopBackend::Portal
&& (screen.init_error.is_some() || !desktop_ready || *lock_for_message.borrow() != Some(false)) { return; }
if !crate::wayland::input_ready() {return;}
use crate::control_protocol::ControlInput;
// Separate receipt budgets keep motion floods from hiding clicks.
static RECEIPTS: [std::sync::atomic::AtomicUsize; 3] = [const { std::sync::atomic::AtomicUsize::new(0) }; 3];
@@ -1073,8 +1158,9 @@ impl WebRtcSession {
log::info!("CONTROL input received: kind={}", kind);
}
if let Some(session)=message_input_session.as_ref() {session.with_input(|| {
if !crate::wayland::input_ready() {return;}
match &event {
ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,input_size),
ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,crate::wayland::input_size(input_size)),
ControlInput::MouseRelative {dx,dy} => input_worker.mouse_relative(*dx,*dy),
ControlInput::MouseScroll {dx,dy} => input_worker.mouse_scroll(*dx,*dy),
ControlInput::Keyboard {key, pressed} => input_worker.windows_key_event(*key, *pressed),