code wiki / _hdl_build / nx_dash_parse_gate.nx
nx_dash_parse_gate.nx source
↩ module page · 47 lines · 3736 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_dash_parse_gate.nx -- proves DASH .mpd -> segment URL list: SegmentTemplate + SegmentTimeline, with
4// $RepresentationID$/$Number$ substitution + highest-bandwidth Representation selection. license_tier: ORIGINAL expect_exit: 0
5import "nx_syscalls.nx"
6import "nx_dash_parse.nx"
7import "nx_gate_verdict.nx"
8
9func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
10" as *u8); return ok }
11func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12func has(buf: *u8, want: *u8) -> i64 { if dp_find(buf, gsl(buf), want, gsl(want), 0) >= 0 { return 1 } return 0 }
13
14func main() -> i64 {
15 gw("dash-parse SOVEREIGN gate (.mpd SegmentTemplate+Timeline -> segment URLs)\n" as *u8)
16 var pass: i64 = 0
17 var ttl: i64 = 0
18
19 // single video representation, SegmentTimeline r=9 -> 10 media segments + 1 init.
20 let mpd1: *u8 = "<MPD><Period><AdaptationSet contentType=\"video\"><Representation id=\"v0\" bandwidth=\"1000000\"><SegmentTemplate media=\"seg-$RepresentationID$-$Number$.m4s\" initialization=\"init-$RepresentationID$.m4s\" startNumber=\"1\" timescale=\"1000\" duration=\"4000\"><SegmentTimeline><S t=\"0\" d=\"4000\" r=\"9\"/></SegmentTimeline></SegmentTemplate></Representation></AdaptationSet></Period></MPD>" as *u8
21 let out1: *u8 = sys_mmap(16384)
22 let c1: i64 = dash_parse(mpd1, gsl(mpd1), out1, 16384)
23 ttl=ttl+1; pass=pass+grow("D1 count == 11 (init + 10 segs)\x00" as *u8, (c1 == 11) as i64)
24 ttl=ttl+1; pass=pass+grow("D2 init-v0.m4s present\x00" as *u8, has(out1, "init-v0.m4s\x00" as *u8))
25 ttl=ttl+1; pass=pass+grow("D3 seg-v0-1.m4s present\x00" as *u8, has(out1, "seg-v0-1.m4s\x00" as *u8))
26 ttl=ttl+1; pass=pass+grow("D4 seg-v0-10.m4s present (last)\x00" as *u8, has(out1, "seg-v0-10.m4s\x00" as *u8))
27 ttl=ttl+1; pass=pass+grow("D5 seg-v0-11.m4s ABSENT (bounded)\x00" as *u8, (1 - has(out1, "seg-v0-11.m4s\x00" as *u8)))
28
29 // two representations: highest-bandwidth (hi, 2Mbps) must win over lo (0.5Mbps).
30 let mpd2: *u8 = "<MPD><Period><AdaptationSet><Representation id=\"lo\" bandwidth=\"500000\"><SegmentTemplate media=\"lo-$Number$.m4s\" initialization=\"lo-init.m4s\" startNumber=\"1\"><SegmentTimeline><S d=\"4000\" r=\"2\"/></SegmentTimeline></SegmentTemplate></Representation><Representation id=\"hi\" bandwidth=\"2000000\"><SegmentTemplate media=\"hi-$RepresentationID$-$Number$.m4s\" initialization=\"hi-init.m4s\" startNumber=\"1\"><SegmentTimeline><S d=\"4000\" r=\"2\"/></SegmentTimeline></SegmentTemplate></Representation></AdaptationSet></Period></MPD>" as *u8
31 let out2: *u8 = sys_mmap(16384)
32 let c2: i64 = dash_parse(mpd2, gsl(mpd2), out2, 16384)
33 ttl=ttl+1; pass=pass+grow("D6 count == 4 (init + 3 segs)\x00" as *u8, (c2 == 4) as i64)
34 ttl=ttl+1; pass=pass+grow("D7 hi-hi-1.m4s present (highest-bw + $RepresentationID$)\x00" as *u8, has(out2, "hi-hi-1.m4s\x00" as *u8))
35 ttl=ttl+1; pass=pass+grow("D8 lo-1.m4s ABSENT (low-bw rep not used)\x00" as *u8, (1 - has(out2, "lo-1.m4s\x00" as *u8)))
36
37 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8)
38 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
39 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
40 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
41 let ctr__dry: *i64 = gv_ctr()
42 ctr__dry[0] = pass
43 ctr__dry[1] = ttl
44 let rc__dry: i64 = gv_verdict("DASH-PARSE-GATE" as *u8, ctr__dry, "DASH .mpd -> init + numbered segment URLs, highest-bw rep)" as *u8)
45 sys_exit(rc__dry)
46 return rc__dry
47}