LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Remote desktop: the video follows the viewer's screen refresh (the page measures it and sends resize hz 24–360; the encoder runs at the fastest viewer's rate, up to 240; a session without a monitor composes at that rate) instead of a fixed 30; CPU blur faster again (two-channel sums, a vectorizable vertical step, no coverage work inside the edges) and canvas.c at -O3, same pixels: 18 → 35 frames a second on VM 116
Federico Pereira866b94be3931
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 66e4549..76a1981 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -51,7 +51,9 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),minutes; it now reaches the top in about 10 s on a local network and still slows down oncongestion. Software H.264 keeps its deblocking filter. Drawing without a GPU (a remote-onlysession, a virtual machine) is faster with the same pixels: the backdrop blur 2.5×, rounded- rectangles 2×; a video window under the blurred menu bar went from 18 to 23 frames a second. The page starts muted, as browsers+ rectangles 2×, and `canvas.c` builds at -O3. The video now follows the browser screen's refresh rate+ (60, 120, 144 Hz…) instead of a fixed 30: a video window under blurred windows went from 18 to 35+ frames a second on a virtual machine without a GPU. The page starts muted, as browsersrequire, and its sound button hides in the top bar: the first click or key in the session nowturns the sound on.- **Files → This computer** shows `/proc`, `/sys`, `/dev` and `/run` with a lock and says why itdiff --git a/docs/REMOTE.md b/docs/REMOTE.mdindex aa55e9d..2fb7746 100644--- a/docs/REMOTE.md+++ b/docs/REMOTE.md@@ -224,7 +224,7 @@ recovers on its own or says why and what to do.| Channel | Content ||---|---|-| video track | H.264 constrained baseline (packetization mode 1) or VP8, RTP over SRTP, 90 kHz clock; frames only when the screen changed, at most 30 per second, one more tiny frame 70 ms after the last change (browsers paint a lone frame late) |+| video track | H.264 constrained baseline (packetization mode 1) or VP8, RTP over SRTP, 90 kHz clock; frames only when the screen changed, at most as many per second as the fastest viewer's screen refreshes (the page measures it: 60, 120, 144 Hz…; 30 if unknown, 240 at most), one more tiny frame 70 ms after the last change (browsers paint a lone frame late) || audio track | Opus, 20 ms frames, mono 48 kHz, 64 kbit/s || `input` data channel | the same JSON input messages as the WebSocket (`m`, `b`, `w`, `s`, `pz`, `k`, `clip`, `resize`), parsed by the same `rs_browser_input`; at most 256 KB per message || `tiles` data channel | `[1][x,y,w,h u16][png]` a lossless tile; `[2][x,y,w,h…]` these areas changed (show the video there); `[3]` done |@@ -254,6 +254,13 @@ it only grows with what the browser receives, so as a fixed ceiling it kept a necurrent screen is encoded again for it. Two users means two sessions, two `lord-server`s and twoencoders, each as its own user.+**The frame rate follows the viewer's screen.** The page measures its screen's refresh rate with+animation frames (not while the tab is hidden) and sends it with its size (`resize`, `hz` 24–360). The+session's encoder runs at the fastest viewer's rate (it starts again when that changes), and a session+without a monitor composes at that rate too (at least 60); on the monitor, the monitor's own refresh+paces composition. Measured on VM 116 (no GPU, 1280×800, a 60 fps video window under blurred windows):+18 frames a second before 0.8.5's work on the CPU path, 35 after.+**The GPU keeps composing.** Until 0.8.3 a remote viewer switched the session to CPU composition.Now `gpu_frame` reads the composed frame back (`gpu_read_next`) once, for the encoder and the tiles,and the screen keeps its GPU composition. Only two cases still use the CPU path: protected windows ondiff --git a/server/Makefile b/server/Makefileindex c16a7ed..b8c4383 100644--- a/server/Makefile+++ b/server/Makefile@@ -546,6 +546,10 @@ build/obj/%.o: src/%.c $(HDR)@mkdir -p $(dir $@)$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -c -o $@ $<+# The CPU path's pixel loops (blur, rounded rectangles, blending) vectorize at -O3: the backdrop blur+# 9.6 → 5.3 ms and rounded rectangles 1.45× faster on x86-64, same pixels (a later -O3 wins over -O2)+build/obj/canvas.o: CFLAGS += -O3+# Third-party code: compiled as is, without our warnings.build/obj/ui/stb.o: src/ui/stb.c@mkdir -p $(dir $@)diff --git a/server/src/canvas.c b/server/src/canvas.cindex daeafaf..cc7e675 100644--- a/server/src/canvas.c+++ b/server/src/canvas.c@@ -439,27 +439,39 @@ void canvas_backdrop_blur(Canvas *c, float x, float y, float w, float h, float ruint32_t *buf = malloc((size_t)sw * sh * 4);uint32_t *tmp = malloc((size_t)sw * 4);if (!buf || !tmp) { free(buf); free(tmp); return; }- /* the f×f average, row by row (each source pixel read once) */- uint32_t *acc = calloc((size_t)sw * 4, 4);- if (!acc) { free(buf); free(tmp); return; }- for (int j = 0; j < sh; j++) {- memset(acc, 0, (size_t)sw * 16);- int rows = by1 - (by0 + j * f) < f ? by1 - (by0 + j * f) : f;- for (int v = 0; v < rows; v++) {- const uint32_t *row = c->px + (size_t)(by0 + j * f + v) * c->stride + bx0;- for (int i = 0, px = 0; px < bx1 - bx0; i++)- for (int u = 0; u < f && px < bx1 - bx0; u++, px++) {- uint32_t p = row[px], *a = acc + (size_t)i * 4;- a[0] += (p >> 16) & 255; a[1] += (p >> 8) & 255; a[2] += p & 255; a[3] += p >> 24;+ /* the f×f average, row by row (each source pixel read once). Two channels share a 32-bit sum+ * (red|blue, alpha|green: at most 16 × 255 each, f <= 4); f = 1 is a copy. */+ if (f == 1) {+ for (int j = 0; j < sh; j++) memcpy(buf + (size_t)j * sw, c->px + (size_t)(by0 + j) * c->stride + bx0, (size_t)sw * 4);+ } else {+ uint32_t *acc = malloc((size_t)sw * 2 * 4);+ if (!acc) { free(buf); free(tmp); return; }+ int span = bx1 - bx0, full = span / f;+ for (int j = 0; j < sh; j++) {+ memset(acc, 0, (size_t)sw * 8);+ int rows = by1 - (by0 + j * f) < f ? by1 - (by0 + j * f) : f;+ for (int v = 0; v < rows; v++) {+ const uint32_t *row = c->px + (size_t)(by0 + j * f + v) * c->stride + bx0;+ for (int i = 0; i < full; i++) {+ uint32_t rb = 0, ag = 0;+ const uint32_t *q = row + (size_t)i * f;+ for (int u = 0; u < f; u++) { rb += q[u] & 0x00ff00ffu; ag += (q[u] >> 8) & 0x00ff00ffu; }+ acc[i * 2] += rb;+ acc[i * 2 + 1] += ag;}+ for (int px = full * f; px < span; px++) {+ acc[full * 2] += row[px] & 0x00ff00ffu;+ acc[full * 2 + 1] += (row[px] >> 8) & 0x00ff00ffu;+ }+ }+ for (int i = 0; i < sw; i++) {+ int cols = bx1 - (bx0 + i * f) < f ? bx1 - (bx0 + i * f) : f;+ uint32_t n = (uint32_t)(cols * rows), rb = acc[i * 2], ag = acc[i * 2 + 1];+ buf[(size_t)j * sw + i] = n ? ((ag >> 16) / n) << 24 | ((rb >> 16) / n) << 16 | ((ag & 0xffff) / n) << 8 | ((rb & 0xffff) / n) : 0;+ }}- for (int i = 0; i < sw; i++) {- int cols = bx1 - (bx0 + i * f) < f ? bx1 - (bx0 + i * f) : f;- uint32_t n = (uint32_t)(cols * rows), *a = acc + (size_t)i * 4;- buf[(size_t)j * sw + i] = n ? (a[3] / n) << 24 | (a[0] / n) << 16 | (a[1] / n) << 8 | (a[2] / n) : 0;- }+ free(acc);}- free(acc);int rad = radius / (2 * f) > 0 ? radius / (2 * f) : 1;int win = 2 * rad + 1;uint8_t *dt = malloc((size_t)255 * win + 1);@@ -483,6 +495,15 @@ void canvas_backdrop_blur(Canvas *c, float x, float y, float w, float h, float rint *cx0 = malloc((size_t)cw * 3 * sizeof(int)), *hr = malloc((size_t)cw * 8 * sizeof(int));if (!cx0 || !hr) { free(cx0); free(hr); free(buf); free(tmp); return; }int *cx1 = cx0 + cw, *cfx = cx1 + cw, *hrow[2] = { hr, hr + (size_t)cw * 4 }, hidx[2] = { -1, -1 };+ uint32_t *vrow = malloc((size_t)cw * 4);+ if (!vrow) { free(cx0); free(hr); free(buf); free(tmp); return; }+ uint8_t *vrow8 = (uint8_t *)vrow;+ /* the columns whose coverage is whole on rows away from the corners: the same float tests as+ * the per-pixel path (i < x + 1, i + 1 > x + w - 1) */+ int in0 = x0, in1 = x1;+ while (in0 < x1 && in0 < x + 1) in0++;+ while (in1 > in0 && in1 - 1 + 1 > x + w - 1) in1--;+ if (in0 >= in1) in0 = in1 = x1;for (int i = x0; i < x1; i++) {float u = (i - bx0 + 0.5f) * inv - 0.5f;if (u < 0) u = 0;@@ -518,17 +539,30 @@ void canvas_backdrop_blur(Canvas *c, float x, float y, float w, float h, float r}if (want) bot = hrow[k]; else top = hrow[k];}+ /* the row of blurred pixels: the vertical step for every channel in one plain loop (bytes in+ * memory order are the channels of a little-endian 0xAARRGGBB) */+ for (int k = 0; k < cw * 4; k++) vrow8[k] = (uint8_t)(((top[k] << 8) + (bot[k] - top[k]) * fy) >> 16);int corner_row = j < y + r || j + 1 > y + h - r;+ int m0 = corner_row ? x1 : in0, m1 = corner_row ? x1 : in1;for (int i = x0; i < x1; i++) {+ if (i == m0) { /* inside the edges: no coverage to work out */+ for (; i < m1; i++) {+ uint32_t p = vrow[i - x0], d = row[i];+ if ((p >> 24) >= 255) { row[i] = p; continue; }+ uint32_t pa = p >> 24;+ uint32_t prb = p & 0xff00ff, pg = p & 0xff00, ia = 255 - pa;+ uint32_t drb = (((d & 0xff00ff) * ia) >> 8) & 0xff00ff, dg = (((d & 0xff00) * ia) >> 8) & 0xff00;+ row[i] = over_alpha(pa, d >> 24) << 24 | (prb + drb) | (pg + dg);+ }+ if (i >= x1) break;+ }uint32_t a = 255;if (corner_row || i < x + 1 || i + 1 > x + w - 1) {float cov = cov_of(rr_sdf(i + 0.5f, j + 0.5f, cx, cy, hw, hh, r));if (cov <= 0) continue;a = (uint32_t)(cov * 255 + 0.5f);}- const int *t = top + (size_t)(i - x0) * 4, *b = bot + (size_t)(i - x0) * 4;- uint32_t p = 0;- for (int s = 0; s < 4; s++) p |= (uint32_t)(((t[s] * 256 + (b[s] - t[s]) * fy) >> 16) & 255) << (s * 8);+ uint32_t p = vrow[i - x0];uint32_t d = row[i];/* premultiplied with its alpha: over the opaque UI it is the same as before; over the hole of* an app window (GPU path) it stays transparent and the app shows through */@@ -542,6 +576,7 @@ void canvas_backdrop_blur(Canvas *c, float x, float y, float w, float h, float r}free(cx0);free(hr);+ free(vrow);free(buf);free(tmp);}diff --git a/server/src/main.c b/server/src/main.cindex 33cdfb3..61ec0f6 100644--- a/server/src/main.c+++ b/server/src/main.c@@ -1762,8 +1762,10 @@ int main(int argc, char **argv) {}}int wants = !unseen && (ui.dirty || s.cursor_dirty || js_wants_frame() || wl_wants_frame() || media_wants_frame() || outs_have_work(&s));- /* sin monitor no hay vblank: a lo sumo 60 cuadros por segundo */- double pace = s.headless ? s.last_render + 16.6 - now_ms() : 0;+ /* no monitor, no vblank: 60 frames a second, or as fast as the fastest remote viewer's screen+ * (120, 144 Hz…) */+ int hz = mirror_fps() > 60 ? mirror_fps() : 60;+ double pace = s.headless ? s.last_render + 1000.0 / hz - 0.4 - now_ms() : 0;if (wants && !all_busy(&s) && pace <= 0) { render(&s); wants = 0; }if (wants && pace > 0 && (delay < 0 || pace < delay)) delay = pace;diff --git a/server/src/media/helper/lm_stream.c b/server/src/media/helper/lm_stream.cindex 405c1ac..d3d0101 100644--- a/server/src/media/helper/lm_stream.c+++ b/server/src/media/helper/lm_stream.c@@ -284,7 +284,7 @@ void lm_stream(const char *params, int ring_fd, int render) {int w = (int)mp_param_int(params, "width", 0), h = (int)mp_param_int(params, "height", 0);int fps = (int)mp_param_int(params, "fps", 30);long kbps = mp_param_int(params, "kbps", 4000);- if (fps < 5 || fps > 60) fps = 30;+ if (fps < 5 || fps > 240) fps = 30;if (kbps < 200 || kbps > 50000) kbps = 4000;char accel[24];AVBufferRef *hw = codec == CODEC_H264 ? lm_hw_device(lm_hw_accel(params, accel, sizeof accel), render) : NULL;diff --git a/server/src/media/mstream.c b/server/src/media/mstream.cindex e3ba9fb..1c0c59d 100644--- a/server/src/media/mstream.c+++ b/server/src/media/mstream.c@@ -19,7 +19,7 @@#include <time.h>#include <unistd.h>-#define FPS 30+#define FPS_MAX 240 /* what the encoder is asked for at most (the viewers' screens decide) */#define MAX_FRAME (8u << 20)typedef struct {@@ -28,6 +28,7 @@ typedef struct {unsigned kbps, sent_kbps;int w, h, pending, want_key, flushing;double t0, last_feed, retry_at, flush_at;+ int fps; /* frames a second (the fastest viewer's screen) */uint8_t *buf;size_t len, cap, total;long frames, enc100;@@ -110,7 +111,7 @@ static int start(Enc *e, int codec) {if (e->audio) s->mic = maudio_open(1, "LordOS", "Remote desktop", "@DEFAULT_MONITOR@", &ring);char params[200];snprintf(params, sizeof params, "codec=%s\nwidth=%d\nheight=%d\nfps=%d\nkbps=%u\nhw=%d\nhwaccel=%s\naudio=%d\nrender=%d\n",- codec == 1 ? "h264" : "vp8", fw, fh, FPS, e->kbps, render >= 0, media_hwaccel(), ring >= 0, render >= 0);+ codec == 1 ? "h264" : "vp8", fw, fh, e->fps, e->kbps, render >= 0, media_hwaccel(), ring >= 0, render >= 0);int fds[2] = { ring, render };s->sock = media_spawn(MK_STREAM, params, fds, 2, &s->pid);if (render >= 0) close(render);@@ -146,7 +147,7 @@ static int start(Enc *e, int codec) {e->pending = 1;e->sent_kbps = e->kbps;e->want_key = 0;- fprintf(stderr, "remote: video encoder for %s started (%dx%d, %u kbit/s%s)\n", codec == 1 ? "H.264" : "VP8", fw, fh, e->kbps,+ fprintf(stderr, "remote: video encoder for %s started (%dx%d, %d fps, %u kbit/s%s)\n", codec == 1 ? "H.264" : "VP8", fw, fh, e->fps, e->kbps,ring >= 0 ? ", with sound" : "");return 0;}@@ -156,9 +157,12 @@ int mstream_active(void) {return 0;}-void mstream_want(int codec, int viewers, int audio, unsigned kbps) {+void mstream_want(int codec, int viewers, int audio, unsigned kbps, int fps) {if (codec < 1 || codec >= MS_CODECS) return;Enc *e = &E[codec];+ fps = fps < 24 ? 30 : fps > FPS_MAX ? FPS_MAX : fps;+ if (e->id && fps != e->fps) stop(e); /* another frame rate: the encoder starts again */+ e->fps = fps;int was = e->viewers;e->viewers = viewers;e->kbps = kbps < 300 ? 300 : kbps > 20000 ? 20000 : kbps;@@ -194,7 +198,7 @@ static void feed(Enc *e, int codec) {* often only when the next one arrives */if (!e->pending && e->flush_at && t >= e->flush_at) { e->pending = 1; e->flush_at = 0; e->flushing = 1; }if (!e->pending || !fpx) return;- if (t - e->last_feed < 1000.0 / FPS - 1) return;+ if (t - e->last_feed < 1000.0 / e->fps - 1) return;int slot = -1;for (int i = 0; i < s->in_slots; i++) if (!s->in_busy[i]) { slot = i; break; }if (slot < 0) return; /* the encoder is behind: the newest frame waits */@@ -233,7 +237,7 @@ double mstream_timeout(void) {for (int c = 1; c < MS_CODECS; c++) {Enc *e = &E[c];if (!e->viewers) continue;- double d = !e->id ? (e->retry_at > t ? e->retry_at - t : 200) : e->pending ? 1000.0 / FPS - (t - e->last_feed)+ double d = !e->id ? (e->retry_at > t ? e->retry_at - t : 200) : e->pending ? 1000.0 / e->fps - (t - e->last_feed): e->flush_at ? e->flush_at - t : -1;if (d >= 0 && d < 4) d = 4;if (d >= 0 && (best < 0 || d < best)) best = d;diff --git a/server/src/media/mstream.h b/server/src/media/mstream.hindex 8cc7309..c3fcc8b 100644--- a/server/src/media/mstream.h+++ b/server/src/media/mstream.h@@ -16,7 +16,7 @@ typedef struct {void mstream_init(const MStreamOut *out);/* How many viewers want this codec, with sound, and the lowest bit rate among them. 0 viewers stops it. */-void mstream_want(int codec, int viewers, int audio, unsigned kbps);+void mstream_want(int codec, int viewers, int audio, unsigned kbps, int fps);/* The session's screen changed (the frame stays valid until the next call or mstream_want(…, 0)). */void mstream_frame(const uint32_t *px, int stride, int w, int h);void mstream_keyframe(int codec);diff --git a/server/src/remote/client.html b/server/src/remote/client.htmlindex 92a5e60..5c563ca 100644--- a/server/src/remote/client.html+++ b/server/src/remote/client.html@@ -147,12 +147,31 @@ function fit() {ox = r.left; oy = r.top;}addEventListener('resize', fit);-// The session takes the window's size (if the monitor is showing it, the monitor wins).-let resizeTimer = 0;+// The session takes the window's size (if the monitor is showing it, the monitor wins), and the video+// this screen's refresh rate (60, 120, 144 Hz…), measured with animation frames once the page shows.+let resizeTimer = 0, screenHz = 0;+function sendSize() {+ const m = { t: 'resize', w: Math.round(innerWidth) & ~1, h: Math.round(innerHeight) & ~1 };+ if (screenHz) m.hz = screenHz;+ send(m);+}addEventListener('resize', () => {clearTimeout(resizeTimer);- resizeTimer = setTimeout(() => send({ t: 'resize', w: Math.round(innerWidth) & ~1, h: Math.round(innerHeight) & ~1 }), 400);+ resizeTimer = setTimeout(sendSize, 400);});+function measureHz() {+ let n = 0, t0 = 0;+ const step = (t) => {+ if (!t0) t0 = t;+ if (t - t0 < 1000) { n++; requestAnimationFrame(step); return; }+ const raw = n * 1000 / (t - t0);+ if (document.hidden || raw < 24) return; // a hidden tab is throttled: no measure+ const hz = [30, 48, 50, 60, 72, 75, 90, 100, 120, 144, 165, 180, 240].reduce((a, b) => (Math.abs(b - raw) < Math.abs(a - raw) ? b : a));+ if (hz !== screenHz) { screenHz = hz; sendSize(); }+ };+ requestAnimationFrame(step);+}+document.addEventListener('visibilitychange', () => { if (!document.hidden) measureHz(); });function send(o) { if (ws && ws.readyState === 1) ws.send(JSON.stringify(o)); }// Input goes over the WebRTC data channel when it's open (lower latency), else over the WebSocket.@@ -415,7 +434,7 @@ function connect() {helloSeen = false;ws = new WebSocket(`wss://${location.host}/ws?w=${w}&h=${h}&v=1`);ws.binaryType = 'arraybuffer';- ws.onopen = () => { rd.wsOpens++; send({ t: 'resize', w: w & ~1, h: h & ~1 }); }; // an existing session takes this size+ ws.onopen = () => { rd.wsOpens++; sendSize(); measureHz(); }; // an existing session takes this sizews.onmessage = (e) => (typeof e.data === 'string' ? onText(JSON.parse(e.data)) : onBin(new Uint8Array(e.data)));ws.onclose = () => {ws = null;diff --git a/server/src/remote/conn.c b/server/src/remote/conn.cindex 1f90400..5cc17cf 100644--- a/server/src/remote/conn.c+++ b/server/src/remote/conn.c@@ -606,6 +606,8 @@ static int vmode; /* the video plays: the lossless refreshstatic int tiles_lost; /* a refresh tile didn't fit the data channel: ask for them all again */static double tiles_lost_at;static Rtc *rtc;+static int view_hz; /* the browser screen's refresh rate (resize "hz"), 0 unknown */+static void video_want(void);static const char *rtc_dead; /* RTC_WHY_* of a peer that just failed */static int resets; /* peers made after the first; the current one is number resets + 1 */static double reset_at;@@ -788,7 +790,12 @@ static void from_browser(const char *j, size_t n, int dc) {sess_send(RP_KEY, p, 3);break;}- case RS_IN_RESIZE: { uint16_t sz[2] = { (uint16_t)in.a, (uint16_t)in.b }; sess_send(RP_RESIZE, sz, 4); break; }+ case RS_IN_RESIZE: {+ uint16_t sz[2] = { (uint16_t)in.a, (uint16_t)in.b };+ sess_send(RP_RESIZE, sz, 4);+ if (in.v1 && in.v1 != view_hz) { view_hz = in.v1; if (rtc && rtc_media_ready(rtc)) video_want(); }+ break;+ }case RS_IN_PING: ws_text("{\"t\":\"pong\",\"ts\":%lld}", in.ts); break;case RS_IN_CLIP: sess_send(RP_SETCLIP, in.text, in.tlen); break;case RS_IN_RTC:@@ -872,15 +879,21 @@ static int conns_full(void) {return n >= RD_MAX_CONNS;}+/* this viewer takes the session's encoded video: u8 codec, u8 sound, u16 frames a second (the browser+ * screen's refresh; 0 unknown), u32 kbit/s */+static void video_want(void) {+ unsigned char v[8] = { (unsigned char)rtc_codec(rtc), 1, 0, 0 };+ uint16_t hz = (uint16_t)view_hz;+ uint32_t k = 4000;+ memcpy(v + 2, &hz, 2);+ memcpy(v + 4, &k, 4);+ sess_send(RP_VIDEO, v, 8);+}static void rtc_signal(void *ud, const char *json) { (void)ud; ws_frame(1, json, strlen(json), NULL, 0); }static void rtc_state(void *ud, int st, const char *why) {(void)ud;if (st == RTC_CONNECTED) {- /* this viewer takes the session's encoded video: u8 codec, u8 sound, u16 0, u32 kbit/s */- unsigned char v[8] = { (unsigned char)rtc_codec(rtc), 1, 0, 0 };- uint32_t k = 4000;- memcpy(v + 4, &k, 4);- sess_send(RP_VIDEO, v, 8);+ video_want();} else if (st == RTC_FAILED) rtc_dead = why ? why : RTC_WHY_SERVER;}static void rtc_message(void *ud, int chan, const uint8_t *p, size_t n, int binary) {diff --git a/server/src/remote/mirror.c b/server/src/remote/mirror.cindex 70bdf12..bb970ad 100644--- a/server/src/remote/mirror.c+++ b/server/src/remote/mirror.c@@ -50,6 +50,7 @@ typedef struct {/* the video path (docs/REMOTE.md, "Video (WebRTC)") */int vcodec, vaudio, vneed_key; /* subscribed to the session's encoder (1 H.264, 2 VP8) */unsigned vkbps;+ int vfps; /* the frame rate this viewer's screen shows (its refresh; 30 if unknown) */int vmode; /* the video plays: lossless tiles once still, damage right away */} Client;@@ -136,7 +137,7 @@ static void notify_clients(void) {/* Who wants which encoder: viewers per codec, sound, and the slowest viewer's rate. */static void video_update(void) {for (int k = 1; k < MS_CODECS; k++) {- int n = 0, audio = 0;+ int n = 0, audio = 0, fps = 0;unsigned kbps = 0;for (int i = 0; i < MAX_CLIENTS; i++) {const Client *c = &cl[i];@@ -144,8 +145,9 @@ static void video_update(void) {n++;audio |= c->vaudio;if (!kbps || c->vkbps < kbps) kbps = c->vkbps;+ if (c->vfps > fps) fps = c->vfps; /* the fastest screen: a slower one shows what it can */}- mstream_want(k, n, audio, kbps ? kbps : 4000);+ mstream_want(k, n, audio, kbps ? kbps : 4000, fps);}}@@ -296,6 +298,9 @@ static void handle(Client *c, int type, const unsigned char *d, uint32_t n) {c->vcodec = d[0];c->vaudio = d[1] != 0;c->vkbps = k < 300 ? 300 : k > 20000 ? 20000 : k;+ uint16_t hz;+ memcpy(&hz, d + 2, 2);+ c->vfps = hz >= 24 && hz <= 360 ? hz : 30;if (c->vcodec && c->vcodec != was) c->vneed_key = 1;video_update();if (c->vcodec && fb) mstream_frame(fb, W, W, H);@@ -477,6 +482,13 @@ int mirror_clients(void) {return n;}+/* The frame rate the remote viewers' screens show (the fastest), 0 without video viewers. */+int mirror_fps(void) {+ int f = 0;+ for (int i = 0; i < MAX_CLIENTS; i++) if (cl[i].fd >= 0 && !cl[i].seat && cl[i].vcodec && cl[i].vfps > f) f = cl[i].vfps;+ return f;+}+int mirror_watchers(void) {int n = 0;for (int i = 0; i < MAX_CLIENTS; i++) if (cl[i].fd >= 0 && !cl[i].seat && cl[i].vcodec) n++;diff --git a/server/src/remote/mirror.h b/server/src/remote/mirror.hindex 8b01b1b..1c11e62 100644--- a/server/src/remote/mirror.h+++ b/server/src/remote/mirror.h@@ -40,6 +40,7 @@ int mirror_clients(void); /* remote desktop connecti/* Connections that take the video now (RP_VIDEO): only for them is the screen captured, compared and* encoded. A browser that is still connecting, or reconnecting its peer, costs nothing. */int mirror_watchers(void);+int mirror_fps(void); /* the fastest remote viewer screen's refresh, 0 without video viewers */int mirror_has_seat(void); /* is lord-sessiond (monitor) connected? *//* Requests from the session to whoever shows it (short JSON): RP_SESSION to every connection* ({"a":"lock"}: lock; {"a":"switch"}: switch user) and RP_GREETER to the monitor. */diff --git a/server/src/remote/rsec.c b/server/src/remote/rsec.cindex d162986..d409243 100644--- a/server/src/remote/rsec.c+++ b/server/src/remote/rsec.c@@ -575,6 +575,10 @@ int rs_browser_input(const RsJson *j, int W, int H, RsInput *in) {if (rs_json_num(j, "w", &a) || rs_json_num(j, "h", &b) || a < 640 || b < 480 || a > 3840 || b > 2400) return RS_IN_NONE;in->a = (int)(a & ~1LL);in->b = (int)(b & ~1LL);+ /* optional: the browser screen's refresh rate (24..360 Hz), for the video's frame rate */+ long long hz = 0;+ if (!rs_json_num(j, "hz", &hz) && (hz < 24 || hz > 360)) return RS_IN_NONE;+ in->v1 = (int32_t)hz;return in->type = RS_IN_RESIZE;}if (!strcmp(t, "ping")) {diff --git a/server/src/remote/rsec.h b/server/src/remote/rsec.hindex 50d19fe..3e87a21 100644--- a/server/src/remote/rsec.h+++ b/server/src/remote/rsec.h@@ -110,7 +110,7 @@ typedef struct {int type;int a, b; /* PTR x,y · BTN button,down · WHEEL steps · KEY code,down · RESIZE w,h · SCROLL/PINCH phase · VMODE on* · RTC/ICE the peer number "p" (0 if absent) */- int32_t v1, v2; /* SCROLL dx,dy (1/256 px) · PINCH scale ×65536, rotation ×256 */+ int32_t v1, v2; /* SCROLL dx,dy (1/256 px) · PINCH scale ×65536, rotation ×256 · RESIZE v1: hz (0 unknown) */long long ts; /* PING */const char *text; /* CLIP, RTC (the SDP offer), ICE (a candidate; "" ends) (inside the RsJson buffer) */size_t tlen;diff --git a/server/tests/remote_sec_test.c b/server/tests/remote_sec_test.cindex 6c98fd7..ab96979 100644--- a/server/tests/remote_sec_test.c+++ b/server/tests/remote_sec_test.c@@ -282,6 +282,10 @@ static void test_json(void) {CHECK(jin("{\"t\":\"resize\",\"w\":1921,\"h\":1080}", 1280, 800, &in) == RS_IN_RESIZE && in.a == 1920);CHECK(jin("{\"t\":\"resize\",\"w\":100000,\"h\":1080}", 1280, 800, &in) == RS_IN_NONE);CHECK(jin("{\"t\":\"resize\",\"w\":100,\"h\":100}", 1280, 800, &in) == RS_IN_NONE);+ CHECK(jin("{\"t\":\"resize\",\"w\":1920,\"h\":1080}", 1280, 800, &in) == RS_IN_RESIZE && in.v1 == 0);+ CHECK(jin("{\"t\":\"resize\",\"w\":1920,\"h\":1080,\"hz\":144}", 1280, 800, &in) == RS_IN_RESIZE && in.v1 == 144);+ CHECK(jin("{\"t\":\"resize\",\"w\":1920,\"h\":1080,\"hz\":1000}", 1280, 800, &in) == RS_IN_NONE);+ CHECK(jin("{\"t\":\"resize\",\"w\":1920,\"h\":1080,\"hz\":-60}", 1280, 800, &in) == RS_IN_NONE);CHECK(jin("{\"t\":\"ping\",\"ts\":123}", 1280, 800, &in) == RS_IN_PING && in.ts == 123);CHECK(jin("{\"t\":\"ack\"}", 1280, 800, &in) == RS_IN_NONE); /* the image path's ack is gone (0.8.4) */CHECK(jin("{\"t\":\"clip\",\"text\":\"h\\u00e9\\ud83d\\udc51\\n\"}", 1280, 800, &in) == RS_IN_CLIP && in.tlen == 8 &&