nx_sfu_select.nx
buildroot/runtime/nx_sfu_select.nx
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
imports: nx_syscalls.nx
imported by: nx_sfu_select_gate.nxnx_signaling_v2.nx
structs
| none |
consts
| 14 | const SFU_MAGIC_65536: i64 = 65536 |
| 15 | const SFU_MAGIC_16777216: i64 = 16777216 |
| 17 | const SFU_MAXC: i64 = 128 // relay conn slots (matches NX_SIG2_MAX_CONNS) |
| 18 | const SFU_PAIRS: i64 = 16384 // 128x128 |
| 20 | const SFU_REC: i64 = 4 |
| 25 | const SFU_ACT_BUCKET_US: i64 = 2000000 // bucket width: score covers the last 2..4s of speech |
| 26 | const SFU_DOM_HYST_N: i64 = 5 // hysteresis 5/4: a challenger needs 1.25x the incumbent's |
| 27 | const SFU_DOM_HYST_D: i64 = 4 // score to take over -- prevents dominant flapping |
| 30 | const SFU_ACTREC: i64 = 6 |
| 31 | const SFU_ACT_OFF: i64 = SFU_REC * SFU_PAIRS // i64 offset where activity plane starts |
| 32 | const SFU_REGION: i64 = 8 * (SFU_REC * SFU_PAIRS + SFU_ACTREC * SFU_MAXC) |
functions
| 34 | func sfu_init(mem: *i64) -> i64 |
| 45 | func sfu_act_ptr(mem: *i64, midx: i64) -> *i64 { return ((mem as i64) + 8 * (SFU_ACT_OFF + midx * SFU_ACTREC)) as *i64 } |
| 47 | func sfu_act_roll(a: *i64, now_us: i64) -> i64 |
| 53 | func sfu_audio_bytes(mem: *i64, midx: i64, nbytes: i64, now_us: i64) -> i64 |
| 61 | func sfu_act_score(mem: *i64, midx: i64, now_us: i64) -> i64 |
| 67 | func sfu_video_seen(mem: *i64, midx: i64, now_us: i64) -> i64 |
| 73 | func sfu_set_lastn(mem: *i64, midx: i64, n: i64) -> i64 |
| 83 | func sfu_dominant(mem: *i64, cand: *i64, ncand: i64, incumbent: i64, now_us: i64) -> i64 |
| 101 | func sfu_video_rank_ok(mem: *i64, s: i64, r: i64, cand: *i64, ncand: i64, now_us: i64) -> i64 |
| 127 | func sfu_want(mem: *i64, s: i64, r: i64, want: i64) -> i64 |
| 138 | func sfu_reset_conn(mem: *i64, idx: i64) -> i64 |
| 155 | func sfu_lo_wanted(mem: *i64, s: i64) -> i64 |
| 168 | func sfu_lprod_check(mem: *i64, s: i64) -> i64 |
| 176 | func sfu_lprod_last(mem: *i64, s: i64) -> i64 |
| 189 | func sfu_on_frame(mem: *i64, s: i64, r: i64, layer: i64, is_key: i64) -> i64 |
| 213 | func sfu_frame_bits(buf: *u8, n: i64, info: *i64) -> i64 |
| 225 | func sfu_rewrite_seq(buf: *u8, out_seq: i64) -> i64 |
| 234 | func sfu_parse_lsub(buf: *u8, n: i64, target_id_out: *u8) -> i64 |