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, 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"] }