code wiki / (root) / nx_hls_get.nx

nx_hls_get.nx

buildroot/runtime/nx_hls_get.nx

16053 B240 linesdepth 22pulls 136 transitivereach 0 importersview sourcekind tooltopic hls
docsdependenciesstructsconstsfunctions

about

nx_hls_get.nx -- X-DLP rung 2: the HLS DOWNLOAD ORCHESTRATOR. Turns an .m3u8 URL into ONE stitched .ts file the gallery can ingest + the operator can watch. Composes the gated rung 0 (nx_hls_parse) + rung 1 (nx_hls_resolve) + the UA/Referer/Cookie-aware fetch (nx_video_get's nx_video_fetch): fetch playlist -> if MASTER pick the highest-bandwidth variant -> fetch its media playlist -> resolve EVERY segment URI to absolute -> fetch each in order -> CONCAT into outpath. FORK-PER-SEGMENT: each segment is fetched in a child that exits, so the TLS stack's per-fetch mmap leak dies with the child (no OOM over hundreds of segments) -- same isolation idiom as the connect researcher. CLEAR + AES-128 (#EXT-X-KEY, rung 3 via nx_aes_cbc) HLS handled here; daemon wiring = rung 4; fMP4/#EXT-X-MAP (init segment) = a later rung (MPEG-TS .ts concatenates cleanly, fMP4 does not). argv[1]=m3u8 url argv[2]=outpath(.ts) argv[3]=referer argv[4]=cookie. license_tier: ORIGINAL module: nishi-core.media.hls_get

dependencies 8 imports · 0 importers

nx_hls_resolve.nx nx_video_get.nx nx_x509_trust_store.nx nx_pem_loader.nx nx_aes.nx nx_aes_cbc.nx nx_syscalls.nx nx_paced_fetch.nx nx_hls_get.nx

imports: nx_hls_resolve.nxnx_video_get.nxnx_x509_trust_store.nxnx_pem_loader.nxnx_aes.nxnx_aes_cbc.nxnx_syscalls.nxnx_paced_fetch.nx

imported by: nobody (leaf or entry point)

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

main hg_w sys_write sys_exit nx_pem_trust_load_file sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close nx_pem_trust_load nx_str_len _pem_find nx_str_len ↻ sys_mmap ↻ b64_decode b64_grab b64_dec_char sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real sys_mmap ↻ hg_fetch

structs

none

consts

20const HG_MAGIC_8192: i64 = 8192
21const HG_MAGIC_4096: i64 = 4096
22const HG_HTTP_OK: i64 = 200 // what the pacer is fed when the forked fetch succeeded (the child cannot hand back the real status)
142const HG_MAXENT: i64 = 20000 // max segments / variants
143const HG_PLCAP: i64 = 4194304 // 4 MiB playlist buffer
144const HG_SEGCAP: i64 = 33554432 // 32 MiB per-segment buffer (HLS .ts segments are typically a few MiB)

functions

24func hg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
25func hg_wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
26func hg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: hg_find_aftermain
29func hg_readfile(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
36func hg_append(fd: i64, buf: *u8, n: i64) -> i64 { var o: i64 = 0; while o < n { let w: i64 = sys_write(fd, (buf as i64 + o) as *u8, n - o); if w <= 0 { return 0 - 1 } o = o + w } return 0 }
called by 1: main calls 1: sys_write
44func hg_fetch(url: *u8, referer: *u8, cookie: *u8, partpath: *u8, store: *TrustStore, now: i64) -> i64
62func hg_find_after(buf: *u8, n: i64, lit: *u8) -> i64
called by 2: hg_parse_keyhg_media_seq calls 1: hg_slen
68func hg_hexv(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-97+10 } } if c>=65 { if c<=70 { return c-65+10 } } return 0 - 1 }
called by 1: hg_parse_key
72func hg_parse_key(pl: *u8, pllen: i64, keyuri: *u8, uricap: i64, ivout: *u8, has_iv: *i64) -> i64
called by 1: main calls 2: hg_find_afterhg_hexv
96func hg_media_seq(pl: *u8, pllen: i64) -> i64
called by 1: main calls 1: hg_find_after
104func hg_seq_iv(seq: i64, iv: *u8) -> i64
called by 1: main
112func hg_mp4_path(ts: *u8, out: *u8) -> i64
120func hg_remux(tspath: *u8, mp4path: *u8) -> i64
146func main(argc: i64, argv: *i64) -> i64