nx_ts_index.nx
buildroot/runtime/nx_ts_index.nx
about
nx_ts_index.nx -- SOVEREIGN media index ("NXVI", our own format) for an MPEG-TS recording.
Scans the .ts ONCE and records: exact duration (sum of per-AU PTS deltas, discontinuity-robust),
audio params, SPS/PPS, and a KEYFRAME TABLE (time_ms -> byte_offset of the IDR access unit) so the
daemon can seek EXACTLY and instantly without re-scanning. MP4 is emitted only at the browser
last-mile; this index is pure-Nishi. Output is a binary index file. Usage: nx_ts_index <in.ts> <out.idx>
Format (all big-endian): "NXVI"(4) ver(4)=2 dur_ms(8) arate(4) achan(4) vidpid(4) audpid(4)
spslen(4) sps[] ppslen(4) pps[] nkf(8) then nkf * { time_ms(8) byte_off(8) }.
v2 adds vidpid/audpid so the muxer can demux a media segment starting EXACTLY at a keyframe AU's
first packet without waiting for a PAT/PMT (deterministic exact seek). kf time_ms is 0-based (the
clamped totdur timeline), matching dur_ms. license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_ts_marks.nxnx_ts_nal.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 15 | const K_MAGIC_262144: i64 = 262144 |
| 16 | const K_MAGIC_65536: i64 = 65536 |
| 17 | const K_MAGIC_900000: i64 = 900000 |
| 18 | const K_MAGIC_48000: i64 = 48000 |
| 19 | const K_MAGIC_44100: i64 = 44100 |
| 20 | const K_MAGIC_32000: i64 = 32000 |
| 21 | const K_MAGIC_24000: i64 = 24000 |
| 22 | const K_MAGIC_22050: i64 = 22050 |
| 23 | const K_MAGIC_16000: i64 = 16000 |
| 24 | const K_MAGIC_4096: i64 = 4096 |
| 26 | const CHUNK: i64 = 16777216 |
| 27 | const AUCAP: i64 = 8388608 |
| 28 | const MAXKF: i64 = 200000 |
| 32 | const SCANCAP: i64 = 16384 |
| 63 | const TS_PROBE_BYTES: i64 = 576 // 3 MPEG-TS packets: enough to require 0x47 sync three times running |
functions
| 34 | func w32(b: *u8, o: i64, v: i64) -> i64 { b[o]=((v>>24)&0xff) as u8; b[o+1]=((v>>16)&0xff) as u8; b[o+2]=((v>>8)&0xff) as u8; b[o+3]=(v&0xff) as u8; return o+4 } |
| 35 | func w64(b: *u8, o: i64, v: i64) -> i64 { o=w32(b,o,(v>>32)&0xffffffff); o=w32(b,o,v&0xffffffff); return o } |
| 36 | func pe(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return sys_write(2,s,n) } |
| 37 | func pn(v: i64) -> i64 { var m: i64=v; if m<0{m=0-m} let b: *u8=sys_mmap(32); var i: i64=32; if m==0{i=i-1;b[i]=(48 as u8)} while m>0{let q: i64=m/10; i=i-1; b[i]=((48+(m-q*10)) as u8); m=q} return sys_write(2,((b as i64)+i) as *u8,32-i) } |
| 38 | func r32(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<24)|((b[o+1] as i64)<<16)|((b[o+2] as i64)<<8)|(b[o+3] as i64) } |
| 39 | func r64(b: *u8, o: i64) -> i64 { return (r32(b,o)<<32)|(r32(b,o+4)&0xffffffff) } |
| 41 | func dump_idx(p: *u8) -> i64 |
| 64 | func main(argc: i64, argv: *i64) -> i64 |