Support split WebRTC timing and THWC frame chunks#397
Conversation
Add shared WebRTC runtime hooks for integrations whose input sampling cadence differs from their output video cadence. The session manager now uses optional input FPS, input frame count, and steady output frame count hooks while keeping the legacy runtime methods as defaults. Add periodic WebRTC performance logging, support THWC uint8 realtime frame chunks, and relax block KV cache rolling so cache sizes do not need to be divisible by chunk size. Cover the shared behavior with focused realtime, WebRTC manager, and KV cache tests.
Greptile SummaryThis PR adds optional split-clock hooks to
Confidence Score: 5/5Safe to merge; all changed paths are well-tested and the fallback chain ensures no regressions for existing runtimes. The split-clock hooks use a getattr/callable guard pattern that is entirely additive and backward-compatible. The KV cache divisibility relaxation is mathematically sound — the shift-size assertion in _roll_local_window_left bounds overflow to ≤ chunk_size by construction, and the non-divisible (sink=1, window=16) parametrize case exercises the first non-trivial rolling transition. The THWC dispatch adds a shape[1] != 3 guard that resolves the pre-existing ambiguity noted in prior review threads. New tests cover all three feature areas with focused, targeted cases. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant Manager as BaseWebRTCSessionManager
participant Runtime as WebRTCSessionRuntime
participant Resampler as KeyboardResampler
participant Track as BufferedVideoTrack
Client->>Manager: create_answer(offer_sdp)
Manager->>Runtime: peek_steady_output_num_frames()
Runtime-->>Manager: output_num_frames
Manager->>Track: "BufferedVideoTrack(fps=output_fps, maxsize=output_num_frames)"
Manager->>Runtime: peek_input_fps()
Runtime-->>Manager: input_fps
Manager->>Resampler: "KeyboardResampler(fps=input_fps)"
Manager-->>Client: answer SDP
loop Generation Worker (per chunk)
Manager->>Runtime: peek_next_input_num_frames()
Runtime-->>Manager: input_num_frames
Note over Manager: sleep(input_num_frames / input_fps)
Manager->>Resampler: sample_chunk(input_num_frames)
Resampler-->>Manager: segments, frame_times
Manager->>Runtime: generate_chunk(segments, frame_times)
Runtime-->>Manager: WebRTCStepResult(num_frames, video_chunk)
Manager->>Track: enqueue_chunk(video_chunk)
Note over Manager: Log perf every N chunks
Manager->>Client: "chunk_done(num_frames=result.num_frames)"
end
Reviews (2): Last reviewed commit: "Address GitHub PR review feedback" | Re-trigger Greptile |
Tighten THWC chunk detection so legacy TCHW tensors with width 3 are not misclassified, and add a regression test for that ambiguous shape. Document the BlockKVCache roll/update invariant and include Ruff's import ordering fix from the failed CPU lint job.
Add shared WebRTC runtime hooks for integrations whose input sampling cadence differs from their output video cadence. The session manager now uses optional input FPS, input frame count, and steady output frame count hooks while keeping the legacy runtime methods as defaults.
Add periodic WebRTC performance logging, support THWC uint8 realtime frame chunks, and relax block KV cache rolling so cache sizes do not need to be divisible by chunk size.
Cover the shared behavior with focused realtime, WebRTC manager, and KV cache tests.