mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13c92d8f68 | ||
|
|
b0015a6c48 | ||
|
|
c60d9f1bfa | ||
|
|
6032129228 | ||
|
|
7ba71a5540 | ||
|
|
b774bf6b16 | ||
|
|
a22f576005 | ||
|
|
212e4943f9 |
No files matched your search
Generated
+1
-1
@@ -2804,7 +2804,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.50"
|
version = "0.2.52"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "uu-remote-linux"
|
name = "uu-remote-linux"
|
||||||
version = "0.2.50"
|
version = "0.2.52"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "uuremote-server"
|
default-run = "uuremote-server"
|
||||||
authors = ["uu-remote-linux contributors"]
|
authors = ["uu-remote-linux contributors"]
|
||||||
|
|||||||
+34
-60
@@ -159,37 +159,10 @@ static size_t symbols_close(const char *text) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Named keycodes the keymap gives no symbol to. Reading the compositor's own list is the only
|
/* Reusable codes for the separate text-only keyboard. Remapping real printable keys on that device
|
||||||
portable way: pressing an unmapped keycode types nothing, and uu_wl_key never matches one
|
keeps the physical-key map untouched and is the form Chromium accepts; the evdev "reserved" codes
|
||||||
because it searches by keysym. Highest first, since uu_wl_key takes the lowest match. */
|
that have no symbol are discarded by some clients. */
|
||||||
static unsigned find_spare_codes(xkb_keycode_t *out,unsigned limit) {
|
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 unsigned find_niri_text_codes(xkb_keycode_t *out,unsigned limit) {
|
|
||||||
/* Printable physical keys work in Chromium; reserved evdev codes can be discarded. */
|
|
||||||
static const xkb_keycode_t text_codes[]={24,25,26,27,28,29,30,31,32,33,38,39,40,41,42,43,44,45,46,52,53,54,55,56,57,58};
|
static const xkb_keycode_t text_codes[]={24,25,26,27,28,29,30,31,32,33,38,39,40,41,42,43,44,45,46,52,53,54,55,56,57,58};
|
||||||
unsigned count=0;
|
unsigned count=0;
|
||||||
for(unsigned i=0;i<sizeof(text_codes)/sizeof(text_codes[0]) && count<limit;i++)
|
for(unsigned i=0;i<sizeof(text_codes)/sizeof(text_codes[0]) && count<limit;i++)
|
||||||
@@ -216,8 +189,12 @@ static void release_held_keys_locked(void) {
|
|||||||
key_state and held_keys: pressed and released here. */
|
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) {
|
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();
|
release_held_keys_locked();
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
if(sync_display()!=0) return -1;
|
||||||
else if(rekey_keyboard()!=0) return -1;
|
usleep(8000);
|
||||||
|
/* A keymap re-sent on a keyboard the client already knows is not handed to it again, so the
|
||||||
|
next batch would still decode with the previous one and repeat it. Re-attaching the text
|
||||||
|
keyboard is what makes the compositor deliver the new keymap. */
|
||||||
|
if(rekey_keyboard()!=0) return -1;
|
||||||
size_t at=keymap_insert;
|
size_t at=keymap_insert;
|
||||||
memcpy(buffer,keymap_text,at);
|
memcpy(buffer,keymap_text,at);
|
||||||
for(unsigned i=0;i<count;i++) {
|
for(unsigned i=0;i<count;i++) {
|
||||||
@@ -227,16 +204,16 @@ static int flush_batch(char *buffer,size_t capacity,const char names[][64],const
|
|||||||
}
|
}
|
||||||
memcpy(buffer+at,keymap_text+keymap_insert,keymap_text_len-keymap_insert);
|
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(upload_keymap(buffer,at+(keymap_text_len-keymap_insert))!=0) return -1;
|
||||||
if(getenv("NIRI_SOCKET")) zwp_virtual_keyboard_v1_modifiers(keyboard,0,0,0,0);
|
zwp_virtual_keyboard_v1_modifiers(keyboard,0,0,0,0);
|
||||||
if(sync_display()!=0) return -1;
|
if(sync_display()!=0) return -1;
|
||||||
if(getenv("NIRI_SOCKET")) usleep(8000);
|
usleep(8000);
|
||||||
for(unsigned i=0;i<count;i++) { press_keycode(codes[i]); (*typed)++; }
|
for(unsigned i=0;i<count;i++) { press_keycode(codes[i]); (*typed)++; }
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
if(sync_display()!=0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* Type UTF-8 like xdotool type does on X11, but on Wayland: characters the session keymap already
|
/* Type UTF-8 like xdotool type does on X11: each character is a Unicode keysym carried by the
|
||||||
has go out as ordinary keycodes, the rest share the spares of one keymap upload (~70 KB, so one
|
text-only keyboard's printable codes, one keymap upload (~70 KB, so one batch per upload) in text
|
||||||
batch per upload), in text order. Never logs the text. */
|
order. Never logs the text. */
|
||||||
static int type_utf8_locked(const char *text) {
|
static int type_utf8_locked(const char *text) {
|
||||||
size_t capacity=keymap_text_len+(size_t)UU_TEXT_SPARE*96+64;
|
size_t capacity=keymap_text_len+(size_t)UU_TEXT_SPARE*96+64;
|
||||||
char *buffer=malloc(capacity);
|
char *buffer=malloc(capacity);
|
||||||
@@ -258,16 +235,11 @@ static int type_utf8_locked(const char *text) {
|
|||||||
if(cp=='\n') sym=0xff0d; /* Return */
|
if(cp=='\n') sym=0xff0d; /* Return */
|
||||||
else if(cp=='\t') sym=0xff09; /* Tab */
|
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<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 */
|
/* Every character goes out as a Unicode keysym, including ASCII: a plain Latin-1 keysym
|
||||||
else sym=(xkb_keysym_t)(0x1000000|cp); /* Unicode keysym */
|
is what a running input method composes as pinyin, so "abc" would turn into candidates
|
||||||
xkb_keycode_t existing=getenv("NIRI_SOCKET")?0:existing_keycode(sym);
|
instead of reaching the field. */
|
||||||
if(existing) {
|
else sym=(xkb_keysym_t)(0x1000000|cp);
|
||||||
if(count && flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
if(count==spare_count) {
|
||||||
count=0;
|
|
||||||
press_keycode(existing); typed++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(count==(getenv("NIRI_SOCKET")?spare_count:UU_TEXT_SPARE)) {
|
|
||||||
if(flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
if(flush_batch(buffer,capacity,names,codes,count,&typed)!=0) { failed=1; break; }
|
||||||
count=0;
|
count=0;
|
||||||
}
|
}
|
||||||
@@ -278,23 +250,25 @@ static int type_utf8_locked(const char *text) {
|
|||||||
}
|
}
|
||||||
if(!failed && count) failed=flush_batch(buffer,capacity,names,codes,count,&typed)!=0;
|
if(!failed && count) failed=flush_batch(buffer,capacity,names,codes,count,&typed)!=0;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
/* Restore the pristine keymap whatever happened above, so uu_wl_key keeps its own symbol map. */
|
|
||||||
if(getenv("NIRI_SOCKET")) {if(sync_display()!=0) return -1;usleep(8000);}
|
|
||||||
else if(upload_keymap(keymap_text,keymap_text_len)!=0) return -1;
|
|
||||||
return failed && !typed?-1:typed;
|
return failed && !typed?-1:typed;
|
||||||
}
|
}
|
||||||
int uu_wl_type_utf8(const char *text) {
|
int uu_wl_type_utf8(const char *text) {
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
int typed=-1;
|
int typed=-1;
|
||||||
if(initialized && text && keymap_text && keymap_insert && spare_count) {
|
if(initialized && text && keymap_text && keymap_insert && spare_count) {
|
||||||
if(getenv("NIRI_SOCKET")) {
|
if(!keyboard_manager) { pthread_mutex_unlock(&lock); return -1; }
|
||||||
/* Only niri uses printable codes on a separate text device; preserve the Hyprland path. */
|
/* Text has its own device: remapping printable codes must not change physical-key input. */
|
||||||
release_held_keys_locked();
|
release_held_keys_locked();
|
||||||
struct zwp_virtual_keyboard_v1 *saved=keyboard;
|
/* The original device stays alive, so key-up alone must not leave its modifiers held. */
|
||||||
keyboard=zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(keyboard_manager,seat);
|
zwp_virtual_keyboard_v1_modifiers(keyboard,
|
||||||
if(keyboard) {typed=type_utf8_locked(text);sync_display();usleep(8000);if(keyboard) zwp_virtual_keyboard_v1_destroy(keyboard);}
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_DEPRESSED),
|
||||||
keyboard=saved;
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LATCHED),
|
||||||
} else typed=type_utf8_locked(text);
|
xkb_state_serialize_mods(key_state,XKB_STATE_MODS_LOCKED),
|
||||||
|
xkb_state_serialize_layout(key_state,XKB_STATE_LAYOUT_EFFECTIVE));
|
||||||
|
struct zwp_virtual_keyboard_v1 *saved=keyboard;
|
||||||
|
keyboard=zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(keyboard_manager,seat);
|
||||||
|
if(keyboard) {typed=type_utf8_locked(text);sync_display();usleep(8000);if(keyboard) zwp_virtual_keyboard_v1_destroy(keyboard);}
|
||||||
|
keyboard=saved;
|
||||||
}
|
}
|
||||||
if(typed>=0 && wl_display_flush(display)<0) typed=-1;
|
if(typed>=0 && wl_display_flush(display)<0) typed=-1;
|
||||||
pthread_mutex_unlock(&lock); return typed;
|
pthread_mutex_unlock(&lock); return typed;
|
||||||
@@ -597,7 +571,7 @@ int uu_wl_init(int32_t *w,int32_t *h) {
|
|||||||
/* Text typing needs unmapped keycodes and a place to declare them. A keymap without either
|
/* 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. */
|
only costs that path - uu_wl_type_utf8 refuses and the caller keeps its own fallback. */
|
||||||
keymap_insert=symbols_close(keymap_text);
|
keymap_insert=symbols_close(keymap_text);
|
||||||
spare_count=getenv("NIRI_SOCKET")?find_niri_text_codes(spare_codes,UU_TEXT_SPARE):find_spare_codes(spare_codes,UU_TEXT_SPARE);
|
spare_count=find_spare_codes(spare_codes,UU_TEXT_SPARE);
|
||||||
}
|
}
|
||||||
initialized=1; *w=width; *h=height; result=0;
|
initialized=1; *w=width; *h=height; result=0;
|
||||||
end:
|
end:
|
||||||
|
|||||||
+36
-4
@@ -331,12 +331,30 @@ static int class_is_terminal(const char *value) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 1 when the focused window belongs to a terminal emulator, else 0. */
|
/* Returns 1 when the focused window belongs to a terminal emulator, else 0.
|
||||||
|
Cached by focused Window with a 1000ms TTL, so key bursts on the same window
|
||||||
|
avoid redundant 12-level XQueryTree walks, while focus changes invalidate immediately. */
|
||||||
int x11_terminal_shortcut_state(void) {
|
int x11_terminal_shortcut_state(void) {
|
||||||
|
static Window cached_window = 0;
|
||||||
|
static int cached_terminal = 0;
|
||||||
|
static struct timespec last_query = {0, 0};
|
||||||
|
|
||||||
if (!g_probe && !(g_probe = XOpenDisplay(NULL))) return 0;
|
if (!g_probe && !(g_probe = XOpenDisplay(NULL))) return 0;
|
||||||
Window focus = 0; int revert = 0;
|
Window focus = 0; int revert = 0;
|
||||||
XGetInputFocus(g_probe, &focus, &revert);
|
XGetInputFocus(g_probe, &focus, &revert);
|
||||||
if (focus == None || focus == PointerRoot) return 0;
|
if (focus == None || focus == PointerRoot) {
|
||||||
|
cached_window = 0;
|
||||||
|
cached_terminal = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec now;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
long diff_ms = (now.tv_sec - last_query.tv_sec) * 1000 + (now.tv_nsec - last_query.tv_nsec) / 1000000;
|
||||||
|
if (focus == cached_window && last_query.tv_sec != 0 && diff_ms >= 0 && diff_ms < 1000) {
|
||||||
|
return cached_terminal;
|
||||||
|
}
|
||||||
|
|
||||||
Window cur = focus;
|
Window cur = focus;
|
||||||
for (int depth = 0; depth < 12 && cur; depth++) {
|
for (int depth = 0; depth < 12 && cur; depth++) {
|
||||||
XClassHint hint = {0};
|
XClassHint hint = {0};
|
||||||
@@ -344,14 +362,28 @@ int x11_terminal_shortcut_state(void) {
|
|||||||
int terminal = class_is_terminal(hint.res_name) || class_is_terminal(hint.res_class);
|
int terminal = class_is_terminal(hint.res_name) || class_is_terminal(hint.res_class);
|
||||||
if (hint.res_name) XFree(hint.res_name);
|
if (hint.res_name) XFree(hint.res_name);
|
||||||
if (hint.res_class) XFree(hint.res_class);
|
if (hint.res_class) XFree(hint.res_class);
|
||||||
|
cached_window = focus;
|
||||||
|
cached_terminal = terminal;
|
||||||
|
last_query = now;
|
||||||
return terminal;
|
return terminal;
|
||||||
}
|
}
|
||||||
Window root, parent, *children = NULL; unsigned int n = 0;
|
Window root, parent, *children = NULL; unsigned int n = 0;
|
||||||
if (!XQueryTree(g_probe, cur, &root, &parent, &children, &n)) return 0;
|
if (!XQueryTree(g_probe, cur, &root, &parent, &children, &n)) {
|
||||||
|
cached_window = 0;
|
||||||
|
cached_terminal = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (children) XFree(children);
|
if (children) XFree(children);
|
||||||
if (parent == root) return 0;
|
if (parent == root) {
|
||||||
|
cached_window = 0;
|
||||||
|
cached_terminal = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
cur = parent;
|
cur = parent;
|
||||||
}
|
}
|
||||||
|
cached_window = focus;
|
||||||
|
cached_terminal = 0;
|
||||||
|
last_query = now;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
Hyprland 等 wlroots 合成器上,手机查看端输入法打出的中文/符号文字可正常上屏。/ Phone IME text (Chinese and symbols) from mobile viewers now types correctly on Hyprland and other wlroots compositors.
|
||||||
|
|
||||||
|
### 修复 / Fixed
|
||||||
|
- **wlroots 手机输入法文字(#176,感谢 @Onekki)**:所有 wlroots 合成器统一用独立的虚拟文字键盘,每批文字重新 attach 键位表,ASCII 也按 Unicode keysym 发送;Wayland 下先走 keysym、失败再回退 uinput;输入前释放按键后同步原设备的修饰键状态,避免 Ctrl/Shift 残留。/ All wlroots compositors use a dedicated virtual text keyboard, re-attaching the keymap per batch and sending ASCII as Unicode keysyms; Wayland tries keysyms before falling back to uinput, and modifier state is re-synced to the original device so Ctrl/Shift do not stick.
|
||||||
|
|
||||||
|
### 验证范围 / Validation
|
||||||
|
单元测试与 CI;贡献者在 Hyprland 0.56.2 + fcitx5 实机验证。niri 等其他 wlroots 合成器未实测。
|
||||||
|
|
||||||
|
### 下载 / Download
|
||||||
|
`uu-remote-linux_0.2.51_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.51-<x86_64|aarch64>-linux.tar.gz`(解压后运行 `./install.sh`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.51`(x86_64)。
|
||||||
|
|
||||||
|
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
性能优化版:降低视频推流与输入通道的拷贝和解析开销,功能行为不变。/ Performance release: less copying and parsing on the video and input paths; no behavior change.
|
||||||
|
|
||||||
|
### 优化 / Improved
|
||||||
|
- **编码帧零拷贝(#184)**:编码完成帧改用共享缓冲,去掉每帧码流深拷贝。/ Encoded frames use shared buffers, removing a per-frame bitstream deep copy.
|
||||||
|
- **H.265 关键帧检测与 RTP 分包(#180、#182)**:IRAP 检测改为单趟流式扫描,HEVC RTP 分包改为零拷贝子切片。/ Single-pass streaming IRAP scan; zero-copy sub-slices for HEVC RTP packetization.
|
||||||
|
- **数据通道解析(#180、#191)**:数据通道包单次解码、CONTROL 通道 JSON 单次解析。/ Single-pass data-channel decoding and single JSON parse on the CONTROL channel.
|
||||||
|
- **X11 终端检测缓存(#182)**:100ms 缓存,减少高频查询。/ 100 ms cache for X11 terminal detection.
|
||||||
|
- **文字输入不阻塞(#189)**:文字输入移到阻塞线程池执行,保持先后顺序。/ Text input runs on the blocking pool while preserving order.
|
||||||
|
|
||||||
|
感谢 @ferstar 提交这批优化。/ Thanks to @ferstar for these optimizations.
|
||||||
|
|
||||||
|
### 验证范围 / Validation
|
||||||
|
单元测试与 CI;各 PR 经 Codex 审查。未做实机性能对比与 Mac/手机客户端界面验收。
|
||||||
|
|
||||||
|
### 下载 / Download
|
||||||
|
`uu-remote-linux_0.2.52_<amd64|arm64>.deb`,或 `uu-remote-linux-v0.2.52-<x86_64|aarch64>-linux.tar.gz`(解压后运行 `./install.sh`),或 `docker pull ghcr.io/vallierdev/uu-remote-linux:v0.2.52`(x86_64)。
|
||||||
|
|
||||||
|
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
|
||||||
+40
@@ -36,6 +36,46 @@ pub fn payload(mtu: usize, annex_b: &[u8]) -> Result<Vec<Bytes>, String> {
|
|||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Payload HEVC Annex-B bitstream with zero-copy sub-slicing for single NAL units <= MTU.
|
||||||
|
pub fn payload_bytes(mtu: usize, annex_b: &Bytes) -> Result<Vec<Bytes>, String> {
|
||||||
|
if mtu < 4 { return Err("HEVC payload MTU too small".into()); }
|
||||||
|
let mut starts = Vec::new();
|
||||||
|
let mut i = 0;
|
||||||
|
let bytes = annex_b.as_ref();
|
||||||
|
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; };
|
||||||
|
starts.push((i, i + prefix)); i += prefix;
|
||||||
|
}
|
||||||
|
if starts.is_empty() { return Err("HEVC access unit has no Annex-B start code".into()); }
|
||||||
|
let mut out = Vec::new();
|
||||||
|
for (index, &(_, start)) in starts.iter().enumerate() {
|
||||||
|
let mut end = starts.get(index + 1).map_or(bytes.len(), |s| s.0);
|
||||||
|
while end > start && bytes[end - 1] == 0 { end -= 1; } // trailing_zero_8bits
|
||||||
|
let nal_slice = &bytes[start..end];
|
||||||
|
if nal_slice.len() < 2 || nal_slice[0] & 0x80 != 0 || nal_slice[1] & 7 == 0 {
|
||||||
|
return Err("Invalid HEVC NAL header".into());
|
||||||
|
}
|
||||||
|
let kind = (nal_slice[0] >> 1) & 63;
|
||||||
|
if kind >= 48 { return Err("HEVC Annex-B contains RTP packet type".into()); }
|
||||||
|
if nal_slice.len() <= mtu {
|
||||||
|
// Zero-copy reference-counted sub-slice:
|
||||||
|
out.push(annex_b.slice(start..end));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let chunks = nal_slice[2..].chunks(mtu - 3);
|
||||||
|
let last = chunks.len() - 1;
|
||||||
|
for (n, chunk) in chunks.enumerate() {
|
||||||
|
let mut fu = Vec::with_capacity(3 + chunk.len());
|
||||||
|
// Keep F, LayerId and TID, replacing only the NAL type with FU=49.
|
||||||
|
fu.extend_from_slice(&[(nal_slice[0] & 0x81) | (49 << 1), nal_slice[1],
|
||||||
|
kind | if n == 0 { 0x80 } else { 0 } | if n == last { 0x40 } else { 0 }]);
|
||||||
|
fu.extend_from_slice(chunk); out.push(fu.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
+11
-4
@@ -742,14 +742,21 @@ impl InputInjector {
|
|||||||
self.emit_uinput_text(&crate::uinput::text_plan(text))
|
self.emit_uinput_text(&crate::uinput::text_plan(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mobile input-method text (`text_input`). uinput types the layout-mappable ASCII prefix
|
/// Mobile input-method text (`text_input`). X11 types directly. Native Wayland uses the text
|
||||||
/// without clipboard access. X11 types directly; native Wayland re-maps a spare
|
/// keyboard's Unicode keysyms first: uinput sends physical keycodes, which a running input
|
||||||
/// keycode in the virtual keyboard's keymap. Portal and other Wayland environments inject
|
/// method composes as pinyin, so "hello" would become candidates instead of text. uinput stays
|
||||||
/// via clipboard paste (Shift+Insert). Set UU_WAYLAND_TEXT=0 to disable Wayland text injection.
|
/// as the fallback when the keymap path is unavailable. Portal and other Wayland environments
|
||||||
|
/// inject via clipboard paste (Shift+Insert).
|
||||||
|
/// Set UU_WAYLAND_TEXT=0 to disable Wayland text injection.
|
||||||
pub fn text_input(&self, text: &str) {
|
pub fn text_input(&self, text: &str) {
|
||||||
let _serial=self.serial.lock().unwrap();
|
let _serial=self.serial.lock().unwrap();
|
||||||
if self.backend != crate::desktop_backend::DesktopBackend::X11 {
|
if self.backend != crate::desktop_backend::DesktopBackend::X11 {
|
||||||
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v| v == "0") { return; }
|
if std::env::var("UU_WAYLAND_TEXT").is_ok_and(|v| v == "0") { return; }
|
||||||
|
if self.backend == crate::desktop_backend::DesktopBackend::Wayland
|
||||||
|
&& crate::wayland::type_utf8(text) >= 0 {
|
||||||
|
log::info!("Desktop text input: chars={} result=keysyms", text.chars().count());
|
||||||
|
return;
|
||||||
|
}
|
||||||
let typed = self.type_uinput_text(text);
|
let typed = self.type_uinput_text(text);
|
||||||
if typed > 0 { log::info!("Desktop text input (uinput): chars={typed}"); }
|
if typed > 0 { log::info!("Desktop text input (uinput): chars={typed}"); }
|
||||||
if typed == text.len() { return; }
|
if typed == text.len() { return; }
|
||||||
|
|||||||
+28
-11
@@ -154,8 +154,25 @@ fn is_independent_frame_for(bytes: &[u8], codec: VideoCodec) -> bool {
|
|||||||
match codec {
|
match codec {
|
||||||
VideoCodec::H264 => !nal_offsets_for(bytes, 5, codec).is_empty() && nal_offsets_for(bytes, 1, codec).is_empty(),
|
VideoCodec::H264 => !nal_offsets_for(bytes, 5, codec).is_empty() && nal_offsets_for(bytes, 1, codec).is_empty(),
|
||||||
// BLA/IDR/CRA are IRAP (RFC 7798 §4.1); no leading pictures with our no-B-frame encoder.
|
// BLA/IDR/CRA are IRAP (RFC 7798 §4.1); no leading pictures with our no-B-frame encoder.
|
||||||
VideoCodec::H265 => (16..=21).any(|kind| !nal_offsets_for(bytes, kind, codec).is_empty())
|
VideoCodec::H265 => {
|
||||||
&& !(0..16).any(|kind| !nal_offsets_for(bytes, kind, codec).is_empty()),
|
let mut has_irap = false;
|
||||||
|
let mut has_non_irap_vcl = false;
|
||||||
|
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) {
|
||||||
|
if (16..=21).contains(&kind) {
|
||||||
|
has_irap = true;
|
||||||
|
} else if kind < 16 {
|
||||||
|
has_non_irap_vcl = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i += prefix;
|
||||||
|
}
|
||||||
|
has_irap && !has_non_irap_vcl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -169,7 +186,7 @@ struct CompleteFrame {
|
|||||||
codec: VideoCodec,
|
codec: VideoCodec,
|
||||||
sequence: u64,
|
sequence: u64,
|
||||||
completed_at: Instant,
|
completed_at: Instant,
|
||||||
data: Vec<u8>,
|
data: bytes::Bytes,
|
||||||
_permit: Option<OwnedSemaphorePermit>,
|
_permit: Option<OwnedSemaphorePermit>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +786,7 @@ async fn read_inprocess(
|
|||||||
let mut gate = DependencyGate::default();
|
let mut gate = DependencyGate::default();
|
||||||
while let Some(unit) = units.recv().await {
|
while let Some(unit) = units.recv().await {
|
||||||
let sequence = sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
let sequence = sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
||||||
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: source.1, source_id: source.0, codec, sequence, completed_at: unit.completed_at, data: unit.data, _permit: Some(unit.permit) }));
|
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: source.1, source_id: source.0, codec, sequence, completed_at: unit.completed_at, data: unit.data.into(), _permit: Some(unit.permit) }));
|
||||||
if latest.is_closed() { break; }
|
if latest.is_closed() { break; }
|
||||||
}
|
}
|
||||||
// Dropping the receiver also unblocks the encoder if it is waiting to send.
|
// Dropping the receiver also unblocks the encoder if it is waiting to send.
|
||||||
@@ -988,7 +1005,7 @@ async fn read_encoder_with(
|
|||||||
if aud.len() < 2 { break; }
|
if aud.len() < 2 { break; }
|
||||||
let next = aud[1];
|
let next = aud[1];
|
||||||
if next > MAX_ACCESS_UNIT { return Err("Encoder access unit exceeds limit".into()); }
|
if next > MAX_ACCESS_UNIT { return Err("Encoder access unit exceeds limit".into()); }
|
||||||
let frame: Vec<u8> = pending.drain(..next).collect();
|
let frame: bytes::Bytes = pending.drain(..next).collect::<Vec<u8>>().into();
|
||||||
let sequence = sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
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};
|
let permit=if wayland {Some(permits_rx.recv().await.ok_or("Capture producer stopped")?)} else {None};
|
||||||
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: settings.source_generation, source_id: settings.source_id,
|
gate.submit(&latest, Arc::new(CompleteFrame { source_generation: settings.source_generation, source_id: settings.source_id,
|
||||||
@@ -1330,7 +1347,7 @@ pub async fn stream_desktop_at(pc: Arc<RTCPeerConnection>, track: Arc<crate::vid
|
|||||||
max_age_ms = max_age_ms.max(frame.completed_at.elapsed().as_millis());
|
max_age_ms = max_age_ms.max(frame.completed_at.elapsed().as_millis());
|
||||||
// Continue monitoring close even if the network send stalls.
|
// Continue monitoring close even if the network send stalls.
|
||||||
let sample = Sample {
|
let sample = Sample {
|
||||||
data: frame.data.clone().into(), duration, ..Default::default()
|
data: frame.data.clone(), duration, ..Default::default()
|
||||||
};
|
};
|
||||||
let extensions = [crate::rtp_metadata::capture_index(0), crate::rtp_metadata::new_frame()];
|
let extensions = [crate::rtp_metadata::capture_index(0), crate::rtp_metadata::new_frame()];
|
||||||
let sent_before=track.revision();
|
let sent_before=track.revision();
|
||||||
@@ -1480,7 +1497,7 @@ mod tests {
|
|||||||
for sequence in 1..=2 {
|
for sequence in 1..=2 {
|
||||||
let permit=budget.clone().acquire_owned().await.unwrap();
|
let permit=budget.clone().acquire_owned().await.unwrap();
|
||||||
gate.submit(&tx,Arc::new(CompleteFrame { source_generation: 0, source_id: 0,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)}));
|
data:vec![0,0,1,5,42].into(),_permit:Some(permit)}));
|
||||||
}
|
}
|
||||||
let sending=rx.recv().await.unwrap();
|
let sending=rx.recv().await.unwrap();
|
||||||
assert_eq!(budget.available_permits(),0);
|
assert_eq!(budget.available_permits(),0);
|
||||||
@@ -1642,7 +1659,7 @@ mod tests {
|
|||||||
let (started_tx, started_rx) = tokio::sync::oneshot::channel();
|
let (started_tx, started_rx) = tokio::sync::oneshot::channel();
|
||||||
let frame = |sequence, idr| Arc::new(CompleteFrame { source_generation: 0, source_id: 0, _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(),
|
sequence, codec: VideoCodec::H264, completed_at: Instant::now(),
|
||||||
data: vec![0, 0, 1, 9, 240, 0, 0, 1, if idr { 5 } else { 1 }, 42],
|
data: vec![0, 0, 1, 9, 240, 0, 0, 1, if idr { 5 } else { 1 }, 42].into(),
|
||||||
});
|
});
|
||||||
let mut reader = EncoderTask(tokio::spawn(async move {
|
let mut reader = EncoderTask(tokio::spawn(async move {
|
||||||
let _stopped = MarkStopped(old_stopped);
|
let _stopped = MarkStopped(old_stopped);
|
||||||
@@ -1735,7 +1752,7 @@ mod tests {
|
|||||||
async fn bounded_queue_never_sends_broken_prediction_chain_after_overload(){
|
async fn bounded_queue_never_sends_broken_prediction_chain_after_overload(){
|
||||||
let(tx,mut rx)=mpsc::channel(1);
|
let(tx,mut rx)=mpsc::channel(1);
|
||||||
let mut gate=DependencyGate::default();
|
let mut gate=DependencyGate::default();
|
||||||
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]});
|
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].into()});
|
||||||
gate.submit(&tx,frame(1,false));assert!(rx.try_recv().is_err()); // no IDR yet
|
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(2,true));
|
||||||
gate.submit(&tx,frame(3,false)); // queue full: P3 lost
|
gate.submit(&tx,frame(3,false)); // queue full: P3 lost
|
||||||
@@ -1808,7 +1825,7 @@ mod tests {
|
|||||||
let (tx, mut rx) = mpsc::channel(1);
|
let (tx, mut rx) = mpsc::channel(1);
|
||||||
let mut gate = DependencyGate::default();
|
let mut gate = DependencyGate::default();
|
||||||
let frame = |sequence, irap| Arc::new(CompleteFrame { source_generation: 0, source_id: 0, _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] });
|
sequence, completed_at: Instant::now(), data: vec![0,0,1,if irap { 38 } else { 2 },1,42].into() });
|
||||||
gate.submit(&tx, frame(1, false));
|
gate.submit(&tx, frame(1, false));
|
||||||
assert!(rx.try_recv().is_err());
|
assert!(rx.try_recv().is_err());
|
||||||
gate.submit(&tx, frame(2, true));
|
gate.submit(&tx, frame(2, true));
|
||||||
@@ -1855,7 +1872,7 @@ mod screen_frame_tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn source_restart_rejects_queued_frames_even_with_same_screen_and_codec() {
|
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 frame=CompleteFrame {source_id:0,source_generation:7,codec:VideoCodec::H264,sequence:1,completed_at:Instant::now(),data:vec![].into(),_permit:None};
|
||||||
let mut settings=VideoSettings {source_id:0,source_generation:7,..Default::default()};
|
let mut settings=VideoSettings {source_id:0,source_generation:7,..Default::default()};
|
||||||
assert!(frame.matches(&settings));
|
assert!(frame.matches(&settings));
|
||||||
settings.source_generation=9;assert!(!frame.matches(&settings));
|
settings.source_generation=9;assert!(!frame.matches(&settings));
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ impl VideoTrack {
|
|||||||
// Leave room for the RTP header and negotiated UU extensions below the 1200 byte MTU.
|
// Leave room for the RTP header and negotiated UU extensions below the 1200 byte MTU.
|
||||||
let payloads = match codec {
|
let payloads = match codec {
|
||||||
VideoCodec::H264 => state.h264.payload(1160, &sample.data).map_err(Error::Rtp)?,
|
VideoCodec::H264 => state.h264.payload(1160, &sample.data).map_err(Error::Rtp)?,
|
||||||
VideoCodec::H265 => crate::hevc::payload(1160, &sample.data).map_err(Error::new)?,
|
VideoCodec::H265 => crate::hevc::payload_bytes(1160, &sample.data).map_err(Error::new)?,
|
||||||
};
|
};
|
||||||
let count = payloads.len();
|
let count = payloads.len();
|
||||||
let mut complete = count > 0;
|
let mut complete = count > 0;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ pub(super) async fn encode(latest: mpsc::Sender<Arc<CompleteFrame>>, settings: V
|
|||||||
let frame = Arc::new(CompleteFrame {
|
let frame = Arc::new(CompleteFrame {
|
||||||
source_generation: settings.source_generation, source_id: settings.source_id,
|
source_generation: settings.source_generation, source_id: settings.source_id,
|
||||||
codec: settings.codec, sequence: sequence.fetch_add(1, Ordering::Relaxed) + 1,
|
codec: settings.codec, sequence: sequence.fetch_add(1, Ordering::Relaxed) + 1,
|
||||||
completed_at: Instant::now(), data: vec![0, 0, 1, 65, 1, 2], _permit: Some(permit),
|
completed_at: Instant::now(), data: vec![0, 0, 1, 65, 1, 2].into(), _permit: Some(permit),
|
||||||
});
|
});
|
||||||
if latest.send(frame).await.is_err() { return Ok(()); }
|
if latest.send(frame).await.is_err() { return Ok(()); }
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-72
@@ -1177,7 +1177,8 @@ impl WebRtcSession {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Ok(fields) = crate::protocol::decode_wire(&msg.data) {
|
let proto_fields = crate::protocol::decode_wire(&msg.data).ok();
|
||||||
|
if let Some(fields) = proto_fields.as_deref() {
|
||||||
use crate::protocol::WireValue;
|
use crate::protocol::WireValue;
|
||||||
let rpc = fields.iter().find_map(|f| match (f.number, &f.value) { (21, WireValue::Bytes(b)) => Some(*b), _ => None });
|
let rpc = fields.iter().find_map(|f| match (f.number, &f.value) { (21, WireValue::Bytes(b)) => Some(*b), _ => None });
|
||||||
let rpc_fields = rpc.and_then(|r| crate::protocol::decode_wire(r).ok());
|
let rpc_fields = rpc.and_then(|r| crate::protocol::decode_wire(r).ok());
|
||||||
@@ -1222,18 +1223,18 @@ impl WebRtcSession {
|
|||||||
let _ = rpc_out.send(crate::initialization::envelope(out_sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response));
|
let _ = rpc_out.send(crate::initialization::envelope(out_sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Some(response) = rpc.and_then(|r| crate::protocol::decode_wire(r).ok()).and_then(|r| crate::terminal::rpc_response(&r)) {
|
if let Some(response) = rpc_fields.as_deref().and_then(crate::terminal::rpc_response) {
|
||||||
let ts = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs();
|
let ts = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default().as_secs();
|
||||||
let _ = rpc_out.send(crate::initialization::envelope(out_sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response));
|
let _ = rpc_out.send(crate::initialization::envelope(out_sequence.fetch_add(1, std::sync::atomic::Ordering::Relaxed), ts, 22, &response));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Ok(fields) = crate::protocol::decode_wire(&msg.data) {
|
if let Some(fields) = proto_fields.as_deref() {
|
||||||
if mapping.handle(&fields, &channel_name) { return; }
|
if mapping.handle(fields, &channel_name) { return; }
|
||||||
}
|
}
|
||||||
if let Some(files) = &file_worker {
|
if let Some(files) = &file_worker {
|
||||||
if let Ok(fields) = crate::protocol::decode_wire(&msg.data) {
|
if let Some(fields) = proto_fields.as_deref() {
|
||||||
if files.handle(&fields) {
|
if files.handle(fields) {
|
||||||
static ROUTE: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
static ROUTE: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||||
if ROUTE.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 20 {
|
if ROUTE.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 20 {
|
||||||
log::info!("File transfer RPC received on {}", channel_name);
|
log::info!("File transfer RPC received on {}", channel_name);
|
||||||
@@ -1259,16 +1260,16 @@ impl WebRtcSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
shape(&value,0).to_string()
|
shape(&value,0).to_string()
|
||||||
} else if let Ok(fields) = crate::protocol::decode_wire(&msg.data) {
|
} else if let Some(fields) = proto_fields.as_deref() {
|
||||||
format!("protobuf fields={:?}",fields.iter().map(|f|f.number).collect::<Vec<_>>())
|
format!("protobuf fields={:?}",fields.iter().map(|f|f.number).collect::<Vec<_>>())
|
||||||
} else { "opaque".to_string() };
|
} else { "opaque".to_string() };
|
||||||
log::info!("Clipboard channel schema: channel={} bytes={} schema={}",channel_name,msg.data.len(),shape);
|
log::info!("Clipboard channel schema: channel={} bytes={} schema={}",channel_name,msg.data.len(),shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if channel_name == "CONTROL_DATA_CHANNEL" || channel_name == "TEXT_DATA_CHANNEL" {
|
if channel_name == "CONTROL_DATA_CHANNEL" || channel_name == "TEXT_DATA_CHANNEL" {
|
||||||
if let Ok(fields) = crate::protocol::decode_wire(&msg.data) {
|
if let Some(fields) = proto_fields.as_deref() {
|
||||||
use crate::protocol::WireValue;
|
use crate::protocol::WireValue;
|
||||||
for field in &fields {
|
for field in fields {
|
||||||
if let (22,WireValue::Bytes(payload))=(field.number,&field.value) {
|
if let (22,WireValue::Bytes(payload))=(field.number,&field.value) {
|
||||||
let update=rich_incoming.lock().unwrap().response(payload);
|
let update=rich_incoming.lock().unwrap().response(payload);
|
||||||
match update {
|
match update {
|
||||||
@@ -1285,8 +1286,6 @@ impl WebRtcSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for field in &fields {
|
|
||||||
if let (21, WireValue::Bytes(payload)) = (field.number,&field.value) {
|
if let (21, WireValue::Bytes(payload)) = (field.number,&field.value) {
|
||||||
let ids=crate::clipboard_rich::format_ids(payload);
|
let ids=crate::clipboard_rich::format_ids(payload);
|
||||||
if !ids.is_empty(){log::info!("Clipboard offered format IDs: {:?}",ids);}
|
if !ids.is_empty(){log::info!("Clipboard offered format IDs: {:?}",ids);}
|
||||||
@@ -1324,8 +1323,6 @@ impl WebRtcSession {
|
|||||||
Err(reason)=>log::warn!("Clipboard RPC rejected: {}",reason),
|
Err(reason)=>log::warn!("Clipboard RPC rejected: {}",reason),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for field in &fields {
|
|
||||||
if let (17, WireValue::Bytes(payload)) = (field.number, &field.value) {
|
if let (17, WireValue::Bytes(payload)) = (field.number, &field.value) {
|
||||||
match clipboard_assembly.lock().unwrap().accept(payload) {
|
match clipboard_assembly.lock().unwrap().accept(payload) {
|
||||||
Ok(Some(text)) => {
|
Ok(Some(text)) => {
|
||||||
@@ -1452,69 +1449,87 @@ impl WebRtcSession {
|
|||||||
}
|
}
|
||||||
if let Ok(txt) = std::str::from_utf8(&msg.data) {
|
if let Ok(txt) = std::str::from_utf8(&msg.data) {
|
||||||
log::debug!("DataChannel [{}] received UTF-8 data: {} bytes", channel_name, txt.len());
|
log::debug!("DataChannel [{}] received UTF-8 data: {} bytes", channel_name, txt.len());
|
||||||
if let Ok(val) = serde_json::from_str::<serde_json::Value>(txt) {
|
if channel_name.contains("CONTROL") {
|
||||||
if !channel_name.contains("CONTROL") {
|
match crate::control_protocol::decode_control(&msg.data) {
|
||||||
// Input JSON on another channel (mobile input-method text was missing from CONTROL, #13/#46):
|
Ok(crate::control_protocol::ControlMessage::Input(event)) => {
|
||||||
// record action names only, once per name, and accept text_input wherever it arrives.
|
// A ready compositor source remains controllable on its lock screen.
|
||||||
if let Some(action) = val.get("action").and_then(serde_json::Value::as_str) {
|
if screen.backend == crate::desktop_backend::DesktopBackend::Portal
|
||||||
static SEEN: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
|
&& (screen.init_error.is_some() || !desktop_ready) { return; }
|
||||||
let mut seen = SEEN.lock().unwrap();
|
if !crate::wayland::input_ready() {return;}
|
||||||
if seen.len() < 32 && action.len() <= 40 && action.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_') && !seen.iter().any(|s| s == action) {
|
use crate::control_protocol::ControlInput;
|
||||||
seen.push(action.to_owned());
|
// Separate receipt budgets keep motion floods from hiding clicks.
|
||||||
log::info!("JSON action on {} channel: action={}", if channel_name.contains("STREAMER") {"STREAMER"} else if channel_name.contains("TEXT") {"TEXT"} else {"other"}, action);
|
static RECEIPTS: [std::sync::atomic::AtomicUsize; 3] = [const { std::sync::atomic::AtomicUsize::new(0) }; 3];
|
||||||
|
let (slot, kind) = match &event {
|
||||||
|
ControlInput::MouseButton {..} | ControlInput::MouseClick {..} => (0, "button"),
|
||||||
|
ControlInput::Keyboard {..} | ControlInput::KeyboardClick {..} | ControlInput::TextInput {..} => (1, "keyboard"),
|
||||||
|
_ => (2, "motion"),
|
||||||
|
};
|
||||||
|
if RECEIPTS[slot].fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 {
|
||||||
|
log::info!("CONTROL input received: kind={}", kind);
|
||||||
}
|
}
|
||||||
}
|
if let Some(session)=message_input_session.as_ref() {
|
||||||
if let Ok(crate::control_protocol::ControlMessage::Input(crate::control_protocol::ControlInput::TextInput {text})) = crate::control_protocol::decode_control(&msg.data) {
|
if matches!(&event, ControlInput::TextInput {..}) {
|
||||||
if let Some(session)=message_input_session.as_ref() { session.with_input(|| {if crate::wayland::input_ready() {input_worker.text_input(&text);}}); }
|
let (session, input, text) = match &event {
|
||||||
|
ControlInput::TextInput {text} => (session.clone(), input_worker.clone(), text.clone()),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
|
session.with_input(|| {
|
||||||
|
if crate::wayland::input_ready() { input.text_input(&text); }
|
||||||
|
});
|
||||||
|
}).await;
|
||||||
|
} else {
|
||||||
|
session.with_input(|| {
|
||||||
|
if !crate::wayland::input_ready() {return;}
|
||||||
|
match &event {
|
||||||
|
ControlInput::MouseAbsolute {x,y} => input_worker.mouse_absolute_normalized(*x,*y,crate::wayland::input_size(if live_x11 {crate::capture::x11_last_size().unwrap_or(input_size)} else {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),
|
||||||
|
ControlInput::KeyboardClick {key} => {input_worker.windows_key_event(*key, true);input_worker.windows_key_event(*key, false);},
|
||||||
|
ControlInput::MouseButton {button,pressed} => input_worker.wire_mouse_button(*button,*pressed),
|
||||||
|
ControlInput::MouseClick {button} => {input_worker.wire_mouse_button(*button,true);input_worker.wire_mouse_button(*button,false);},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
Ok(crate::control_protocol::ControlMessage::Unsupported(v)) => {
|
||||||
|
// Action name and key names only, never values (an IME text event would carry typed text).
|
||||||
|
static UNSUPPORTED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
||||||
|
if UNSUPPORTED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 {
|
||||||
|
let action = v.get("action").and_then(serde_json::Value::as_str)
|
||||||
|
.filter(|a| a.len() <= 40 && a.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_')).unwrap_or("?");
|
||||||
|
let keys: Vec<&str> = v.as_object().map(|o| o.keys().map(String::as_str).take(12).collect()).unwrap_or_default();
|
||||||
|
log::info!("Unsupported CONTROL input: action={action} keys={keys:?}");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
} else if let Ok(val) = serde_json::from_str::<serde_json::Value>(txt) {
|
||||||
|
// Input JSON on another channel (mobile input-method text was missing from CONTROL, #13/#46):
|
||||||
|
// record action names only, once per name, and accept text_input wherever it arrives.
|
||||||
|
if let Some(action) = val.get("action").and_then(serde_json::Value::as_str) {
|
||||||
|
static SEEN: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
|
||||||
|
let mut seen = SEEN.lock().unwrap();
|
||||||
|
if seen.len() < 32 && action.len() <= 40 && action.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_') && !seen.iter().any(|s| s == action) {
|
||||||
|
seen.push(action.to_owned());
|
||||||
|
log::info!("JSON action on {} channel: action={}", if channel_name.contains("STREAMER") {"STREAMER"} else if channel_name.contains("TEXT") {"TEXT"} else {"other"}, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if channel_name.contains("CONTROL") {
|
if let Ok(crate::control_protocol::ControlMessage::Input(crate::control_protocol::ControlInput::TextInput {text})) = crate::control_protocol::decode_control(&msg.data) {
|
||||||
match crate::control_protocol::decode_control(&msg.data) {
|
if let Some(session)=message_input_session.as_ref() {
|
||||||
Ok(crate::control_protocol::ControlMessage::Input(event)) => {
|
let (session, input) = (session.clone(), input_worker.clone());
|
||||||
// A ready compositor source remains controllable on its lock screen.
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
if screen.backend == crate::desktop_backend::DesktopBackend::Portal
|
session.with_input(|| {
|
||||||
&& (screen.init_error.is_some() || !desktop_ready) { return; }
|
if crate::wayland::input_ready() { input.text_input(&text); }
|
||||||
if !crate::wayland::input_ready() {return;}
|
});
|
||||||
use crate::control_protocol::ControlInput;
|
}).await;
|
||||||
// Separate receipt budgets keep motion floods from hiding clicks.
|
|
||||||
static RECEIPTS: [std::sync::atomic::AtomicUsize; 3] = [const { std::sync::atomic::AtomicUsize::new(0) }; 3];
|
|
||||||
let (slot, kind) = match &event {
|
|
||||||
ControlInput::MouseButton {..} | ControlInput::MouseClick {..} => (0, "button"),
|
|
||||||
ControlInput::Keyboard {..} | ControlInput::KeyboardClick {..} | ControlInput::TextInput {..} => (1, "keyboard"),
|
|
||||||
_ => (2, "motion"),
|
|
||||||
};
|
|
||||||
if RECEIPTS[slot].fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 {
|
|
||||||
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,crate::wayland::input_size(if live_x11 {crate::capture::x11_last_size().unwrap_or(input_size)} else {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),
|
|
||||||
ControlInput::TextInput {text} => input_worker.text_input(text),
|
|
||||||
ControlInput::KeyboardClick {key} => {input_worker.windows_key_event(*key, true);input_worker.windows_key_event(*key, false);},
|
|
||||||
ControlInput::MouseButton {button,pressed} => input_worker.wire_mouse_button(*button,*pressed),
|
|
||||||
ControlInput::MouseClick {button} => {input_worker.wire_mouse_button(*button,true);input_worker.wire_mouse_button(*button,false);},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
});}
|
|
||||||
|
|
||||||
},
|
|
||||||
Ok(crate::control_protocol::ControlMessage::Unsupported(v)) => {
|
|
||||||
// Action name and key names only, never values (an IME text event would carry typed text).
|
|
||||||
static UNSUPPORTED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
|
|
||||||
if UNSUPPORTED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 16 {
|
|
||||||
let action = v.get("action").and_then(serde_json::Value::as_str)
|
|
||||||
.filter(|a| a.len() <= 40 && a.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'_')).unwrap_or("?");
|
|
||||||
let keys: Vec<&str> = v.as_object().map(|o| o.keys().map(String::as_str).take(12).collect()).unwrap_or_default();
|
|
||||||
log::info!("Unsupported CONTROL input: action={action} keys={keys:?}");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
} else if channel_name.contains("STREAMER") {
|
}
|
||||||
|
if channel_name.contains("STREAMER") {
|
||||||
log::debug!("STREAMER channel JSON received");
|
log::debug!("STREAMER channel JSON received");
|
||||||
if let Some(event)=val.get("connection_period_stats_event") {
|
if let Some(event)=val.get("connection_period_stats_event") {
|
||||||
let nums=crate::viewer_metrics::collect(event);
|
let nums=crate::viewer_metrics::collect(event);
|
||||||
|
|||||||
Reference in new issue
Block a user