Files
kinect/tools/record-replay/vkrr/__main__.py
T
kinect-bot 4a66699d82
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python tracker (pytest) (push) Canceled after 0s
feat(mapping,tracker,tools): NUI mapping+smoothing, MediaPipe tracker, record/replay harness, mock NUI host (wave 3)
2026-11-25 04:21:18 -05:00

54 lines
1.7 KiB
Python

"""Runnable record/replay demo: ``python -m vkrr [fixture_path]`` (plan todo 16).
Records a short synthetic frame sequence, writes a fixture, replays it on a fake
clock, and prints a summary proving the replay is byte-identical and the fake
clock advanced without any wall-clock wait.
"""
import sys
import tempfile
import time
from . import (
ContractFrameBuffer,
FakeClock,
Recorder,
Replayer,
build_synthetic_frame,
read_fixture,
)
def main(argv: list[str]) -> int:
path = argv[1] if len(argv) > 1 else tempfile.mktemp(suffix=".vkrr")
buffer = ContractFrameBuffer()
recorder = Recorder()
frame_count = 30
for index in range(frame_count):
buffer.publish(build_synthetic_frame(index, 1_000_000 + index * 33_333, seed=7))
recorder.poll(buffer)
recorder.write(path)
originals = [bytes(frame) for _seq, frame in recorder.frames]
header, _ = read_fixture(path)
clock = FakeClock()
wall_start = time.monotonic()
replayed = Replayer.from_fixture(path, clock).replay(lambda _s, _f: None)
wall_elapsed_ms = (time.monotonic() - wall_start) * 1000.0
replayed_bytes = [bytes(frame) for _seq, frame in replayed]
identical = replayed_bytes == originals
print(f"fixture : {path}")
print(f"format/contract : v{header.format_version} / contract v{header.contract_version}")
print(f"recorded frames : {header.frame_count}")
print(f"byte-identical : {identical}")
print(f"virtual clock adv : {clock.now_micros() - 1_000_000} us over {frame_count} frames")
print(f"wall time : {wall_elapsed_ms:.3f} ms (fake clock, no sleeps)")
return 0 if identical else 1
if __name__ == "__main__":
raise SystemExit(main(sys.argv))