nx_ts_nal.nx
buildroot/runtime/nx_ts_nal.nx
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
imports: nx_syscalls.nx
imported by: nx_cam_poster.nxnx_ts_es.nxnx_ts_index.nxnx_ts_nal_gate.nx
structs
| none |
consts
| 23 | const TSN_MAGIC_1111: i64 = 1111 |
| 24 | const TSN_MAGIC_111111: i64 = 111111 |
| 25 | const TSN_MAGIC_11111: i64 = 11111 |
| 27 | const TSN_H264: i64 = 0 |
| 28 | const TSN_HEVC: i64 = 1 |
functions
| 31 | func tsn_codec_of_stream_type(st: i64) -> i64 |
| 38 | func tsn_nal_type(b0: i64, codec: i64) -> i64 |
| 47 | func tsn_nal_is_key(nt: i64, codec: i64) -> i64 |
| 58 | func tsn_nal_is_vcl(nt: i64, codec: i64) -> i64 |
| 84 | func tsn_build_hvcc(out: *u8, vps: *u8, vpslen: i64, sps: *u8, spslen: i64, pps: *u8, ppslen: i64) -> i64 |
| 124 | func tsn_hvcc_array(out: *u8, off: i64, nal_type: i64, nal: *u8, nlen: i64) -> i64 called by 1: tsn_build_hvcc |
| 138 | func tsn_sps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 33 } return 7 } |
| 139 | func tsn_pps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 34 } return 8 } |
| 140 | func tsn_vps_type(codec: i64) -> i64 { if codec == TSN_HEVC { return 32 } return 0 - 1 } |