fix: restore webcam sessions and stop export deadlocks

This commit is contained in:
Siddharth
2026-03-17 18:50:05 -07:00
parent 0a0dd088c3
commit b33ec5e2d7
3 changed files with 75 additions and 7 deletions
+9 -1
View File
@@ -167,6 +167,7 @@ export class GifExporter {
let frameIndex = 0;
webcamFrameQueue = this.config.webcamVideoUrl ? new AsyncVideoFrameQueue() : null;
let stopWebcamDecode = false;
let webcamDecodeError: Error | null = null;
const webcamDecodePromise =
this.webcamDecoder && webcamFrameQueue
@@ -178,9 +179,13 @@ export class GifExporter {
this.config.trimRegions,
this.config.speedRegions,
async (webcamFrame) => {
while (queue.length >= 12 && !this.cancelled) {
while (queue.length >= 12 && !this.cancelled && !stopWebcamDecode) {
await new Promise((resolve) => setTimeout(resolve, 2));
}
if (this.cancelled || stopWebcamDecode) {
webcamFrame.close();
return;
}
queue.enqueue(webcamFrame);
},
)
@@ -248,6 +253,9 @@ export class GifExporter {
return { success: false, error: "Export cancelled" };
}
stopWebcamDecode = true;
webcamFrameQueue?.destroy();
this.webcamDecoder?.cancel();
await webcamDecodePromise;
// Update progress to show we're now in the finalizing phase
+9 -1
View File
@@ -118,6 +118,7 @@ export class VideoExporter {
const frameDuration = 1_000_000 / this.config.frameRate; // in microseconds
let frameIndex = 0;
webcamFrameQueue = this.config.webcamVideoUrl ? new AsyncVideoFrameQueue() : null;
let stopWebcamDecode = false;
let webcamDecodeError: Error | null = null;
const webcamDecodePromise =
this.webcamDecoder && webcamFrameQueue
@@ -129,9 +130,13 @@ export class VideoExporter {
this.config.trimRegions,
this.config.speedRegions,
async (webcamFrame) => {
while (queue.length >= 12 && !this.cancelled) {
while (queue.length >= 12 && !this.cancelled && !stopWebcamDecode) {
await new Promise((resolve) => setTimeout(resolve, 2));
}
if (this.cancelled || stopWebcamDecode) {
webcamFrame.close();
return;
}
queue.enqueue(webcamFrame);
},
)
@@ -229,6 +234,9 @@ export class VideoExporter {
return { success: false, error: "Export cancelled" };
}
stopWebcamDecode = true;
webcamFrameQueue?.destroy();
this.webcamDecoder?.cancel();
await webcamDecodePromise;
// Finalize encoding