code wiki / (root) / nx_vcodec_wasm.nx

nx_vcodec_wasm.nx source

↩ module page · 34 lines · 2695 B

1// nx_vcodec_wasm.nx -- the BROWSER entry wrapper for the sovereign video codec (nx_vcodec). Same wasm memory model as 2// nx_wasmvoxel/nx_wasmcube: fixed linear-memory offsets (the codec's "caller-owned scratch" become wasm offsets), a 3// handful of exported entry/accessor funcs, main()=0. This wrapper drives the TRANSMITTABLE PACKED codec -- the path 4// the gates prove and the daemon relays -- so the in-browser demo exercises the real encode->stream->INDEPENDENT-decode 5// (with directional intra prediction + the sovereign H.264 integer DCT), not just an encoder-side reconstruction. 6// JS only ferries raw bytes + blits to <canvas>; ALL codec logic is sovereign nx compiled nx_compile_wat -> 7// nx_wat_compiler -> .wasm. Frame cap 128x128 this rung. license_tier: ORIGINAL 8import "nx_vcodec.nx" 9 10const O_CUR: i64 = 0 // current frame, 8bpp luma (up to 128*128 = 16384 B) 11const O_PREV: i64 = 16384 // previous reconstructed reference (unused for a keyframe) 12const O_ENC_RECON: i64 = 32768 // encoder-side reconstruction 13const O_DEC_RECON: i64 = 49152 // INDEPENDENT decoder reconstruction (what the far side sees) 14const O_STREAM: i64 = 65536 // the transmittable bitstream (up to 65536 B) 15const O_BLK: i64 = 131072 // 16 i64 transform scratch 16const O_MV: i64 = 131200 // 2 i64 motion vector 17 18// encode CUR against PREV at (qp, keyframe, sad_thresh): writes the transmittable stream to STREAM and the encoder 19// reconstruction to ENC_RECON; returns the total compressed bit count. (Browser copies a recon -> PREV between frames.) 20func vc_wasm_encode(W: i64, H: i64, qp: i64, keyframe: i64, sad_thresh: i64) -> i64 { 21 return vc_enc_frame_packed((O_CUR as i64) as *u8, (O_PREV as i64) as *u8, (O_ENC_RECON as i64) as *u8, W, H, qp, keyframe, sad_thresh, (O_STREAM as i64) as *u8, (O_BLK as i64) as *i64, (O_MV as i64) as *i64) 22} 23// decode the STREAM (using PREV only) -> writes the INDEPENDENT reconstruction to DEC_RECON; returns bits consumed. 24// Proves the bitstream is self-describing: the decoder never sees the original, only (prev + stream). 25func vc_wasm_decode(W: i64, H: i64, qp: i64) -> i64 { 26 return vc_dec_frame_packed((O_PREV as i64) as *u8, (O_DEC_RECON as i64) as *u8, W, H, qp, (O_STREAM as i64) as *u8, (O_BLK as i64) as *i64, (O_MV as i64) as *i64) 27} 28// offset accessors so the JS last-mile knows where to write/read (no hard-coded addresses on the JS side) 29func vc_cur_off() -> i64 { return O_CUR } 30func vc_prev_off() -> i64 { return O_PREV } 31func vc_enc_recon_off() -> i64 { return O_ENC_RECON } 32func vc_dec_recon_off() -> i64 { return O_DEC_RECON } 33func vc_stream_off() -> i64 { return O_STREAM } 34func main() -> i64 { return 0 }