code wiki / (root) / nx_h264_mb_gate.nx

nx_h264_mb_gate.nx source

↩ module page · 88 lines · 3624 B

1// nx_h264_mb_gate.nx -- REFEREE for the I-slice macroblock type layer (rung 4d). 2// classify: 0->I_NxN, 1->I_16x16, 25->I_PCM. 3// i16x16 derive (Table 7-11, hand-computed): 4// mb_type 1 -> pred0 cbpC0 cbpL0 5// mb_type 5 -> pred0 cbpC1 cbpL0 6// mb_type 12 -> pred3 cbpC2 cbpL0 7// mb_type 13 -> pred0 cbpC0 cbpL15 8// mb_type 24 -> pred3 cbpC2 cbpL15 9// parse: ue buffer for mb_type=13 ("0001110") read back = 13. 10// Every value PRINTED. stdout + knowledge/status/h264_mb_gate.log. Exit 0/1. 11// Sovereign: nx_syscalls + nx_h264_bits + nx_h264_mb. license_tier: ORIGINAL 12import "nx_syscalls.nx" 13import "nx_h264_bits.nx" 14import "nx_h264_mb.nx" 15 16func gp(logfd: i64, s: *u8) -> i64 { 17 var n: i64 = 0 18 while s[n] != (0 as u8) { n = n + 1 } 19 sys_write(1, s, n) 20 if logfd > 0 { sys_write(logfd, s, n) } 21 return 0 22} 23func gn(logfd: i64, v: i64) -> i64 { 24 let bb: *u8 = sys_mmap(28) 25 var m: i64 = v 26 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 27 let t: *u8 = sys_mmap(28) 28 var k: i64 = 0 29 if m == 0 { t[0] = 48 as u8; k = 1 } 30 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 31 var i: i64 = 0 32 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 33 sys_write(1, bb, k) 34 if logfd > 0 { sys_write(logfd, bb, k) } 35 return 0 36} 37func chk(logfd: i64, mb: i64, out: *i64, ep: i64, ec: i64, el: i64) -> i64 { 38 nx_h264_i16x16_derive(mb, out) 39 gp(logfd, " mb_type=\x00" as *u8); gn(logfd, mb); gp(logfd, " -> pred=\x00" as *u8); gn(logfd, out[0]); gp(logfd, " cbpC=\x00" as *u8); gn(logfd, out[1]); gp(logfd, " cbpL=\x00" as *u8); gn(logfd, out[2]) 40 var good: i64 = 1 41 if out[0] != ep { good = 0 } 42 if out[1] != ec { good = 0 } 43 if out[2] != el { good = 0 } 44 if good == 1 { gp(logfd, " OK\n\x00" as *u8) } 45 if good == 0 { gp(logfd, " BAD\n\x00" as *u8) } 46 return good 47} 48 49func main() -> i64 { 50 let logfd: i64 = sys_openat_append("knowledge/status/h264_mb_gate.log\x00" as *u8, 0x1a4) 51 gp(logfd, "H264-MB-GATE (rung 4d I-slice mb_type)\n\x00" as *u8) 52 var ok: i64 = 1 53 let out: *i64 = sys_mmap(32) as *i64 54 55 let c0: i64 = nx_h264_mb_type_class(0) 56 let c1: i64 = nx_h264_mb_type_class(1) 57 let c25: i64 = nx_h264_mb_type_class(25) 58 gp(logfd, " class: 0->\x00" as *u8); gn(logfd, c0); gp(logfd, " 1->\x00" as *u8); gn(logfd, c1); gp(logfd, " 25->\x00" as *u8); gn(logfd, c25); gp(logfd, " (expect 0 1 2)\n\x00" as *u8) 59 if c0 != NX_MB_I_NXN { ok = 0 } 60 if c1 != NX_MB_I_16X16 { ok = 0 } 61 if c25 != NX_MB_I_PCM { ok = 0 } 62 63 if chk(logfd, 1, out, 0, 0, 0) != 1 { ok = 0 } 64 if chk(logfd, 5, out, 0, 1, 0) != 1 { ok = 0 } 65 if chk(logfd, 12, out, 3, 2, 0) != 1 { ok = 0 } 66 if chk(logfd, 13, out, 0, 0, 15) != 1 { ok = 0 } 67 if chk(logfd, 24, out, 3, 2, 15) != 1 { ok = 0 } 68 69 // ue parse: mb_type=13 encoded "0001110" = bytes {0x1C, ...} (0001110 0 -> 0x1C) 70 let buf: *u8 = sys_mmap(8) 71 buf[0] = 0x1C as u8 // 0001 1100 ; first 7 bits 0001110 = ue 13 72 let br: *BitReader = sys_mmap(NX_BR_BYTES) as *BitReader 73 br_init(br, buf, 8) 74 let mt: i64 = nx_h264_mb_parse_itype(br) 75 gp(logfd, " parse ue mb_type=\x00" as *u8); gn(logfd, mt); gp(logfd, " (expect 13)\n\x00" as *u8) 76 if mt != 13 { ok = 0 } 77 78 if ok == 1 { 79 gp(logfd, "H264-MB-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 80 if logfd > 0 { sys_close(logfd) } 81 sys_exit(0) 82 return 0 83 } 84 gp(logfd, "H264-MB-GATE result=FAIL verdict=RED\n\x00" as *u8) 85 if logfd > 0 { sys_close(logfd) } 86 sys_exit(1) 87 return 1 88}