Fix running = false being set too late for ReadOrchestrator workers (fixes #84)

This commit is contained in:
Vanilagy
2025-09-02 16:21:39 +02:00
parent 62b04f4dcb
commit 4b3fb34a95
2 changed files with 13 additions and 5 deletions
+2 -2
View File
@@ -24,7 +24,7 @@
chunked: true,
chunkSize: 2**20
});
const outputFormat = new Mediabunny.Mp4OutputFormat({});
const outputFormat = new Mediabunny.WavOutputFormat({});
const button = document.createElement('button');
button.textContent = 'Cancel';
@@ -74,7 +74,7 @@
},
*/
video: () => ({
codec: 'avc',
//codec: 'avc',
//fit: 'contain',
//frameRate: 27.123,
//width: 320,
+11 -3
View File
@@ -178,6 +178,8 @@ export class BlobSource extends Source {
this.onread?.(worker.currentPos, worker.currentPos + value.length);
this._orchestrator.supplyWorkerData(worker, value);
}
worker.running = false;
}
}
@@ -409,6 +411,7 @@ export class UrlSource extends Source {
);
}
worker.running = false;
return;
}
@@ -418,11 +421,14 @@ export class UrlSource extends Source {
if (worker.currentPos >= worker.targetPos || worker.aborted) {
abortController.abort();
worker.running = false;
return;
}
}
}
worker.running = false;
// The previous UrlSource had logic for circumventing https://issues.chromium.org/issues/436025873; I haven't
// been able to observe this bug with the new UrlSource (maybe because we're using response streaming), so the
// logic for that has vanished for now. Leaving a comment here if this becomes relevant again.
@@ -681,6 +687,8 @@ export class StreamSource extends Source {
throw new TypeError('options.read must return or resolve to a Uint8Array or a ReadableStream.');
}
}
worker.running = false;
}
}
@@ -933,6 +941,7 @@ class ReadOrchestrator {
// another one so close to it
const gapTolerance = 2 ** 17;
// This check also implies worker.currentPos <= outerHole.start, a critical condition
if (closedIntervalsOverlap(
outerHole.start - gapTolerance, outerHole.start,
worker.currentPos, worker.targetPos,
@@ -1024,15 +1033,14 @@ class ReadOrchestrator {
void this.options.runWorker(worker)
.catch((error) => {
worker.running = false;
if (worker.pendingSlices.length > 0) {
worker.pendingSlices.forEach(x => x.reject(error)); // Make sure to propagate any errors
worker.pendingSlices.length = 0;
} else {
throw error; // So it doesn't get swallowed
}
})
.finally(() => {
worker.running = false;
});
}