code wiki / (root) / nx_ts_index.nx

nx_ts_index.nx

buildroot/runtime/nx_ts_index.nx

18944 B252 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tooltopic ts
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_ts_marks.nx nx_ts_nal.nx nx_ts_index.nx

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

main pe sys_write dump_idx sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close pe ↻ r32 r64 r32 ↻ pn sys_mmap ↻ sys_write ↻ sys_openat_rd ↻ sys_mmap ↻ sys_read ↻ sys_close ↻ sys_lseek ↻ sys_clock_now_us sys_now_us sys_mmap ↻ sys_clock_gettime_mono tsn_codec_of_stream_type tsn_sps_type tsn_pps_type tsn_nal_type tsn_nal_is_key tsn_nal_is_vcl ts_silence_marks tm_median sys_mmap ↻ ts_motion_marks tm_median ↻ tm_percentile sys_mmap ↻

structs

none

consts

15const K_MAGIC_262144: i64 = 262144
16const K_MAGIC_65536: i64 = 65536
17const K_MAGIC_900000: i64 = 900000
18const K_MAGIC_48000: i64 = 48000
19const K_MAGIC_44100: i64 = 44100
20const K_MAGIC_32000: i64 = 32000
21const K_MAGIC_24000: i64 = 24000
22const K_MAGIC_22050: i64 = 22050
23const K_MAGIC_16000: i64 = 16000
24const K_MAGIC_4096: i64 = 4096
26const CHUNK: i64 = 16777216
27const AUCAP: i64 = 8388608
28const MAXKF: i64 = 200000
32const SCANCAP: i64 = 16384
63const TS_PROBE_BYTES: i64 = 576 // 3 MPEG-TS packets: enough to require 0x47 sync three times running

functions

34func 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 }
called by 2: w64main
35func w64(b: *u8, o: i64, v: i64) -> i64 { o=w32(b,o,(v>>32)&0xffffffff); o=w32(b,o,v&0xffffffff); return o }
called by 1: main calls 1: w32
36func pe(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return sys_write(2,s,n) }
called by 2: dump_idxmain calls 1: sys_write
37func 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) }
called by 2: dump_idxmain calls 2: sys_mmapsys_write
38func 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) }
called by 2: r64dump_idx
39func r64(b: *u8, o: i64) -> i64 { return (r32(b,o)<<32)|(r32(b,o+4)&0xffffffff) }
called by 1: dump_idx calls 1: r32
41func dump_idx(p: *u8) -> i64
64func main(argc: i64, argv: *i64) -> i64