From 92853172a68d875bbf43ac3408a114220241edc1 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Fri, 30 Oct 2026 17:09:55 +0100 Subject: [PATCH 1/2] fix(web): rate the connection dot from the wire The dot divided presentation skips by decoded frames, and two decoded frames between two animation frames is routine, so it read poor on nearly every 60 fps stream. The rule now comes from core (`hud::quality`) on the wire's facts: lost frames, FEC repairs and round trip, worst of the last three windows. Skips stay in the overlay's skipped line. --- README.md | 4 ++-- apps/web/src/ui/fixtures.ts | 2 +- apps/web/src/ui/hud.tsx | 23 ++++++++++------------- apps/web/src/ui/types.ts | 2 ++ packages/stream/build.sh | 2 +- packages/stream/rust/session.rs | 12 ++++++++++++ packages/stream/src/emscripten.d.ts | 2 ++ packages/stream/src/engine.test.ts | 19 +++++++++++++++++++ packages/stream/src/engine.ts | 9 +++++++++ 9 files changed, 58 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 6b5e946..1132fd0 100644 --- a/README.md +++ b/README.md @@ -318,8 +318,8 @@ A `v*` tag builds everything above and attaches the app as - **The microphone does not go back.** Host → browser audio plays; browser → host is the same plane the other way (`0xCB`) and is not written yet. -- **Latency and packet loss are not reported.** `SessionStats` has the fields; only decoder drops - are filled in, so the quality dot is coarse rather than wrong. +- **Latency and packet loss are not on `SessionStats`.** The stats overlay prints them and the + quality dot is rated from them in core; the engine's own counters stop at decoder drops. - **Codec and HDR are pinned** in `rust/session.rs`. Choosing either needs the wire, not a control. - **Resize renegotiation is off by default.** The observer is hard-debounced and the host rebuilds diff --git a/apps/web/src/ui/fixtures.ts b/apps/web/src/ui/fixtures.ts index 2578a27..361d51f 100644 --- a/apps/web/src/ui/fixtures.ts +++ b/apps/web/src/ui/fixtures.ts @@ -35,7 +35,7 @@ const art = new Map(entries.map((e, i) => [e.id, cover(i * 31)] as const)); const stats = { origin: "https://192.168.1.25:47990", width: 2560, height: 1440, fps: 60, accessUnits: 18_432, - decoded: 18_400, dropped: 12, uploadMs: 0.8, backend: "webgpu" as const, + decoded: 18_400, dropped: 12, quality: "good" as const, uploadMs: 0.8, backend: "webgpu" as const, pointerCaptured: false, audio: { state: "playing" as const, frames: 91_204, lost: 3, errors: 0, underruns: 1 }, hud: [ diff --git a/apps/web/src/ui/hud.tsx b/apps/web/src/ui/hud.tsx index 6496468..baabb23 100644 --- a/apps/web/src/ui/hud.tsx +++ b/apps/web/src/ui/hud.tsx @@ -22,18 +22,15 @@ const FADE = { duration: 0.18, ease: "easeOut" } as const; const DROP = { initial: { opacity: 0, y: -8 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -8 }, transition: FADE }; const RISE = { initial: { opacity: 0, y: 8 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 8 }, transition: FADE }; -/** Connection quality, from what the decoder saw. - * - * Drops alone, because drops are the only loss signal the engine reports today; jitter and - * packet loss are on `SessionStats` but not yet filled in, and a dot that lies is worse than a - * coarse one. The thresholds are what reads as "smooth" and "visibly hitching" at 60 fps. */ -function quality(s: SessionStats): { variant: BadgeVariant; text: string } { - if (!s.decoded) return { variant: "outline", text: "starting" }; - const lost = s.dropped / Math.max(1, s.decoded + s.dropped); - if (lost < 0.005) return { variant: "success", text: "good" }; - if (lost < 0.03) return { variant: "warning", text: "fair" }; - return { variant: "destructive", text: "poor" }; -} +/** The connection dot is the wire's verdict, rated in core (`hud::quality`) from loss, repairs + * and round trip. Presentation skips are the page's own pacing, not loss: they stay in the + * overlay's skipped line. */ +const QUALITY: Record = { + starting: { variant: "outline", text: "starting" }, + good: { variant: "success", text: "good" }, + fair: { variant: "warning", text: "fair" }, + poor: { variant: "destructive", text: "poor" }, +}; export function Hud({ screen, actions }: { screen: Extract; actions: Actions }): JSX.Element { const [idle, setIdle] = useState(false); @@ -56,7 +53,7 @@ export function Hud({ screen, actions }: { screen: Extract, text: String, + /// The connection dot's last three windows. + quality: hud::QualityState, /// The shared post-loss freeze: the page withholds decoded frames until the stream /// re-anchors, as every native client does. gate: ReanchorGate, @@ -142,6 +144,7 @@ impl Client { fps: 0, snap: None, text: String::new(), + quality: hud::QualityState::default(), gate: ReanchorGate::new(0), next_index: None, pending_rfi: None, @@ -216,6 +219,7 @@ pub extern "C" fn pf_session_reset() { c.receipts.clear(); c.snap = None; c.text.clear(); + c.quality = hud::QualityState::default(); }); crate::audio::reset(); crate::rumble::reset(); @@ -924,10 +928,18 @@ pub extern "C" fn pf_hud_drain(skipped: u32) { snap.decoder = "WebCodecs".into(); let rtt = crate::transport::rtt_us(); snap.rtt_us = (rtt > 0).then_some(rtt); + hud::quality(&snap, &mut c.quality); c.snap = Some(snap); }); } +/// The connection dot, `0` starting to `3` poor ([`hud::Quality::index`]), as of the last +/// [`pf_hud_drain`]. +#[unsafe(no_mangle)] +pub extern "C" fn pf_hud_quality() -> u32 { + CLIENT.with(|c| c.borrow().quality.shown().index()) +} + /// The last window as overlay lines (`\t\n` each) for `tier` (`StatsVerbosity` /// index) and vocabulary. Returns the byte length; [`pf_hud_text_ptr`] points at the bytes until /// the next call. diff --git a/packages/stream/src/emscripten.d.ts b/packages/stream/src/emscripten.d.ts index 0c43960..2a65196 100644 --- a/packages/stream/src/emscripten.d.ts +++ b/packages/stream/src/emscripten.d.ts @@ -106,6 +106,8 @@ export interface PunktfunkModule { _pf_request_keyframe(): void; /** Close the overlay window. `skipped`: frames replaced before drawing since the last call. */ _pf_hud_drain(skipped: number): void; + /** The connection dot as of the last drain: `0` starting, `1` good, `2` fair, `3` poor. */ + _pf_hud_quality(): number; /** Format the last window at `tier` (0–3) in the Advanced vocabulary or not; byte length. */ _pf_hud_text(tier: number, advanced: number): number; /** Where `_pf_hud_text` left its bytes: `\t\n` per line. */ diff --git a/packages/stream/src/engine.test.ts b/packages/stream/src/engine.test.ts index f16a230..721590a 100644 --- a/packages/stream/src/engine.test.ts +++ b/packages/stream/src/engine.test.ts @@ -230,3 +230,22 @@ test("the bridge is remembered for the origin, and forgotten when it fails", asy dial(engine); assert.equal(dialled.at(-1), "https://192.168.1.21:9778/pf2", "WebTransport first again"); }); + +test("the connection dot is the wire's rating, read once a second", () => { + const { engine, mod } = engineIn("ready"); + Object.assign(mod, { + _pf_session_phase: () => 2, + _pf_session_audio_channels: () => 0, + _pf_hud_text: () => 0, + }); + const snapshot = () => ({ width: 0, height: 0, decoded: 60, dropped: 30, uploadMs: 0, backend: null }); + Object.assign(engine, { video: { snapshot } }); + const second = (rating: number) => { + mod._pf_hud_quality = () => rating; + Object.assign(engine, { lastSecond: performance.now() - 1000 }); + (engine as unknown as { updateSession(): void }).updateSession(); + return (engine.current as { stats: { quality: string } }).stats.quality; + }; + assert.equal(second(3), "poor"); + assert.equal(second(0), "starting"); +}); diff --git a/packages/stream/src/engine.ts b/packages/stream/src/engine.ts index 8b35291..e9e1e88 100644 --- a/packages/stream/src/engine.ts +++ b/packages/stream/src/engine.ts @@ -73,6 +73,8 @@ export interface HudLine { text: string; } const ROLES: readonly HudLine["role"][] = ["primary", "detail", "muted", "warn"]; +/** `_pf_hud_quality`'s numbers, in order. */ +const QUALITY: readonly SessionStats["quality"][] = ["starting", "good", "fair", "poor"]; const UTF8 = new TextDecoder(); export interface SessionStats { @@ -84,6 +86,9 @@ export interface SessionStats { accessUnits: number; decoded: number; dropped: number; + /** The connection, rated from the wire's loss, repairs and round trip; presentation skips + * never count. `starting` until the first second closes. */ + quality: "starting" | "good" | "fair" | "poor"; /** Average milliseconds uploading a frame to the video plane. */ uploadMs: number; backend: "webgpu" | "webgl2" | null; @@ -277,6 +282,7 @@ export class Engine { /** What the last `streaming` notification showed, so an unchanged frame notifies no one. */ private shown = ""; private lastDropped = 0; + private quality: SessionStats["quality"] = "starting"; /** The last launch notice and when it arrived (`performance.now()`). */ private launchNotice: { text: string; at: number } | null = null; /** The session's last access advert, read when its counter moves, with its deadline on @@ -683,6 +689,7 @@ export class Engine { this.tier = this.tunable.statsTier; this.hud = []; this.lastDropped = 0; + this.quality = "starting"; // The wasm frame count starts again at zero with each session. this.lastFrames = 0; this.lastSecond = performance.now(); @@ -1314,6 +1321,7 @@ export class Engine { const dropped = v?.dropped ?? 0; this.mod._pf_hud_drain(Math.max(0, dropped - this.lastDropped)); this.lastDropped = dropped; + this.quality = QUALITY[this.mod._pf_hud_quality()] ?? "starting"; this.hud = this.readHud(); } const state: EngineState = { @@ -1326,6 +1334,7 @@ export class Engine { accessUnits: frames, decoded: v?.decoded ?? 0, dropped: v?.dropped ?? 0, + quality: this.quality, uploadMs: v?.uploadMs ?? 0, audio: this.audio?.snapshot() ?? { state: "off", frames: 0, lost: 0, errors: 0, underruns: 0 }, backend: v?.backend ?? null, From 84da5fcde0ab03cf99143908b73b3d70459cf94c Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Fri, 30 Oct 2026 18:22:16 +0100 Subject: [PATCH 2/2] chore(stream): pin core to main with the quality rule The rev is punktfunk main at eb990a68. It carries #2214 (`hud::quality`, which the dot reads) and #2213 (`abr::feed` with an exported `stream_ceiling_kbps`). The server follows the same rev. --- packages/stream/Cargo.lock | 8 ++++---- packages/stream/Cargo.toml | 8 ++++---- server/Cargo.lock | 4 ++-- server/Cargo.toml | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/stream/Cargo.lock b/packages/stream/Cargo.lock index 5e2d9e3..54159eb 100644 --- a/packages/stream/Cargo.lock +++ b/packages/stream/Cargo.lock @@ -531,7 +531,7 @@ dependencies = [ [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" [[package]] name = "fiat-crypto" @@ -997,7 +997,7 @@ dependencies = [ [[package]] name = "pf-client-core" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" dependencies = [ "anyhow", "cfg_aliases", @@ -1012,7 +1012,7 @@ dependencies = [ [[package]] name = "pf-console-ui" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" dependencies = [ "anyhow", "pf-client-core", @@ -1105,7 +1105,7 @@ dependencies = [ [[package]] name = "punktfunk-core" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" dependencies = [ "aes-gcm", "aws-lc-rs", diff --git a/packages/stream/Cargo.toml b/packages/stream/Cargo.toml index df7eb60..92524f1 100644 --- a/packages/stream/Cargo.toml +++ b/packages/stream/Cargo.toml @@ -15,7 +15,7 @@ name = "punktfunk-client-web" path = "rust/main.rs" # The punktfunk crates follow the host's release tags, all three together: the client speaks that -# release's wire. This is v0.45.0. +# release's wire. This is main at eb990a68, ahead of v0.45.0. [dependencies] anyhow = "1" # The device fingerprint: SHA-256 of the WebCrypto key's SPKI, which is what the host stores. @@ -23,7 +23,7 @@ anyhow = "1" sha2 = "0.11" # `transport::Transport`, the wire codecs and the SPAKE2 ceremony. `pake`, not `quic`: the # browser plane is WebTransport, so the ceremony is wanted and the quinn runtime under it is not. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "9a230631e9867b02fb5298a8cc6f6feb544b274f", default-features = false, features = ["pake"] } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "eb990a68305046336025ba115c9fff2ba395238a", default-features = false, features = ["pake"] } # wasm only. Off it this is a bin that prints how to build it, so `cargo test` on a developer's # desktop stays green and does not resolve skia-safe for a target that wants a second Skia @@ -32,12 +32,12 @@ punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "9a230631e9 # The shell itself. `default-features = false`: `vulkan-overlay` is the desktop session binary's, # and it would put `vulkan` on skia-safe and change the prebuilt key away from # `ganesh-gl-jpegd-jpege-pdf-textlayout`, the one build.sh downloads for this target. -pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "9a230631e9867b02fb5298a8cc6f6feb544b274f", default-features = false } +pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "eb990a68305046336025ba115c9fff2ba395238a", default-features = false } # The bridge's JSON both ways: the model the page pushes, what the shell raises. serde = "1" serde_json = "1" # The portable half — `trust::Settings` for the snapshot store the shell loads from. -pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "9a230631e9867b02fb5298a8cc6f6feb544b274f", default-features = false } +pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "eb990a68305046336025ba115c9fff2ba395238a", default-features = false } # The SAME line pf-console-ui's wasm block carries, features included: two feature sets in one # build resolve two prebuilt keys, and the second one puts a source build of Skia on the critical # path. Only `host.rs` names it, to build the context and wrap the canvas. diff --git a/server/Cargo.lock b/server/Cargo.lock index e159931..deb69ea 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -544,7 +544,7 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "fec-rs" version = "0.1.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" [[package]] name = "find-msvc-tools" @@ -1403,7 +1403,7 @@ dependencies = [ [[package]] name = "punktfunk-core" version = "0.45.0" -source = "git+https://git.unom.io/unom/punktfunk?rev=9a230631e9867b02fb5298a8cc6f6feb544b274f#9a230631e9867b02fb5298a8cc6f6feb544b274f" +source = "git+https://git.unom.io/unom/punktfunk?rev=eb990a68305046336025ba115c9fff2ba395238a#eb990a68305046336025ba115c9fff2ba395238a" dependencies = [ "aes-gcm", "chacha20poly1305", diff --git a/server/Cargo.toml b/server/Cargo.toml index f96bbbe..f157f30 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -31,7 +31,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } wtransport = { version = "0.7", default-features = false, features = ["aws-lc-rs"] } # Pinned to the rev packages/stream builds against: the same PinVerify and address ranking the # native clients use, so this server trusts and reaches a host exactly the way they do. -punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "9a230631e9867b02fb5298a8cc6f6feb544b274f", default-features = false, features = ["tls"] } +punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "eb990a68305046336025ba115c9fff2ba395238a", default-features = false, features = ["tls"] } [dev-dependencies] tower = { version = "0.5", features = ["util"] }