fix(video): vsync remote canvas draws
Some checks failed
Mirror to GitHub / mirror (push) Failing after 31s
Build Release Binaries / build-amd64 (push) Failing after 3m24s

This commit is contained in:
Siavash Sameni
2026-05-26 08:46:11 +04:00
parent f65b399a21
commit 8415804a1a
3 changed files with 14 additions and 7 deletions

View File

@@ -739,6 +739,10 @@ let remoteFrameSerial = 0;
let remoteDrawInFlight = false;
let remotePendingFrame: { serial: number; width: number; height: number; jpeg_b64: string } | null = null;
function nextAnimationFrame() {
return new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
}
async function drawRemoteFrame(frame: { serial: number; width: number; height: number; jpeg_b64: string }) {
const img = new Image();
img.src = `data:image/jpeg;base64,${frame.jpeg_b64}`;
@@ -751,6 +755,8 @@ async function drawRemoteFrame(frame: { serial: number; width: number; height: n
});
}
if (frame.serial !== remoteFrameSerial) return;
await nextAnimationFrame();
if (frame.serial !== remoteFrameSerial) return;
if (vdRemoteVideo.width !== frame.width) vdRemoteVideo.width = frame.width;
if (vdRemoteVideo.height !== frame.height) vdRemoteVideo.height = frame.height;