code wiki / (root) / nx_svc.nx

nx_svc.nx source

↩ module page · 36 lines · 2102 B

1// nx_svc.nx -- sovereign SCALABLE VIDEO CODING: dyadic TEMPORAL LAYERS (the VP9/AV1 SVC technique). One encode 2// produces a layered stream; a weak link (the girl on bad mobile) decodes only the BASE layer (lower fps), a good 3// link decodes all layers (full fps) -- no re-encode, no separate streams. The invariant that makes it work: a 4// frame only REFERENCES frames in its own layer or below, so dropping higher layers leaves a valid lower-fps 5// stream. Research: VP9/AV1 SVC, scalable conferencing (arXiv 2503.11649). Pure index logic. license_tier: ORIGINAL 6 7// trailing-zero count of n (n=0 -> a large cap value) 8func svc_tz(n: i64) -> i64 { 9 if n == 0 { return 99 } 10 var c: i64 = 0; var m: i64 = n 11 while (m & 1) == 0 { c = c + 1; m = m >> 1 } 12 return c 13} 14// the dyadic temporal layer of frame n (0 = base/lowest fps, nlayers-1 = top). Pattern over a period of 15// 2^(nlayers-1): e.g. nlayers=3 -> [0,2,1,2,0,2,1,2,...]. 16func svc_temporal_id(n: i64, nlayers: i64) -> i64 { 17 let cap: i64 = nlayers - 1 18 var tz: i64 = svc_tz(n) 19 if tz > cap { tz = cap } 20 return cap - tz 21} 22// can a receiver that decodes up to max_layer play frame n? (yes iff the frame's layer <= max_layer) 23func svc_can_decode(n: i64, nlayers: i64, max_layer: i64) -> i64 { 24 if svc_temporal_id(n, nlayers) <= max_layer { return 1 } 25 return 0 26} 27// frames decodable per period at max_layer = 2^max_layer (out of the 2^(nlayers-1) period) -> the fps fraction. 28func svc_frames_per_period(max_layer: i64) -> i64 { var f: i64 = 1; var i: i64 = 0; while i < max_layer { f = f * 2; i = i + 1 } return f } 29func svc_period(nlayers: i64) -> i64 { return svc_frames_per_period(nlayers - 1) } 30// reference RULE / invariant: a frame may reference an earlier frame only if that frame's layer <= its own layer. 31// (So dropping the higher layers never orphans a kept frame.) returns 1 if (ref_n -> n) is a legal reference. 32func svc_valid_ref(ref_n: i64, n: i64, nlayers: i64) -> i64 { 33 if ref_n >= n { return 0 } 34 if svc_temporal_id(ref_n, nlayers) <= svc_temporal_id(n, nlayers) { return 1 } 35 return 0 36}