mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Make _flushOrWaitForOngoingClose set closingPromise (fixes #270)
This commit is contained in:
+4
-6
@@ -134,12 +134,10 @@ export abstract class MediaSource {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
async _flushOrWaitForOngoingClose(forceClose: boolean) {
|
async _flushOrWaitForOngoingClose(forceClose: boolean) {
|
||||||
if (this._closingPromise) {
|
return this._closingPromise ??= (async () => {
|
||||||
// Since closing also flushes, we don't want to do it twice
|
await this._flushAndClose(forceClose);
|
||||||
return this._closingPromise;
|
this._closed = true;
|
||||||
} else {
|
})();
|
||||||
return this._flushAndClose(forceClose);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { test } from 'vitest';
|
||||||
|
import { Output } from '../../src/output.js';
|
||||||
|
import { WebMOutputFormat } from '../../src/output-format.js';
|
||||||
|
import { BufferTarget } from '../../src/target.js';
|
||||||
|
import { VideoSampleSource } from '../../src/media-source.js';
|
||||||
|
import { VideoSample } from '../../src/sample.js';
|
||||||
|
import { QUALITY_MEDIUM } from '../../src/encode.js';
|
||||||
|
|
||||||
|
test('VideoSampleSource.close() should be idempotent after finalize()', async () => {
|
||||||
|
const output = new Output({
|
||||||
|
format: new WebMOutputFormat(),
|
||||||
|
target: new BufferTarget(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const videoSource = new VideoSampleSource({
|
||||||
|
codec: 'vp8',
|
||||||
|
bitrate: QUALITY_MEDIUM,
|
||||||
|
});
|
||||||
|
|
||||||
|
output.addVideoTrack(videoSource);
|
||||||
|
await output.start();
|
||||||
|
|
||||||
|
const canvas = new OffscreenCanvas(100, 100);
|
||||||
|
const ctx = canvas.getContext('2d')!;
|
||||||
|
ctx.fillStyle = 'red';
|
||||||
|
ctx.fillRect(0, 0, 100, 100);
|
||||||
|
|
||||||
|
const sample = new VideoSample(canvas, { timestamp: 0, duration: 1 / 30 });
|
||||||
|
await videoSource.add(sample);
|
||||||
|
sample.close();
|
||||||
|
|
||||||
|
await output.finalize();
|
||||||
|
|
||||||
|
videoSource.close(); // This previously threw
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user