code wiki / (root) / nx_uxf_remux.nx

nx_uxf_remux.nx

buildroot/runtime/nx_uxf_remux.nx

7180 B136 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind librarytopic uxf
docsdependenciesstructsconstsfunctions

about

nx_uxf_remux.nx -- FM4: the frame-level LOSSLESS REWRAP, extracted from nx_uxf_remux_test so that it has a CALLABLE ENTRY POINT (2026-09-06). WHY THIS EXISTS. The remux data-flow was proven byte-identical in June 2026 and the proof lived INSIDE a test with no function anything could call, so the capability was real and uncomposable at the same time. The formats board ranked that #1 for exactly that reason. This is the extraction; nx_uxf_remux_gate drives it and asserts the same five properties the original test asserted. WHAT IT DOES. Parses one EBML element carrying a frame (the MKV input side) and REWRAPS those exact bytes into a minimal MP4 of ftyp + mdat + stsz (the MP4 output side). The frame is COPIED, never re-encoded -- that is the whole point, and it is what makes the endpoint-negotiation REMUX plan honest. HONEST SCOPE, UNCHANGED FROM THE ORIGINAL: one frame, flat structure. A spec-complete PLAYABLE MKV to MP4 needs a real SimpleBlock header decode, multi-frame and multi-track sample tables stts stsc stco, codec private data in stsd, timestamps and proper moov nesting. That is FM5 and it is not claimed here. Defensive at the boundary (Rule 12): a malformed vint, a frame running past the input, or an output that would not fit are each REFUSED BY NAME rather than truncated. PROVENANCE 2026-09-06: extracted from nx_uxf_remux_test to close formats rung FM4, which ranked first on that board precisely because a capability with no callable entry point cannot be composed. This comment is also the probe for a build-cache question: a comment-only edit compiles byte-identical, so if the cache key of a DEPENDENT gate changes when this file changes, the key covers the import closure. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_uxf_remux.nx nx_uxf_ebml_gate.nx nx_uxf_mp4box_gate.nx nx_uxf_remux_gate.nx

imports: nx_syscalls.nx

imported by: nx_uxf_ebml_gate.nxnx_uxf_mp4box_gate.nxnx_uxf_remux_gate.nx

structs

none

consts

25const UXR_OK: i64 = 0
26const UXR_ERR_VINT: i64 = 0-1 // leading byte is not a legal EBML vint
27const UXR_ERR_OVERRUN: i64 = 0-2 // the declared frame runs past the input buffer
28const UXR_ERR_CAPACITY: i64 = 0-3 // the rewrapped MP4 would not fit in outcap
30const UXR_META_ID: i64 = 0
31const UXR_META_FRAMESIZE: i64 = 1
32const UXR_META_MDAT_OFF: i64 = 2
33const UXR_META_STSZ_OFF: i64 = 3
34const UXR_META_SLOTS: i64 = 4
37const UXR_FIXED_OVERHEAD: i64 = 52
38const UXR_STSZ_SAMPLESIZE_OFF: i64 = 12 // from the stsz box start: 8 header + 4 version-and-flags

functions

41func uxr_vint_len(b: i64) -> i64
52func uxr_read_id(buf: *u8, pos: *i64) -> i64
62func uxr_read_size(buf: *u8, pos: *i64) -> i64
74func uxr_w32(out: *u8, off: i64, v: i64) -> i64 { out[off] = ((v >> 24) & 0xff) as u8; out[off + 1] = ((v >> 16) & 0xff) as u8; out[off + 2] = ((v >> 8) & 0xff) as u8; out[off + 3] = (v & 0xff) as u8; return off + 4 }
75func uxr_r32(buf: *u8, off: i64) -> i64 { return ((buf[off] as i64) * 16777216) + ((buf[off + 1] as i64) * 65536) + ((buf[off + 2] as i64) * 256) + (buf[off + 3] as i64) }
76func uxr_4cc(out: *u8, off: i64, a: i64, b: i64, c: i64, d: i64) -> i64 { out[off] = a as u8; out[off + 1] = b as u8; out[off + 2] = c as u8; out[off + 3] = d as u8; return off + 4 }
77func uxr_box_begin(out: *u8, off: i64, a: i64, b: i64, c: i64, d: i64) -> i64 { uxr_w32(out, off, 0); uxr_4cc(out, off + 4, a, b, c, d); return off + 8 }
called by 2: mainuxf_remux_frame calls 2: uxr_w32uxr_4cc
78func uxr_box_end(out: *u8, start: i64, cur: i64) -> i64 { uxr_w32(out, start, cur - start); return cur }
called by 2: mainuxf_remux_frame calls 1: uxr_w32
79func uxr_copy(out: *u8, off: i64, src: *u8, srcoff: i64, n: i64) -> i64 { var i: i64 = 0; while i < n { out[off + i] = src[srcoff + i]; i = i + 1 } return off + n }
called by 1: uxf_remux_frame
82func uxr_walk_ok(buf: *u8, n: i64) -> i64 { var off: i64 = 0; while (off + 8) <= n { let sz: i64 = uxr_r32(buf, off); if sz < 8 { return 0 } off = off + sz } if off == n { return 1 } return 0 }
called by 1: main calls 1: uxr_r32
83func uxr_bytes_eq(a: *u8, aoff: i64, b: *u8, boff: i64, n: i64) -> i64 { var i: i64 = 0; while i < n { if a[aoff + i] != b[boff + i] { return 0 } i = i + 1 } return 1 }
called by 2: mainmain
88func uxf_remux_frame(inb: *u8, inlen: i64, out: *u8, outcap: i64, meta: *i64) -> i64
128func uxf_remux_src_off(inb: *u8) -> i64