code wiki / _hdl_build / nx_dash_parse_gate.nx

nx_dash_parse_gate.nx source

↩ module page · 39 lines · 3355 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" 7 8func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 9" as *u8); return ok } 10func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 11func has(buf: *u8, want: *u8) -> i64 { if dp_find(buf, gsl(buf), want, gsl(want), 0) >= 0 { return 1 } return 0 } 12 13func main() -> i64 { 14 gw("dash-parse SOVEREIGN gate (.mpd SegmentTemplate+Timeline -> segment URLs)\n" as *u8) 15 var pass: i64 = 0 16 var ttl: i64 = 0 17 18 // single video representation, SegmentTimeline r=9 -> 10 media segments + 1 init. 19 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 20 let out1: *u8 = sys_mmap(16384) 21 let c1: i64 = dash_parse(mpd1, gsl(mpd1), out1, 16384) 22 ttl=ttl+1; pass=pass+grow("D1 count == 11 (init + 10 segs)\x00" as *u8, (c1 == 11) as i64) 23 ttl=ttl+1; pass=pass+grow("D2 init-v0.m4s present\x00" as *u8, has(out1, "init-v0.m4s\x00" as *u8)) 24 ttl=ttl+1; pass=pass+grow("D3 seg-v0-1.m4s present\x00" as *u8, has(out1, "seg-v0-1.m4s\x00" as *u8)) 25 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)) 26 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))) 27 28 // two representations: highest-bandwidth (hi, 2Mbps) must win over lo (0.5Mbps). 29 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 30 let out2: *u8 = sys_mmap(16384) 31 let c2: i64 = dash_parse(mpd2, gsl(mpd2), out2, 16384) 32 ttl=ttl+1; pass=pass+grow("D6 count == 4 (init + 3 segs)\x00" as *u8, (c2 == 4) as i64) 33 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)) 34 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))) 35 36 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 37 if pass == ttl { gw("verdict=GREEN (DASH .mpd -> init + numbered segment URLs, highest-bw rep)\n" as *u8); sys_exit(0); return 0 } 38 gw("verdict=RED\n" as *u8); sys_exit(1); return 1 39}