code wiki / (root) / nx_h264_cabac_residual.nx

nx_h264_cabac_residual.nx

buildroot/runtime/nx_h264_cabac_residual.nx

4974 B118 linesdepth 3pulls 4 transitivereach 1 importersview sourcekind librarytopic h264
docsdependenciesstructsconstsfunctions

about

nx_h264_cabac_residual.nx -- H.264 CABAC residual block decoding (clause 9.3.2.3 / 9.3.3.1.3). STEP 2, built on the STEP-1 arithmetic engine in nx_h264_cabac.nx which is KAT-verified against clause 9.3.1 (gate ALL-PASS). Decodes ONE residual block: the significance map, then the levels in reverse scan order, then signs. WHY THIS EXISTS: ~50% of the recording corpus is CABAC-coded and the poster/dead-air paths refuse it outright (rc=10), which is the single largest measured blocker on gallery posters (117 of 236 files needing work, 2026-07-31). The arithmetic engine already existed and was never built on. SCOPE + HONESTY: binarization and context routing follow the spec, and the teeth below check the structure that can be checked without a reference decoder. END-TO-END CORRECTNESS IS NOT PROVEN HERE -- that requires decoding a real CABAC stream and looking at the image. Do not claim CABAC posters work until that runs. license_tier: ORIGINAL

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_h264_cabac.nx nx_h264_cabac_ctxinc.nx nx_h264_cabac_residual.nx nx_h264_cabac_residual_gate.nx

imports: nx_syscalls.nxnx_h264_cabac.nxnx_h264_cabac_ctxinc.nx

imported by: nx_h264_cabac_residual_gate.nx

structs

none

consts

19const CBR_MAXCOEFF: i64 = 64 // largest block we handle (8x8 luma); 4x4 uses 16
20const CBR_UNARY_MAX: i64 = 13 // coeff_abs_level_minus1 prefix cap before the EG0 suffix
21const CBR_EG0_MAXK: i64 = 32
22const CBR_MAX_LEVEL: i64 = 32768 // a coefficient level beyond this cannot occur in 8-bit H.264; past it the stream is corrupt and we REFUSE rather than emit a value that overflows the coefficient arrays // bound on the Exp-Golomb suffix so a corrupt stream cannot spin

functions

25func cbr_eg0_bypass(cab: *i64) -> i64
called by 2: cbr_levelsmain calls 1: cab_bypass
48func cbr_sigmap(cab: *i64, ctx: *i64, rlps: *i64, tlps: *i64, tmps: *i64,
called by 1: main calls 2: cab_decisioncci_sig4x4
79func cbr_levels(cab: *i64, ctx: *i64, rlps: *i64, tlps: *i64, tmps: *i64,