code wiki / _hdl_build / nx_audio_serve.nx

nx_audio_serve.nx

buildroot/runtime/_hdl_build/nx_audio_serve.nx

13730 B186 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind servicetopic audio
docsdependenciesstructsconstsfunctions

about

nx_audio_serve.nx -- the SOVEREIGN audiobook player BRAIN (SC34/35/37), server-side Nishi code (operator: the player capabilities ARE nishi-code APIs, not browser JS). Binds 127.0.0.1 only. The browser is a dumb native <audio> client; THIS daemon does the work: GET /audio/<slug> -> the zero-JS player.html (rendered by nx_audio_render) GET /audio/<slug>/track -> serve the audio bytes; honors `Range: bytes=X-Y` (206) so <audio> seeks/streams GET /audio/<slug>/track?sleep=N -> SLEEP TIMER: caps the served stream to N*BYTES_PER_MIN -> playback ends (SC34) POST /audio/<slug>/bookmark (pos=BYTE) -> stores the position server-side -> 303 (SC35 + SC37 cross-device) GET /audio/<slug>/resume -> returns the stored position {"pos":N} (the client seeks there) (SC37) Reuses the proven nx_vizsla_serve HTTP pattern (handle-mode gate hook + gallery_serve socket idiom). The position store is a per-slug file (reader/<slug>/audio_pos.txt). license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_audio_serve.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_write as_slen as_match as_slen ↻ sys_mmap as_readall sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close handle sys_mmap ↻ parse_route as_match ↻ as_cat as_valid_slug as_match ↻ as_slen ↻ bodyfield as_slen ↻ posfile as_cat ↻ sys_openat_wr sys_write ↻ sys_close ↻ as_readall ↻ as_catn sys_mmap ↻ parse_range as_match ↻ serve_track sys_mmap ↻ as_cat ↻ as_readall ↻ as_catn ↻ sys_socket sys_setsockopt sys_bind

structs

none

consts

12const BYTES_MAGIC_65536: i64 = 65536
13const BYTES_MAGIC_1024: i64 = 1024
14const BYTES_MAGIC_33554432: i64 = 33554432
15const BYTES_MAGIC_18099: i64 = 18099
19const BYTES_PER_MIN: i64 = 100

functions

21func as_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
22func as_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){d[o+i]=s[i];i=i+1} return o+i }
23func as_catn(d: *u8, o0: i64, v: i64) -> i64 { var o: i64=o0; var m: i64=v; if m<0{d[o]=45 as u8;o=o+1;m=0-m}; let t: *u8=sys_mmap(28); 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}; var i: i64=0; while i<k{d[o+i]=t[k-1-i];i=i+1} return o+k }
called by 2: serve_trackhandle calls 1: sys_mmap
24func as_match(req: *u8, rn: i64, pat: *u8) -> i64 { let pl: i64=as_slen(pat); if pl>rn{return 0} var j: i64=0; while j<pl{ if req[j]!=pat[j]{return 0} j=j+1 } return 1 }
25func as_valid_slug(s: *u8) -> i64
called by 1: handle
31func as_readall(path: *u8, szp: *i64) -> *u8
39func parse_range(req: *u8, rn: i64, sp: *i64, ep: *i64) -> i64
called by 1: handle calls 1: as_match
61func bodyfield(req: *u8, rn: i64, key: *u8, out: *u8) -> i64
called by 1: handle calls 1: as_slen
71func parse_route(req: *u8, rn: i64, slug: *u8, action: *u8, sleepp: *i64) -> i64
called by 1: handle calls 1: as_match
90func posfile(slug: *u8, out: *u8) -> i64 { var o: i64=as_cat(out,0,"knowledge/staging/media/reader/" as *u8); o=as_cat(out,o,slug); o=as_cat(out,o,"/audio_pos.txt" as *u8); out[o]=0 as u8; return o }
called by 1: handle calls 1: as_cat
93func serve_track(slug: *u8, has_range: i64, rs: i64, re0: i64, sleep_min: i64, rbuf: *u8) -> i64
119func handle(req: *u8, rn: i64, rbuf: *u8) -> i64
159func main(argc: i64, argv: *i64) -> i64