code wiki / (root) / nx_adaptive_bitrate.nx

nx_adaptive_bitrate.nx

buildroot/runtime/nx_adaptive_bitrate.nx

10910 B249 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_adaptive_bitrate.nx -- pick a quality tier from observed link state. Composes with nx_bandwidth_meter to turn raw bytes/sec + RTT + loss observations into a sealed-enum verdict the game engine can act on: NX_AB_TIER_DIALUP -- 56 kbps dial-up, satellite, deep rural mobile NX_AB_TIER_3G -- mobile 3G / poor 4G / shared cafe wifi NX_AB_TIER_BROADBAND -- home cable / good 4G / urban fibre NX_AB_TIER_FIBRE -- gigabit / data centre Plus a concrete recommended-settings struct (audio bitrate, video bitrate, game tickrate, AOI radius) so downstream code can act without re-deriving from raw metrics. Hysteresis: once at a given tier, the meter must observe a decisive improvement (one full band above) before stepping up; one full band below before stepping down. This avoids tier-flapping at boundary conditions where a single sample crosses a threshold. Source references (open): - Opus codec recommended bitrates (Xiph wiki / RFC 6716) - Source/CS:GO rate settings progression (developer.valvesoftware.com) - WebRTC simulcast ladder choices (W3C webrtc-pc, MDN simulcast docs) genealogy_id: opus_voip_tiers + source_rate_settings + simulcast_ladder lineage_id: poor_internet_quality_step_router

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_bandwidth_meter.nx nx_adaptive_bitrate.nx

imports: nx_syscalls.nxnx_tier.nxnx_bandwidth_meter.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_bandwidth_meter_new sys_mmap nx_adaptive_bitrate_classi nx_bandwidth_meter_bytes_p nx_bandwidth_meter_rtt_ms nx_bandwidth_meter_loss_ra _ab_tier_from_bps _ab_tier_from_rtt _ab_tier_from_loss _ab_min_tier nx_bandwidth_meter_observe _bm_ewma nx_bandwidth_meter_observe _bm_ewma ↻ nx_bandwidth_meter_observe _bm_ewma ↻ sys_mmap ↻ nx_adaptive_bitrate_recomm nx_adaptive_bitrate_classi ↻

structs

none

consts

31const NX_MAGIC_6000: i64 = 6000
32const NX_MAGIC_12000: i64 = 12000
33const NX_MAGIC_150000: i64 = 150000
34const NX_MAGIC_24000: i64 = 24000
35const NX_MAGIC_400000: i64 = 400000
36const NX_MAGIC_32000: i64 = 32000
37const NX_MAGIC_800000: i64 = 800000
38const NX_MAGIC_30000: i64 = 30000
39const NX_MAGIC_2000000: i64 = 2000000
42const NX_AB_TIER_DIALUP: nx_int = 0
43const NX_AB_TIER_3G: nx_int = 1
44const NX_AB_TIER_BROADBAND: nx_int = 2
45const NX_AB_TIER_FIBRE: nx_int = 3
48const NX_AB_BPS_DIALUP_MAX: i64 = 7000 // 56 kbps
49const NX_AB_BPS_3G_MAX: i64 = 50000 // ~400 kbps
50const NX_AB_BPS_BROADBAND_MAX: i64 = 625000 // 5 Mbps
54const NX_AB_RTT_FIBRE_MAX: i64 = 50
55const NX_AB_RTT_BROADBAND_MAX: i64 = 150
56const NX_AB_RTT_3G_MAX: i64 = 500
60const NX_AB_LOSS_CLEAN_MAX_Q14: i64 = 164 // ~1.0%
61const NX_AB_LOSS_LOSSY_MAX_Q14: i64 = 819 // ~5.0%
68const NX_AB_REC_TIER: nx_int = 0
69const NX_AB_REC_VOICE_BPS: nx_int = 1 // Opus encode bitrate
70const NX_AB_REC_VIDEO_BPS: nx_int = 2 // VP9 encode bitrate (0 = off)
71const NX_AB_REC_TICKRATE_HZ: nx_int = 3 // sim tick rate to broadcast
72const NX_AB_REC_AOI_RADIUS_M: nx_int = 4 // metres (not Q14) for streaming
73const NX_AB_REC_SIZE: nx_int = 5

functions

77func _ab_tier_from_bps(bps: i64) -> nx_int {
84func _ab_tier_from_rtt(rtt_ms: i64) -> nx_int {
91func _ab_tier_from_loss(loss_q14: i64) -> nx_int {
98func _ab_min_tier(a: nx_int, b: nx_int, c: nx_int) -> nx_int {
109func nx_adaptive_bitrate_classify(meter: *i64) -> nx_int {
129func nx_adaptive_bitrate_recommend(meter: *i64, out: *i64) -> nx_int {
called by 1: main calls 1: nx_adaptive_bitrate_classify
164func main() -> i64 {