code wiki / (root) / nx_sfu_select.nx

nx_sfu_select.nx

buildroot/runtime/nx_sfu_select.nx

11750 B241 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_sfu_select.nx -- SOVEREIGN SELECTIVE-FORWARDING core (the jitsi-videobridge value prop, measured our #1 SOTA hole: relay had broadcast=7/selective=0 -> every receiver got every full-rate stream -> multi- party collapse). PURE LOGIC, no sockets: the relay integrates it thinly; this organ is gate-proven alone. MODEL (layers = geometries): a sender may mark each 0x57 frame HI (flags bit1=0, today's clients) or LO (bit1=1, e.g. 160x120 simulcast). Per (sender,receiver) pair the relay forwards EXACTLY ONE layer. A layer SWITCH happens only AT A KEYFRAME of the target layer -- to a geometry-flex receiver the switch is just a legal geometry change at a key: ZERO new client decode logic. The forwarded subset gets its seq REWRITTEN (out_seq++ per forwarded frame, the JVB trick) so dedupe+P-chain rules hold. SAFE BY CONSTRUCTION: default want=HI = exactly today's behavior; want=LO with a sender that never produces LO keeps HI flowing (no starvation); unknown flag bits ignored; senders/receivers cap 64. license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_sfu_select.nx nx_sfu_select_gate.nx nx_signaling_v2.nx

imports: nx_syscalls.nx

imported by: nx_sfu_select_gate.nxnx_signaling_v2.nx

structs

none

consts

14const SFU_MAGIC_65536: i64 = 65536
15const SFU_MAGIC_16777216: i64 = 16777216
17const SFU_MAXC: i64 = 128 // relay conn slots (matches NX_SIG2_MAX_CONNS)
18const SFU_PAIRS: i64 = 16384 // 128x128
20const SFU_REC: i64 = 4
25const SFU_ACT_BUCKET_US: i64 = 2000000 // bucket width: score covers the last 2..4s of speech
26const SFU_DOM_HYST_N: i64 = 5 // hysteresis 5/4: a challenger needs 1.25x the incumbent's
27const SFU_DOM_HYST_D: i64 = 4 // score to take over -- prevents dominant flapping
30const SFU_ACTREC: i64 = 6
31const SFU_ACT_OFF: i64 = SFU_REC * SFU_PAIRS // i64 offset where activity plane starts
32const SFU_REGION: i64 = 8 * (SFU_REC * SFU_PAIRS + SFU_ACTREC * SFU_MAXC)

functions

34func sfu_init(mem: *i64) -> i64
called by 2: mainmain calls 1: sfu_act_ptr
45func sfu_act_ptr(mem: *i64, midx: i64) -> *i64 { return ((mem as i64) + 8 * (SFU_ACT_OFF + midx * SFU_ACTREC)) as *i64 }
47func sfu_act_roll(a: *i64, now_us: i64) -> i64
53func sfu_audio_bytes(mem: *i64, midx: i64, nbytes: i64, now_us: i64) -> i64
61func sfu_act_score(mem: *i64, midx: i64, now_us: i64) -> i64
67func sfu_video_seen(mem: *i64, midx: i64, now_us: i64) -> i64
called by 2: mainsig2_broadcast calls 1: sfu_act_ptr
73func sfu_set_lastn(mem: *i64, midx: i64, n: i64) -> i64
called by 2: mainsig2_handle_frame calls 1: sfu_act_ptr
83func sfu_dominant(mem: *i64, cand: *i64, ncand: i64, incumbent: i64, now_us: i64) -> i64
101func sfu_video_rank_ok(mem: *i64, s: i64, r: i64, cand: *i64, ncand: i64, now_us: i64) -> i64
127func sfu_want(mem: *i64, s: i64, r: i64, want: i64) -> i64
138func sfu_reset_conn(mem: *i64, idx: i64) -> i64
called by 2: mainsig2_memidx calls 1: sfu_act_ptr
155func sfu_lo_wanted(mem: *i64, s: i64) -> i64
called by 2: sfu_lprod_checkmain
168func sfu_lprod_check(mem: *i64, s: i64) -> i64
176func sfu_lprod_last(mem: *i64, s: i64) -> i64
called by 2: mainsig2_lprod_eval calls 1: sfu_act_ptr
189func sfu_on_frame(mem: *i64, s: i64, r: i64, layer: i64, is_key: i64) -> i64
called by 2: mainsig2_broadcast
213func sfu_frame_bits(buf: *u8, n: i64, info: *i64) -> i64
called by 2: mainsig2_broadcast
225func sfu_rewrite_seq(buf: *u8, out_seq: i64) -> i64
called by 2: mainsig2_broadcast
234func sfu_parse_lsub(buf: *u8, n: i64, target_id_out: *u8) -> i64