code wiki / (root) / nx_ts_nal.nx

nx_ts_nal.nx

buildroot/runtime/nx_ts_nal.nx

7188 B140 linesdepth 2pulls 2 transitivereach 5 importersview sourcekind librarytopic ts
docsdependenciesstructsconstsfunctions

about

nx_ts_nal.nx -- codec-aware NAL classification for MPEG-TS elementary streams. WHY A LIB AND NOT INLINE (2026-07-31): this logic lived inside nx_ts_index's single scan loop, where it could not be tested without a real multi-megabyte recording. The HEVC hole below was therefore invisible to every gate. Pulling the classification out makes the DECISION testable independently of the I/O that feeds it -- the bug was never in the scanning, it was in the arithmetic. THE HOLE THIS CLOSES: nx_ts_index accepted only stream_type 0x1b (H.264), so an HEVC recording never got a video PID -- no keyframe index AND no NXMK dead-air/motion markers, permanently, for every H.265 asset in the corpus. THE TWO CODECS ARE NOT A TUNING DIFFERENCE, THEY ARE DIFFERENT GEOMETRY: H.264 1-byte NAL header, type = b & 0x1f keyframe = IDR, the single value 5 HEVC 2-byte NAL header, type = (b >> 1) & 0x3f keyframe = IRAP, the RANGE 16..23 ★★★ Reading HEVC through the H.264 mask does not fail loudly -- it takes the wrong bits and yields a plausible small integer, so random frames get marked as keyframes. A seek index that is WRONG is worse than one that is ABSENT, because absent is visibly ready:0 while wrong looks like it works and seeks to garbage. license_tier: ORIGINAL

dependencies 1 imports · 4 importers

nx_syscalls.nx nx_ts_nal.nx nx_cam_poster.nx nx_ts_es.nx nx_ts_index.nx nx_ts_nal_gate.nx

imports: nx_syscalls.nx

imported by: nx_cam_poster.nxnx_ts_es.nxnx_ts_index.nxnx_ts_nal_gate.nx

structs

none

consts

23const TSN_MAGIC_1111: i64 = 1111
24const TSN_MAGIC_111111: i64 = 111111
25const TSN_MAGIC_11111: i64 = 11111
27const TSN_H264: i64 = 0
28const TSN_HEVC: i64 = 1

functions

31func tsn_codec_of_stream_type(st: i64) -> i64
38func tsn_nal_type(b0: i64, codec: i64) -> i64
called by 2: mainmain
47func tsn_nal_is_key(nt: i64, codec: i64) -> i64
called by 2: mainmain
58func tsn_nal_is_vcl(nt: i64, codec: i64) -> i64
called by 2: mainmain
84func tsn_build_hvcc(out: *u8, vps: *u8, vpslen: i64, sps: *u8, spslen: i64, pps: *u8, ppslen: i64) -> i64
called by 1: main calls 1: tsn_hvcc_array
124func tsn_hvcc_array(out: *u8, off: i64, nal_type: i64, nal: *u8, nlen: i64) -> i64
called by 1: tsn_build_hvcc
138func tsn_sps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 33 } return 7 }
called by 2: mainmain
139func tsn_pps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 34 } return 8 }
called by 2: mainmain
140func tsn_vps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 32 } return 0 - 1 }