code wiki / _hdl_build / nx_codec_license_gate.nx

nx_codec_license_gate.nx source

↩ module page · 123 lines · 8801 B

1// nx_codec_license_gate.nx -- grades codec patent-cleanliness from the NATIVE content-addressed seg_store 2// (no TSV, no SQL). The audit rows are AUTHORED-BY-ORGAN into a fresh /tmp native-config store each run, then 3// read back via ncfg -- so the verdict is computed from the sovereign store, not a flat file. 4// Verdict GREEN only if ZERO techniques are RISKY (clean-by-construction); otherwise RED with the worklist. This is a 5// liar-kill: it refuses to certify the media stack "clean" while any H.264/AVC-pool-derived technique remains shipped. 6// ENGINEERING due-diligence, NOT legal advice -- a real freedom-to-operate review is a separate, lawyer step. 7import "nx_syscalls.nx" 8import "nx_g_pn_lite_lib.nx" 9import "nx_g_puts_lib.nx" 10import "nx_native_config.nx" 11 12func g_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 13 14// fresh unique native store prefix per run. 15func cl_fresh_prefix(out: *u8, base: *u8) -> i64 { 16 var po: i64 = 0 17 while base[po] != (0 as u8) { out[po] = base[po]; po = po + 1 } 18 var m: i64 = sys_now_ms() 19 let ds: *u8 = sys_mmap(28) 20 var k: i64 = 0 21 if m == 0 { ds[0] = 48 as u8; k = 1 } 22 while m > 0 { ds[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 var j: i64 = 0 24 while j < k { out[po] = ds[k - 1 - j]; po = po + 1; j = j + 1 } 25 out[po] = 45 as u8; po = po + 1 26 out[po] = 0 as u8 27 return po 28} 29 30// author one audit row under the "aud" tag. 31func cl_row(w: *i64, idx: i64, technique: *u8, organ: *u8, verdict: *u8, basis: *u8, clean_path: *u8) -> i64 { 32 let keys: *i64 = sys_mmap(8 * 8) as *i64 33 let vals: *i64 = sys_mmap(8 * 8) as *i64 34 keys[0] = ("technique\x00") as i64; vals[0] = (technique as i64) 35 keys[1] = ("organ\x00") as i64; vals[1] = (organ as i64) 36 keys[2] = ("verdict\x00") as i64; vals[2] = (verdict as i64) 37 keys[3] = ("basis\x00") as i64; vals[3] = (basis as i64) 38 keys[4] = ("clean_path\x00") as i64; vals[4] = (clean_path as i64) 39 return ncfg_add_row(w, "aud\x00" as *u8, idx, keys, vals, 5) 40} 41 42// authored-by-organ codec license audit (11 techniques) into the native store -- FAITHFUL to the retired TSV. 43func cl_seed(prefix: *u8) -> i64 { 44 let w: *i64 = ncfg_begin() 45 cl_row(w, 0, "4x4_block_coding\x00" as *u8, "nx_vcodec\x00" as *u8, "CLEAN\x00" as *u8, 46 "block-based transform coding is ~1992 prior art (JPEG, MPEG-1 1993); structure unpatentable\x00" as *u8, 47 "keep\x00" as *u8) 48 cl_row(w, 1, "walsh_hadamard_transform\x00" as *u8, "nx_vtransform\x00" as *u8, "CLEAN\x00" as *u8, 49 "Walsh 1923 / Hadamard 1893 -- pure math, no patent possible\x00" as *u8, 50 "keep (already shipped, clean)\x00" as *u8) 51 cl_row(w, 2, "block_motion_compensation\x00" as *u8, "nx_vmotion\x00" as *u8, "CLEAN\x00" as *u8, 52 "block matching is MPEG-1 1993 prior art\x00" as *u8, 53 "keep\x00" as *u8) 54 cl_row(w, 3, "bilinear_subpel_motion\x00" as *u8, "nx_vsubpel\x00" as *u8, "CLEAN\x00" as *u8, 55 "bilinear interpolation is trivial/ancient math; we deliberately did NOT use H.264 6-tap filter\x00" as *u8, 56 "keep; never adopt H.264 6-tap\x00" as *u8) 57 cl_row(w, 4, "intra_pred_dc_v_h_ddr\x00" as *u8, "nx_intra_pred\x00" as *u8, "CLEAN\x00" as *u8, 58 "DC/vertical/horizontal are trivial; 45-deg diagonal is broad prior art; NOT H.264 exact 9-mode set\x00" as *u8, 59 "keep our 4 simple modes\x00" as *u8) 60 cl_row(w, 5, "range_entropy_coder\x00" as *u8, "nx_ventropy\x00" as *u8, "CLEAN\x00" as *u8, 61 "range coding (Martin 1979) + arithmetic coding base are free; IBM Q-coder patents expired\x00" as *u8, 62 "prefer range coder\x00" as *u8) 63 cl_row(w, 6, "h264_integer_dct\x00" as *u8, "nx_vtransform_dct\x00" as *u8, "REVIEW\x00" as *u8, 64 "the EXACT H.264 core transform (Cf/Ci) + Mf/Vi quant tables are the AVC standard (Via-LA pool) -- now UNSHIPPED: vc_enc_sub_at/vc_dec_sub_at reverted to the clean WHT; this module kept in-tree ONLY as a reference for the clean-DCT migration\x00" as *u8, 65 "build a royalty-free integer DCT-II (1974 DCT prior art, non-standard scale, NOT H.264/HEVC matrices) to recover the RD win cleanly; until then ship WHT (clean)\x00" as *u8) 66 cl_row(w, 7, "h264_deblock_8723\x00" as *u8, "nx_vdeblock / nx_h264_deblock\x00" as *u8, "REVIEW\x00" as *u8, 67 "literal H.264 in-loop deblock (ITU-T H.264 8.7.2.3) BUT gate-only: nx_vcodec has NO deblock call -- the inloop gate applies it AROUND the codec, it is NOT in the shipped codec path\x00" as *u8, 68 "keep out of the shipped path; if deblock is wanted, build a simple royalty-free/original loop filter, never ship the AVC one\x00" as *u8) 69 cl_row(w, 8, "cavlc_family_entropy\x00" as *u8, "nx_ventropy\x00" as *u8, "REVIEW\x00" as *u8, 70 "described as CAVLC-family (CAVLC is H.264-specific); confirm we do NOT use the exact AVC CAVLC tables/contexts\x00" as *u8, 71 "migrate fully to the range coder (clean) or a generic VLC; drop any CAVLC table parity\x00" as *u8) 72 cl_row(w, 9, "long_term_reference\x00" as *u8, "nx_vcodec\x00" as *u8, "REVIEW\x00" as *u8, 73 "referencing an older ACK'd frame is a broad concept used across codecs; LTR-as-named is H.264 but the idea predates it\x00" as *u8, 74 "likely clean; document as generic reference-management, not AVC LTR\x00" as *u8) 75 cl_row(w, 10, "h264_iframe_decode\x00" as *u8, "nx_h264_decode_frame\x00" as *u8, "TEST_ONLY\x00" as *u8, 76 "a sovereign H.264 decoder implements the AVC standard (patent-risk IF shipped); we use it ONLY in the test harness to decode the corpus, never in product\x00" as *u8, 77 "keep test-harness-only; for shipped DECODE of others content prefer royalty-free (AV1/VP9)\x00" as *u8) 78 cl_row(w, 11, "royalty_free_integer_dct2\x00" as *u8, "nx_vtransform_dct2\x00" as *u8, "CLEAN\x00" as *u8, 79 "the literal Ahmed-Natarajan-Rao 1974 DCT-II basis cos((2n+1)*k*pi/8) at scale 64 (integer matrix 32/42/17) with UNIFORM scalar quant -- NOT the H.264/AVC Cf/Ci core, NOT its Mf/Vi quant tables, NOT HEVC matrices. The DCT itself is 1974 prior art (cited: knowledge/fetched/dct_provenance.raw, sovereign-fetched)\x00" as *u8, 80 "measured +2.2dB RD vs WHT at matched bitrate (nx_vcodec_dct2_rd_gate, bit-exact); clean to ship as the codec tf=1 transform\x00" as *u8) 81 ncfg_set_count(w, "aud\x00" as *u8, 12) 82 return ncfg_commit(prefix, w) 83} 84 85func main() -> i64 { 86 g_puts("nx_codec_license gate (patent-cleanliness of the media stack, MEASURED from the NATIVE audit store)\n" as *u8) 87 88 // seed a fresh native store this run, then read it back -- sovereign, no TSV. 89 let cp: *u8 = sys_mmap(256) 90 cl_fresh_prefix(cp, "/tmp/codec-license-audit-\x00" as *u8) 91 if cl_seed(cp) != 0 { g_puts(" FAIL cannot seed native audit store\n" as *u8); g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 } 92 let h: *i64 = ncfg_open(cp) 93 if (h as i64) == 0 { g_puts(" FAIL cannot open native audit store\n" as *u8); g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1 } 94 95 let cnt: i64 = ncfg_count(h, "aud\x00" as *u8) 96 let rk: *i64 = sys_mmap(8 * 8) as *i64 97 let rv: *i64 = sys_mmap(8 * 8) as *i64 98 var nclean: i64=0; var nrisky: i64=0; var nreview: i64=0; var ntest: i64=0 99 var i: i64 = 0 100 while i < cnt { 101 let rf: i64 = ncfg_row(h, "aud\x00" as *u8, i, rk, rv, 8) 102 if rf > 0 { 103 let vb: *u8 = ncfg_field(rk, rv, rf, "verdict\x00" as *u8) 104 let tb: *u8 = ncfg_field(rk, rv, rf, "technique\x00" as *u8) 105 if (vb as i64) != 0 { 106 if g_streq(vb, "CLEAN\x00" as *u8) == 1 { nclean = nclean + 1 } 107 else { if g_streq(vb, "RISKY\x00" as *u8) == 1 { nrisky = nrisky + 1; g_puts(" RISKY -> " as *u8); if (tb as i64) != 0 { g_puts(tb) } g_puts("\n" as *u8) } 108 else { if g_streq(vb, "REVIEW\x00" as *u8) == 1 { nreview = nreview + 1; g_puts(" REVIEW -> " as *u8); if (tb as i64) != 0 { g_puts(tb) } g_puts("\n" as *u8) } 109 else { if g_streq(vb, "TEST_ONLY\x00" as *u8) == 1 { ntest = ntest + 1 } 110 else { } } } } 111 } 112 } 113 i = i + 1 114 } 115 g_puts(" [measure] techniques: CLEAN=" as *u8); g_pn(nclean); g_puts(" RISKY=" as *u8); g_pn(nrisky) 116 g_puts(" REVIEW=" as *u8); g_pn(nreview); g_puts(" TEST_ONLY=" as *u8); g_pn(ntest); g_puts("\n" as *u8) 117 if nrisky == 0 { 118 g_puts("verdict=GREEN (no patent-RISKY shipped technique; review items remain)\n" as *u8) 119 sys_exit(0); return 0 120 } 121 g_puts("verdict=RED (media stack is NOT patent-clean: RISKY H.264/AVC-pool techniques shipped -- migrate per the audit clean_path)\n" as *u8) 122 sys_exit(1); return 1 123}