mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89abae2369 | ||
|
|
0afc602e66 | ||
|
|
762cfccc44 | ||
|
|
9520b69730 | ||
|
|
c45e4749b5 | ||
|
|
c1b8bfe1b3 |
No files matched your search
@@ -39,7 +39,8 @@ Dependencies (Ubuntu/Debian):
|
|||||||
sudo apt install build-essential pkg-config \
|
sudo apt install build-essential pkg-config \
|
||||||
libx11-dev libxext-dev libxtst-dev libxfixes-dev libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev libgtk-3-dev ffmpeg
|
libx11-dev libxext-dev libxtst-dev libxfixes-dev libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev libgtk-3-dev ffmpeg
|
||||||
# --features inproc-av: libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev
|
# --features inproc-av: libavcodec-dev libavformat-dev libavdevice-dev libswscale-dev libclang-dev
|
||||||
# (FFmpeg 6.x; in-process capture/encoding, Ubuntu 24.04 ships it)
|
# (FFmpeg 6.x only; in-process capture/encoding, Ubuntu 24.04 ships it. FFmpeg >= 7
|
||||||
|
# fails in ffmpeg-sys-next with "avfft.h file not found", before our build.rs runs)
|
||||||
# --features wayland: libwayland-dev libxkbcommon-dev wl-clipboard
|
# --features wayland: libwayland-dev libxkbcommon-dev wl-clipboard
|
||||||
# --features wayland,portal: + libglib2.0-dev libpipewire-0.3-dev libei-dev (libei >= 1.1)
|
# --features wayland,portal: + libglib2.0-dev libpipewire-0.3-dev libei-dev (libei >= 1.1)
|
||||||
```
|
```
|
||||||
|
|||||||
Generated
+1
-1
@@ -2741,7 +2741,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.18"
|
version = "0.2.19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.18"
|
version = "0.2.19"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "uuremote-server"
|
default-run = "uuremote-server"
|
||||||
authors = ["uu-remote-linux contributors"]
|
authors = ["uu-remote-linux contributors"]
|
||||||
|
|||||||
@@ -187,6 +187,11 @@ cargo build --release --features wayland # + Hyprland
|
|||||||
cargo build --release --features wayland,portal # + GNOME/KDE on Wayland
|
cargo build --release --features wayland,portal # + GNOME/KDE on Wayland
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The optional `--features inproc-av` (in-process encoding) and the viewer's `viewer-ffmpeg` support **FFmpeg 6.x only**
|
||||||
|
(`pkg-config --modversion libavcodec` = 60.x). FFmpeg 7+ fails inside the `ffmpeg-sys-next` dependency with
|
||||||
|
`avfft.h file not found`; its build script runs before this project's, so no clearer check is possible (#63). The default
|
||||||
|
build and the release packages need neither feature.
|
||||||
|
|
||||||
### 3. Log in
|
### 3. Log in
|
||||||
|
|
||||||
Run inside your graphical session:
|
Run inside your graphical session:
|
||||||
@@ -339,6 +344,8 @@ Common environment variables:
|
|||||||
Host settings such as "lock after remote session" and "mute host" are stored in
|
Host settings such as "lock after remote session" and "mute host" are stored in
|
||||||
`~/.config/uuremote/host_settings.json`.
|
`~/.config/uuremote/host_settings.json`.
|
||||||
|
|
||||||
|
Custom bitrate follows the Mbps value selected in the client; for example, 1 Mbps sets an encoder cap of 1000 kbit/s.
|
||||||
|
|
||||||
With external FFmpeg CPU encoding, the bitrate presets (Original / Ultra / HD / custom) use average bitrate (ABR) to avoid gray keyframes at 4K and low bitrates; Auto keeps constant rate factor (CRF).
|
With external FFmpeg CPU encoding, the bitrate presets (Original / Ultra / HD / custom) use average bitrate (ABR) to avoid gray keyframes at 4K and low bitrates; Auto keeps constant rate factor (CRF).
|
||||||
|
|
||||||
## Let an AI agent install or develop it
|
## Let an AI agent install or develop it
|
||||||
|
|||||||
@@ -171,6 +171,10 @@ cargo build --release --features wayland # + Hyprland
|
|||||||
cargo build --release --features wayland,portal # + GNOME/KDE Wayland
|
cargo build --release --features wayland,portal # + GNOME/KDE Wayland
|
||||||
```
|
```
|
||||||
|
|
||||||
|
可选的 `--features inproc-av`(进程内编码)和控制端的 `viewer-ffmpeg` 只支持 **FFmpeg 6.x**(`pkg-config --modversion libavcodec` 为 60.x)。
|
||||||
|
FFmpeg 7 及以上会在依赖 `ffmpeg-sys-next` 里报 `avfft.h file not found`——它的构建脚本先于本项目运行,所以无法提前给出更清楚的提示(#63)。
|
||||||
|
默认构建和预编译包都不需要这两个特性。
|
||||||
|
|
||||||
### 3. 登录
|
### 3. 登录
|
||||||
|
|
||||||
在图形桌面里运行:
|
在图形桌面里运行:
|
||||||
@@ -308,6 +312,8 @@ systemctl --user restart uuremote-native.service
|
|||||||
|
|
||||||
「远程结束后自动锁屏」「静音运行」等设置保存在 `~/.config/uuremote/host_settings.json`。
|
「远程结束后自动锁屏」「静音运行」等设置保存在 `~/.config/uuremote/host_settings.json`。
|
||||||
|
|
||||||
|
自定义码率按客户端选择的 Mbps 生效,例如 1 Mbps 对应 1000 kbit/s 的编码上限。
|
||||||
|
|
||||||
选择码率档(原画 / 超清 / 高清 / 自定义)时,外部 FFmpeg 的 CPU 编码以平均码率(ABR)为目标,避免 4K 低码率下关键帧发灰;「自动」档仍使用恒定质量(CRF)。
|
选择码率档(原画 / 超清 / 高清 / 自定义)时,外部 FFmpeg 的 CPU 编码以平均码率(ABR)为目标,避免 4K 低码率下关键帧发灰;「自动」档仍使用恒定质量(CRF)。
|
||||||
|
|
||||||
本地编码诊断 `desktop-video-probe [output.h264]` 可设置 `UU_PROBE_FPS`、`UU_PROBE_FRAMES`(默认 5)和 `UU_PROBE_QUALITY`(1–5);设置 `UU_PROBE_INPUT=clip.y4m`(也支持 `.mp4`、`frames/%05d.png`)可绕过桌面采集,以相同的生产 FFmpeg 编码参数测量固定输入并打印分辨率和编码统计,`UU_PROBE_LOOP=1` 循环到指定帧数,输入无法打开或帧数不足时以非零状态退出(固定输入始终使用外部 FFmpeg 管线)。
|
本地编码诊断 `desktop-video-probe [output.h264]` 可设置 `UU_PROBE_FPS`、`UU_PROBE_FRAMES`(默认 5)和 `UU_PROBE_QUALITY`(1–5);设置 `UU_PROBE_INPUT=clip.y4m`(也支持 `.mp4`、`frames/%05d.png`)可绕过桌面采集,以相同的生产 FFmpeg 编码参数测量固定输入并打印分辨率和编码统计,`UU_PROBE_LOOP=1` 循环到指定帧数,输入无法打开或帧数不足时以非零状态退出(固定输入始终使用外部 FFmpeg 管线)。
|
||||||
|
|||||||
@@ -601,7 +601,11 @@ end:
|
|||||||
int uu_wl_wake(void) {
|
int uu_wl_wake(void) {
|
||||||
pthread_mutex_lock(&lock); int result=-1;
|
pthread_mutex_lock(&lock); int result=-1;
|
||||||
/* Output power management is optional; missing it must not block screencopy. */
|
/* Output power management is optional; missing it must not block screencopy. */
|
||||||
if(initialized && !power) result=0;
|
if(initialized && (!power || power_failed)) {
|
||||||
|
/* No power manager, or the compositor refused the mode (outputs without DPMS,
|
||||||
|
headless outputs): streaming continues, the screen simply stays as it is. */
|
||||||
|
result=0;
|
||||||
|
}
|
||||||
if(initialized && power && !power_failed) {
|
if(initialized && power && !power_failed) {
|
||||||
zwlr_output_power_v1_set_mode(power,ZWLR_OUTPUT_POWER_V1_MODE_ON);
|
zwlr_output_power_v1_set_mode(power,ZWLR_OUTPUT_POWER_V1_MODE_ON);
|
||||||
if(sync_display()==0 && !power_failed) result=0;
|
if(sync_display()==0 && !power_failed) result=0;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
# Unofficial UU Remote Linux host in a container, for NAS boxes (Synology DSM, etc.) without a desktop.
|
# 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.
|
# Headless mode: file transfer, terminal and port mapping; no remote desktop. Uses the published release binary.
|
||||||
FROM ubuntu:24.04
|
FROM ubuntu:24.04
|
||||||
ARG VERSION=v0.2.18
|
ARG VERSION=v0.2.19
|
||||||
LABEL org.opencontainers.image.source="https://github.com/VallierDev/uu-remote-linux" \
|
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.description="Unofficial UU Remote Linux host, headless (file transfer, terminal, port mapping)" \
|
||||||
org.opencontainers.image.licenses="GPL-3.0"
|
org.opencontainers.image.licenses="GPL-3.0"
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
无头 Wayland 出画面、自定义码率、`show` 与登录体验修复。/ Headless Wayland video, custom bitrate, `show` and login fixes.
|
||||||
|
|
||||||
|
### 修复 / Fixed
|
||||||
|
- **无头 Wayland 主机连上没有画面**(#64 / #65,感谢 @axlrose):输出不支持 DPMS 时电源握手失败不再中断视频;贡献者在 sway headless 上复现并验证。
|
||||||
|
- **自定义码率单位错误**(#67,感谢 @JuanZoran):手机端自定义码率按 bit/s 发送(1 Mbps = 1000000),此前被当成 kbit/s 而触发 100 Mbps 上限,
|
||||||
|
导致大量重传、画面滞留。贡献者在 Hyprland + NVENC 上用手机实测。另外对明显是 Mbps / kbps 的小数值做了兜底换算(维护者补充,未实测)。
|
||||||
|
- **`uuremote-server show` 静默卡 30 秒**(#62,感谢 @axlrose):服务被条件跳过、反复崩溃重启或启动失败时立即报出真实原因。贡献者已用真实 systemd 单元验证。
|
||||||
|
- **登录二维码反复立即失效**(#68,感谢 @axlrose):状态轮询在服务器立即应答时不再紧循环(2 秒退避);二维码连续在几秒内失效时指数退避,
|
||||||
|
并提示可备份删除 `~/.config/uuremote/config.json` 重新登录(注册新设备身份,#68 中以此恢复)。退避逻辑未在被标记的设备上实测。
|
||||||
|
|
||||||
|
### 改进 / Improved
|
||||||
|
- `doctor`:会话里没有 `DISPLAY` / `WAYLAND_DISPLAY` 时给出提示(#66,感谢 @axlrose)。
|
||||||
|
- 文档:`inproc-av` / `viewer-ffmpeg` 只支持 FFmpeg 6.x,FFmpeg 7+ 会在依赖里报 `avfft.h file not found`(#63)。
|
||||||
|
|
||||||
|
### 下载 / Download
|
||||||
|
`uu-remote-linux_0.2.19_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.19-<x86_64|aarch64>-linux.tar.gz`,或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.19`(x86_64)。
|
||||||
|
|
||||||
|
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||||
+50
-10
@@ -45,8 +45,8 @@ pub struct VideoSettings {
|
|||||||
pub fps: u32,
|
pub fps: u32,
|
||||||
pub codec: VideoCodec,
|
pub codec: VideoCodec,
|
||||||
pub quality: u64,
|
pub quality: u64,
|
||||||
/// Viewer max_custom_bitrate (only used for QUALITY_CUSTOM): Mbit/s, or kbit/s above 1000.
|
/// Viewer max_custom_bitrate in bits/s (only used for QUALITY_CUSTOM).
|
||||||
pub custom_mbps: u32,
|
pub custom_bps: u32,
|
||||||
/// Scaled stream size (其他分辨率); None streams the native desktop size.
|
/// Scaled stream size (其他分辨率); None streams the native desktop size.
|
||||||
pub output: Option<(u32, u32)>,
|
pub output: Option<(u32, u32)>,
|
||||||
/// CHROMA_420 or CHROMA_444 (真彩); 4:4:4 only when the encoder pipeline supports it.
|
/// CHROMA_420 or CHROMA_444 (真彩); 4:4:4 only when the encoder pipeline supports it.
|
||||||
@@ -54,7 +54,7 @@ pub struct VideoSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VideoSettings {
|
impl Default for VideoSettings {
|
||||||
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 } }
|
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_bps: 0, output: None, chroma: CHROMA_420 } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Selectable smaller stream sizes with the desktop's aspect ratio (even dimensions).
|
/// Selectable smaller stream sizes with the desktop's aspect ratio (even dimensions).
|
||||||
@@ -86,8 +86,8 @@ impl VideoSettings {
|
|||||||
QUALITY_GENERAL => Some(2_000),
|
QUALITY_GENERAL => Some(2_000),
|
||||||
QUALITY_HD => Some(8_000),
|
QUALITY_HD => Some(8_000),
|
||||||
QUALITY_BLURAY => Some(20_000),
|
QUALITY_BLURAY => Some(20_000),
|
||||||
QUALITY_CUSTOM if self.custom_mbps > 0 =>
|
QUALITY_CUSTOM if self.custom_bps > 0 =>
|
||||||
Some(if self.custom_mbps > 1_000 { self.custom_mbps } else { self.custom_mbps * 1_000 }.min(100_000)),
|
Some((self.custom_bps / 1_000).clamp(1, 100_000)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +112,14 @@ fn fps_from_option(value: u64) -> Option<u64> {
|
|||||||
|
|
||||||
/// Applies a capture-setting RPC to `settings` and returns the RpcResponse payload (Message 22),
|
/// Applies a capture-setting RPC to `settings` and returns the RpcResponse payload (Message 22),
|
||||||
/// or None when the RPC is not a capture/fps/quality setting.
|
/// or None when the RPC is not a capture/fps/quality setting.
|
||||||
|
/// max_custom_bitrate (field 8) in bit/s: the mobile viewer sends 1_000_000 for 1 Mbps (#67). Values
|
||||||
|
/// that can only be a different unit stay usable instead of collapsing to a 1 kbit/s cap: below 1000
|
||||||
|
/// they are Mbit/s, below 200_000 kbit/s (no viewer offers custom rates under 200 kbit/s).
|
||||||
|
fn custom_bitrate_bps(value: u64) -> u32 {
|
||||||
|
let bps = if value < 1_000 { value * 1_000_000 } else if value < 200_000 { value * 1_000 } else { value };
|
||||||
|
bps.min(u64::from(u32::MAX)) as u32
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native: (u32, u32)) -> Option<Vec<u8>> {
|
pub fn handle_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native: (u32, u32)) -> Option<Vec<u8>> {
|
||||||
handle_rpc_with_codecs(rpc, settings, native, true, false)
|
handle_rpc_with_codecs(rpc, settings, native, true, false)
|
||||||
}
|
}
|
||||||
@@ -148,7 +156,7 @@ fn apply_rpc(rpc: &[WireField], settings: &watch::Sender<VideoSettings>, native:
|
|||||||
// Field 1 is the viewer's fps option index (1 = 30, 2 = 60, ...); 18 fpsCount is the frame rate.
|
// Field 1 is the viewer's fps option index (1 = 30, 2 = 60, ...); 18 fpsCount is the frame rate.
|
||||||
if let Some(fps) = number(&fields, 18).filter(|v| *v > 0).or_else(|| number(&fields, 1).and_then(fps_from_option)) { next.fps = fps as u32; }
|
if let Some(fps) = number(&fields, 18).filter(|v| *v > 0).or_else(|| number(&fields, 1).and_then(fps_from_option)) { next.fps = fps as u32; }
|
||||||
if let Some(quality) = number(&fields, 2).filter(|v| *v > 0) { next.quality = quality; }
|
if let Some(quality) = number(&fields, 2).filter(|v| *v > 0) { next.quality = quality; }
|
||||||
if let Some(bitrate) = number(&fields, 8).filter(|v| *v > 0) { next.custom_mbps = bitrate as u32; }
|
if let Some(bitrate) = number(&fields, 8).filter(|v| *v > 0) { next.custom_bps = custom_bitrate_bps(bitrate); }
|
||||||
// Field 7 chorma_format (sic): 3 = 4:4:4 when 真彩 is on, 1 = 4:2:0. The Sync reports what is encoded.
|
// Field 7 chorma_format (sic): 3 = 4:4:4 when 真彩 is on, 1 = 4:2:0. The Sync reports what is encoded.
|
||||||
match number(&fields, 7) {
|
match number(&fields, 7) {
|
||||||
Some(CHROMA_444) if full_chroma => next.chroma = CHROMA_444,
|
Some(CHROMA_444) if full_chroma => next.chroma = CHROMA_444,
|
||||||
@@ -237,7 +245,7 @@ pub fn sync_payload(settings: &VideoSettings, native: (u32, u32)) -> Vec<u8> {
|
|||||||
put_varint(1, u64::from(settings.fps), &mut out);
|
put_varint(1, u64::from(settings.fps), &mut out);
|
||||||
put_varint(2, settings.quality, &mut out);
|
put_varint(2, settings.quality, &mut out);
|
||||||
put_varint(3, settings.chroma, &mut out);
|
put_varint(3, settings.chroma, &mut out);
|
||||||
if settings.custom_mbps > 0 { put_varint(4, u64::from(settings.custom_mbps), &mut out); }
|
if settings.custom_bps > 0 { put_varint(4, u64::from(settings.custom_bps), &mut out); }
|
||||||
put_varint(5, u64::from(size.0), &mut out);
|
put_varint(5, u64::from(size.0), &mut out);
|
||||||
put_varint(6, u64::from(size.1), &mut out);
|
put_varint(6, u64::from(size.1), &mut out);
|
||||||
put_varint(9, u64::from(size.0), &mut out);
|
put_varint(9, u64::from(size.0), &mut out);
|
||||||
@@ -284,7 +292,7 @@ mod tests {
|
|||||||
put_varint(18, 30, &mut body);
|
put_varint(18, 30, &mut body);
|
||||||
let request = rpc(77, 2, &body);
|
let request = rpc(77, 2, &body);
|
||||||
let response = handle_rpc(&decode_wire(&request).unwrap(), &tx, (1920, 1080)).unwrap();
|
let response = handle_rpc(&decode_wire(&request).unwrap(), &tx, (1920, 1080)).unwrap();
|
||||||
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(), VideoSettings { source_id:0,source_generation:0, codec: VideoCodec::H264, fps: 30, quality: QUALITY_GENERAL, custom_bps: 0, output: None, chroma: CHROMA_420 });
|
||||||
assert_eq!(rx.borrow().max_kbps(), Some(2_000));
|
assert_eq!(rx.borrow().max_kbps(), Some(2_000));
|
||||||
let fields = decode_wire(&response).unwrap();
|
let fields = decode_wire(&response).unwrap();
|
||||||
assert_eq!(message(&fields, 1), Some(&[8u8, 77][..]));
|
assert_eq!(message(&fields, 1), Some(&[8u8, 77][..]));
|
||||||
@@ -468,8 +476,40 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn auto_quality_keeps_constant_quality_encoding() {
|
fn auto_quality_keeps_constant_quality_encoding() {
|
||||||
assert_eq!(VideoSettings::default().max_kbps(), None);
|
assert_eq!(VideoSettings::default().max_kbps(), None);
|
||||||
assert_eq!(VideoSettings { quality: QUALITY_CUSTOM, custom_mbps: 0, ..Default::default() }.max_kbps(), None);
|
assert_eq!(VideoSettings { quality: QUALITY_CUSTOM, custom_bps: 0, ..Default::default() }.max_kbps(), None);
|
||||||
assert_eq!(VideoSettings { quality: QUALITY_CUSTOM, custom_mbps: 12, ..Default::default() }.max_kbps(), Some(12_000));
|
assert_eq!(VideoSettings { quality: QUALITY_CUSTOM, custom_bps: 12_000_000, ..Default::default() }.max_kbps(), Some(12_000));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mobile_custom_bitrate_is_bits_per_second_in_request_and_sync() {
|
||||||
|
// Mobile viewer sends field 8 = 1_000_000 for 1 Mbps (observed live, 2026-10-20).
|
||||||
|
for (bps, kbps) in [(1_000_000, 1_000), (30_000_000, 30_000), (500_000, 500), (100_000_000, 100_000), (200_000_000, 100_000)] {
|
||||||
|
let (tx, rx) = watch::channel(VideoSettings::default());
|
||||||
|
let mut body = Vec::new();
|
||||||
|
put_varint(2, QUALITY_CUSTOM, &mut body);
|
||||||
|
put_varint(8, bps, &mut body);
|
||||||
|
handle_rpc(&decode_wire(&rpc(7, 2, &body)).unwrap(), &tx, (1920, 1080)).unwrap();
|
||||||
|
assert_eq!(rx.borrow().max_kbps(), Some(kbps));
|
||||||
|
let sync = sync_payload(&rx.borrow(), (1920, 1080));
|
||||||
|
assert_eq!(number(&decode_wire(&sync).unwrap(), 4), Some(bps));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn small_custom_bitrates_are_read_as_larger_units() {
|
||||||
|
assert_eq!(custom_bitrate_bps(20), 20_000_000);
|
||||||
|
assert_eq!(custom_bitrate_bps(8_000), 8_000_000);
|
||||||
|
assert_eq!(custom_bitrate_bps(1_000_000), 1_000_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn oversized_custom_bitrate_does_not_wrap_before_encoder_limit() {
|
||||||
|
let (tx, rx) = watch::channel(VideoSettings::default());
|
||||||
|
let mut body = Vec::new();
|
||||||
|
put_varint(2, QUALITY_CUSTOM, &mut body);
|
||||||
|
put_varint(8, u64::from(u32::MAX) + 1, &mut body);
|
||||||
|
handle_rpc(&decode_wire(&rpc(8, 2, &body)).unwrap(), &tx, (1920, 1080)).unwrap();
|
||||||
|
assert_eq!(rx.borrow().max_kbps(), Some(100_000));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ async fn command_output(program: &str, args: &[&str]) -> Option<String> {
|
|||||||
Some(String::from_utf8_lossy(&output.stdout).trim().to_owned())
|
Some(String::from_utf8_lossy(&output.stdout).trim().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the report must say that this session has no screen to capture: neither DISPLAY nor
|
||||||
|
/// WAYLAND_DISPLAY is set, and the backend is the X11 one that needs a display to open.
|
||||||
|
fn missing_display(backend: crate::desktop_backend::DesktopBackend, headless: bool,
|
||||||
|
display: Option<&std::ffi::OsStr>, wayland: Option<&std::ffi::OsStr>) -> bool {
|
||||||
|
!headless && backend == crate::desktop_backend::DesktopBackend::X11
|
||||||
|
&& display.is_none() && wayland.is_none()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn run() -> Result<(), String> {
|
pub async fn run() -> Result<(), String> {
|
||||||
use crate::desktop_backend as backend;
|
use crate::desktop_backend as backend;
|
||||||
use crate::engine_plugin::{load, Engine};
|
use crate::engine_plugin::{load, Engine};
|
||||||
@@ -66,6 +74,13 @@ pub async fn run() -> Result<(), String> {
|
|||||||
if selected.as_ref().is_ok_and(|b| *b == backend::DesktopBackend::X11) && backend::wayland_session_running() && !backend::headless() {
|
if selected.as_ref().is_ok_and(|b| *b == backend::DesktopBackend::X11) && backend::wayland_session_running() && !backend::headless() {
|
||||||
println!(" ! X11 backend inside a Wayland session: the picture will be black");
|
println!(" ! X11 backend inside a Wayland session: the picture will be black");
|
||||||
}
|
}
|
||||||
|
// A session without any display cannot capture a screen; say so instead of naming a backend.
|
||||||
|
if let Ok(selected) = &selected {
|
||||||
|
if missing_display(*selected, backend::headless(), std::env::var_os("DISPLAY").as_deref(), std::env::var_os("WAYLAND_DISPLAY").as_deref()) {
|
||||||
|
println!(" ! DISPLAY and WAYLAND_DISPLAY are unset: the X11 engine will only try :0 and :1; without an X server there, no screen can be captured");
|
||||||
|
println!(" terminal, file transfer and port mapping still work; UU_DESKTOP_BACKEND=none marks the host as headless");
|
||||||
|
}
|
||||||
|
}
|
||||||
if cfg!(feature = "engine-plugins") {
|
if cfg!(feature = "engine-plugins") {
|
||||||
for engine in [Engine::Wayland, Engine::Portal] {
|
for engine in [Engine::Wayland, Engine::Portal] {
|
||||||
line(engine.file(), match load(engine) { Ok(()) => "loaded".to_owned(), Err(e) => e });
|
line(engine.file(), match load(engine) { Ok(()) => "loaded".to_owned(), Err(e) => e });
|
||||||
@@ -133,4 +148,18 @@ mod tests {
|
|||||||
if home.len() > 1 { assert_eq!(super::redact(&format!("{home}/.config/x")), "~/.config/x"); }
|
if home.len() > 1 { assert_eq!(super::redact(&format!("{home}/.config/x")), "~/.config/x"); }
|
||||||
assert_eq!(super::env_state("UU_DOCTOR_TEST_SURELY_UNSET"), "unset");
|
assert_eq!(super::env_state("UU_DOCTOR_TEST_SURELY_UNSET"), "unset");
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn a_session_without_any_display_is_reported() {
|
||||||
|
use crate::desktop_backend::DesktopBackend;
|
||||||
|
let display = std::ffi::OsStr::new(":0");
|
||||||
|
let wayland = std::ffi::OsStr::new("wayland-1");
|
||||||
|
// No DISPLAY and no WAYLAND_DISPLAY: nothing can be captured.
|
||||||
|
assert!(super::missing_display(DesktopBackend::X11, false, None, None));
|
||||||
|
// One of them present: the backend has a screen to open.
|
||||||
|
assert!(!super::missing_display(DesktopBackend::X11, false, Some(display), None));
|
||||||
|
assert!(!super::missing_display(DesktopBackend::X11, false, None, Some(wayland)));
|
||||||
|
// Another backend, or a headless host: not this warning.
|
||||||
|
assert!(!super::missing_display(DesktopBackend::Wayland, false, None, None));
|
||||||
|
assert!(!super::missing_display(DesktopBackend::X11, true, None, None));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+20
-3
@@ -268,6 +268,7 @@ pub async fn prepare_device() -> Result<(Value, Credentials), String> {
|
|||||||
pub(crate) async fn flow(ui: &LoginUi) -> Result<String, String> {
|
pub(crate) async fn flow(ui: &LoginUi) -> Result<String, String> {
|
||||||
let (mut cfg, creds) = prepare_device().await?;
|
let (mut cfg, creds) = prepare_device().await?;
|
||||||
let client = UUAuthClient::new(creds.clone());
|
let client = UUAuthClient::new(creds.clone());
|
||||||
|
let mut instant_expiries = 0u32;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (status, resp) = client.post_json("/api/v1/qrcode/gen/login", &json!({})).await?;
|
let (status, resp) = client.post_json("/api/v1/qrcode/gen/login", &json!({})).await?;
|
||||||
@@ -293,11 +294,14 @@ pub(crate) async fn flow(ui: &LoginUi) -> Result<String, String> {
|
|||||||
// 1 waiting, 2 scanned, 4 after the phone confirmed); the server answers when it changes.
|
// 1 waiting, 2 scanned, 4 after the phone confirmed); the server answers when it changes.
|
||||||
let mut login_status = 1i64;
|
let mut login_status = 1i64;
|
||||||
let mut expired = false;
|
let mut expired = false;
|
||||||
|
let generated = std::time::Instant::now();
|
||||||
for _ in 0..150 {
|
for _ in 0..150 {
|
||||||
let query = json!({"token": ticket, "qrcode_jump_url": url, "login_status": login_status});
|
let query = json!({"token": ticket, "qrcode_jump_url": url, "login_status": login_status});
|
||||||
|
let asked = std::time::Instant::now();
|
||||||
let (status, resp) = match client.post_json("/api/v1/qrcode/login/status", &query).await {
|
let (status, resp) = match client.post_json("/api/v1/qrcode/login/status", &query).await {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_) => continue, // long-poll timeout: ask again
|
// Long-poll timeout: ask again, but never spin on transport errors (#68).
|
||||||
|
Err(_) => { if asked.elapsed() < Duration::from_secs(1) { tokio::time::sleep(Duration::from_secs(2)).await; } continue; }
|
||||||
};
|
};
|
||||||
// Code 1190 (HTTP 400, "二维码已失效"): the QR expired; generate a new one.
|
// Code 1190 (HTTP 400, "二维码已失效"): the QR expired; generate a new one.
|
||||||
if resp.get("code").and_then(|c| c.as_i64()) == Some(QR_EXPIRED) {
|
if resp.get("code").and_then(|c| c.as_i64()) == Some(QR_EXPIRED) {
|
||||||
@@ -305,7 +309,12 @@ pub(crate) async fn flow(ui: &LoginUi) -> Result<String, String> {
|
|||||||
expired = true; break;
|
expired = true; break;
|
||||||
}
|
}
|
||||||
let st = data("qrcode status", status, &resp)?.get("status").and_then(|v| v.as_i64()).unwrap_or(login_status);
|
let st = data("qrcode status", status, &resp)?.get("status").and_then(|v| v.as_i64()).unwrap_or(login_status);
|
||||||
if st == login_status { continue; }
|
if st == login_status {
|
||||||
|
// The server normally holds this request; an immediate unchanged answer must not
|
||||||
|
// turn into a tight loop of dozens of requests per second (#68).
|
||||||
|
if asked.elapsed() < Duration::from_secs(1) { tokio::time::sleep(Duration::from_secs(2)).await; }
|
||||||
|
continue;
|
||||||
|
}
|
||||||
login_status = st;
|
login_status = st;
|
||||||
match st {
|
match st {
|
||||||
2 => {
|
2 => {
|
||||||
@@ -343,7 +352,15 @@ pub(crate) async fn flow(ui: &LoginUi) -> Result<String, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}", if expired { "QR code expired; generating a new one" } else { "QR code timed out; generating a new one" });
|
println!("{}", if expired { "QR code expired; generating a new one" } else { "QR code timed out; generating a new one" });
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await; // never spin if the server keeps refusing
|
// A QR rejected within seconds of being generated, again and again, was seen when the cloud
|
||||||
|
// flagged this device identity (#68): back off and say how to recover.
|
||||||
|
if expired && generated.elapsed() < Duration::from_secs(10) { instant_expiries += 1; } else { instant_expiries = 0; }
|
||||||
|
if instant_expiries == 3 {
|
||||||
|
eprintln!("The QR code keeps expiring immediately. If this persists, the cloud may reject this device identity: \
|
||||||
|
back up and remove ~/.config/uuremote/config.json, then run `uuremote-server login` again to register a new device.");
|
||||||
|
ui.status("二维码反复立即失效:可备份并删除 ~/.config/uuremote/config.json 后重新登录(会注册新设备)", Tone::Error);
|
||||||
|
}
|
||||||
|
tokio::time::sleep(Duration::from_secs(1u64 << instant_expiries.min(5))).await; // never spin if the server keeps refusing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+34
-2
@@ -143,6 +143,35 @@ fn write_host_pid() {
|
|||||||
let _ = write!(f, "{}", std::process::id());
|
let _ = write!(f, "{}", std::process::id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Why `unit` is not (going to be) running, from `systemctl --user show`; None while it is active or starting.
|
||||||
|
fn unit_not_running(unit: &str, settled: bool) -> Option<String> {
|
||||||
|
let output = std::process::Command::new("systemctl").args(["--user", "show", unit, "-p", "ActiveState,SubState,ConditionResult"]).output().ok()?;
|
||||||
|
let text = String::from_utf8_lossy(&output.stdout);
|
||||||
|
let value = |key: &str| text.lines().find_map(|l| l.strip_prefix(key).and_then(|v| v.strip_prefix('='))).unwrap_or("").to_owned();
|
||||||
|
unit_state_problem(unit, &value("ActiveState"), &value("SubState"), &value("ConditionResult"), settled)
|
||||||
|
}
|
||||||
|
fn unit_state_problem(unit: &str, active: &str, sub: &str, condition: &str, settled: bool) -> Option<String> {
|
||||||
|
let hint = format!("see `systemctl --user status {unit}` and `journalctl --user -u {unit}`");
|
||||||
|
if condition == "no" { return Some(format!("{unit} was skipped: a Condition in the unit is not met (e.g. ConditionEnvironment outside the graphical session); {hint}")); }
|
||||||
|
if active == "failed" { return Some(format!("{unit} failed to start; {hint}")); }
|
||||||
|
if sub == "auto-restart" { return Some(format!("{unit} keeps exiting and being restarted; {hint}")); }
|
||||||
|
if settled && active == "inactive" { return Some(format!("{unit} is not running; {hint}")); }
|
||||||
|
None
|
||||||
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
mod show_unit_tests {
|
||||||
|
#[test]
|
||||||
|
fn skipped_crashing_and_failed_units_are_reported() {
|
||||||
|
let p = |a, s, c, settled| super::unit_state_problem("u.service", a, s, c, settled);
|
||||||
|
assert!(p("inactive", "dead", "no", false).unwrap().contains("skipped"));
|
||||||
|
assert!(p("activating", "auto-restart", "yes", false).unwrap().contains("restarted"));
|
||||||
|
assert!(p("failed", "failed", "yes", false).unwrap().contains("failed"));
|
||||||
|
assert!(p("inactive", "dead", "yes", false).is_none());
|
||||||
|
assert!(p("inactive", "dead", "yes", true).unwrap().contains("not running"));
|
||||||
|
assert!(p("active", "running", "yes", true).is_none());
|
||||||
|
assert!(p("activating", "start", "yes", true).is_none());
|
||||||
|
}
|
||||||
|
}
|
||||||
/// `uuremote-server show` (desktop launcher): open the running host's window, or start the host in the
|
/// `uuremote-server show` (desktop launcher): open the running host's window, or start the host in the
|
||||||
/// foreground with its window when none runs (e.g. no systemd unit installed yet).
|
/// foreground with its window when none runs (e.g. no systemd unit installed yet).
|
||||||
fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -162,7 +191,10 @@ fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().is_ok_and(|s| s.success());
|
.stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).status().is_ok_and(|s| s.success());
|
||||||
if installed && std::process::Command::new("systemctl").args(["--user", "start", &unit]).status().is_ok_and(|s| s.success()) {
|
if installed && std::process::Command::new("systemctl").args(["--user", "start", &unit]).status().is_ok_and(|s| s.success()) {
|
||||||
let before = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok();
|
let before = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok();
|
||||||
for _ in 0..60 {
|
for attempt in 0..60 {
|
||||||
|
// `systemctl start` also returns 0 when the unit is skipped by a Condition or keeps
|
||||||
|
// crashing under Restart=; report that instead of waiting 30 s for a pid (#62).
|
||||||
|
if let Some(reason) = unit_not_running(&unit, attempt >= 2) { return Err(reason.into()); }
|
||||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
let fresh = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok().is_some_and(|t| Some(t) != before);
|
let fresh = std::fs::metadata(host_pid_path()).and_then(|m| m.modified()).ok().is_some_and(|t| Some(t) != before);
|
||||||
let pid = std::fs::read_to_string(host_pid_path()).ok().and_then(|s| s.trim().parse::<i32>().ok());
|
let pid = std::fs::read_to_string(host_pid_path()).ok().and_then(|s| s.trim().parse::<i32>().ok());
|
||||||
@@ -171,7 +203,7 @@ fn show_running_host() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
if unsafe { libc::kill(pid, libc::SIGUSR1) } == 0 { return Ok(()); }
|
if unsafe { libc::kill(pid, libc::SIGUSR1) } == 0 { return Ok(()); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Err("the UU remote host service started but did not open its window".into());
|
return Err(format!("{unit} is running but did not open its window within 30 s; check `journalctl --user -u {unit}`").into());
|
||||||
}
|
}
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
Err(Box::new(std::process::Command::new("/proc/self/exe").env("UU_SHOW_WINDOW", "1").exec()))
|
Err(Box::new(std::process::Command::new("/proc/self/exe").env("UU_SHOW_WINDOW", "1").exec()))
|
||||||
|
|||||||
Reference in new issue
Block a user