Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/ui/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
23 changes: 10 additions & 13 deletions apps/web/src/ui/hud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionStats["quality"], { variant: BadgeVariant; text: string }> = {
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<Screen, { kind: "streaming" }>; actions: Actions }): JSX.Element {
const [idle, setIdle] = useState(false);
Expand All @@ -56,7 +53,7 @@ export function Hud({ screen, actions }: { screen: Extract<Screen, { kind: "stre
for (const type of types) window.removeEventListener(type, wake);
};
}, []);
const q = quality(stats);
const q = QUALITY[stats.quality];
const notice = screen.notice ?? stats.launchNotice ?? stats.accessNotice;
const line = [
stats.width ? `${stats.width}×${stats.height}` : "",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface SessionStats {
accessUnits: number;
decoded: number;
dropped: number;
/** The connection dot: the wire's loss, repairs and round trip. */
quality: "starting" | "good" | "fair" | "poor";
/** Average milliseconds uploading a frame to the video plane. */
uploadMs: number;
backend: "webgpu" | "webgl2" | null;
Expand Down
8 changes: 4 additions & 4 deletions packages/stream/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/stream/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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.
# Already in the tree via `pake`.
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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/stream/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ link=(
-C link-arg=-sSTACK_SIZE=4MB
# Every `_pf_*` the page calls, the ring's included: `src/carrier/feed.ts` writes datagrams
# into it.
-C link-arg=-sEXPORTED_FUNCTIONS=_main,_pf_start,_pf_frame,_pf_key,_pf_console_text,_pf_console_pointer,_pf_console_pad,_pf_console_phase,_pf_console_state,_pf_console_leave_out,_pf_console_push,_pf_console_art,_pf_rx_base,_pf_rx_stride,_pf_rx_claim,_pf_rx_commit,_pf_rx_dropped,_pf_net_blast,_pf_net_drain,_pf_wt_close,_pf_wt_ctl_open,_pf_ctl_recv,_pf_uni_recv,_pf_session_hello,_pf_session_codecs,_pf_session_pump,_pf_session_phase,_pf_session_frames,_pf_device_init,_pf_device_set,_pf_device_sign,_pf_device_fingerprint_hex,_pf_cred_phase,_pf_cred_sign_ptr,_pf_cred_sign_len,_pf_cred_signed,_pf_pair_begin,_pf_input,_pf_gamepad,_pf_gamepad_arrival,_pf_gamepad_remove,_pf_audio_frames,_pf_audio_lost,_pf_session_audio_channels,_pf_session_audio,_pf_session_audio_layout,_pf_mic_send,_pf_session_access_seq,_pf_session_access_grants,_pf_session_access_secs,_pf_session_reset,_pf_session_reconfigure,_pf_hud_decoded,_pf_hud_presented,_pf_gate_decoded,_pf_gate_no_output,_pf_request_keyframe,_pf_hud_drain,_pf_hud_text,_pf_hud_text_ptr,_pf_session_host_caps,_pf_cursor_render,_pf_cursor_serial,_pf_cursor_flags,_malloc,_free
-C link-arg=-sEXPORTED_FUNCTIONS=_main,_pf_start,_pf_frame,_pf_key,_pf_console_text,_pf_console_pointer,_pf_console_pad,_pf_console_phase,_pf_console_state,_pf_console_leave_out,_pf_console_push,_pf_console_art,_pf_rx_base,_pf_rx_stride,_pf_rx_claim,_pf_rx_commit,_pf_rx_dropped,_pf_net_blast,_pf_net_drain,_pf_wt_close,_pf_wt_ctl_open,_pf_ctl_recv,_pf_uni_recv,_pf_session_hello,_pf_session_codecs,_pf_session_pump,_pf_session_phase,_pf_session_frames,_pf_device_init,_pf_device_set,_pf_device_sign,_pf_device_fingerprint_hex,_pf_cred_phase,_pf_cred_sign_ptr,_pf_cred_sign_len,_pf_cred_signed,_pf_pair_begin,_pf_input,_pf_gamepad,_pf_gamepad_arrival,_pf_gamepad_remove,_pf_audio_frames,_pf_audio_lost,_pf_session_audio_channels,_pf_session_audio,_pf_session_audio_layout,_pf_mic_send,_pf_session_access_seq,_pf_session_access_grants,_pf_session_access_secs,_pf_session_reset,_pf_session_reconfigure,_pf_hud_decoded,_pf_hud_presented,_pf_gate_decoded,_pf_gate_no_output,_pf_request_keyframe,_pf_hud_drain,_pf_hud_quality,_pf_hud_text,_pf_hud_text_ptr,_pf_session_host_caps,_pf_cursor_render,_pf_cursor_serial,_pf_cursor_flags,_malloc,_free
# `stringToNewUTF8` is how the page hands a string across; `HEAPU8` is emscripten's view of
# wasm memory, which `src/carrier/feed.ts` writes datagrams into.
-C link-arg=-sEXPORTED_RUNTIME_METHODS=stringToNewUTF8,HEAPU8
Expand Down
12 changes: 12 additions & 0 deletions packages/stream/rust/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct Client {
/// The last closed window, and its lines as last asked for.
snap: Option<StatsSnapshot>,
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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 (`<role>\t<text>\n` each) for `tier` (`StatsVerbosity`
/// index) and vocabulary. Returns the byte length; [`pf_hud_text_ptr`] points at the bytes until
/// the next call.
Expand Down
2 changes: 2 additions & 0 deletions packages/stream/src/emscripten.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<role>\t<text>\n` per line. */
Expand Down
19 changes: 19 additions & 0 deletions packages/stream/src/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
9 changes: 9 additions & 0 deletions packages/stream/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 = {
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
Loading