mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 19:03:46 +02:00
Circumvent flush() being called on sources when cancelling output, surface error before doing cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mediabunny/mp3-encoder",
|
||||
"version": "0.0.1",
|
||||
"version": "1.6.0",
|
||||
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||
"types": "./dist/modules/src/index.d.ts",
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { WorkerCommand, WorkerResponse, WorkerResponseData } from './shared
|
||||
import createWorker from './encode.worker';
|
||||
|
||||
class Mp3Encoder extends CustomAudioEncoder {
|
||||
private worker!: Worker;
|
||||
private worker: Worker | null = null;
|
||||
private nextMessageId = 0;
|
||||
private pendingMessages = new Map<number, {
|
||||
resolve: (value: WorkerResponseData) => void;
|
||||
@@ -23,7 +23,7 @@ class Mp3Encoder extends CustomAudioEncoder {
|
||||
private buffer = new Uint8Array(2 ** 16);
|
||||
private currentBufferOffset = 0;
|
||||
private currentTimestamp = 0;
|
||||
private chunkMetadata!: EncodedAudioChunkMetadata;
|
||||
private chunkMetadata: EncodedAudioChunkMetadata = {};
|
||||
|
||||
static override supports(codec: AudioCodec, config: AudioDecoderConfig): boolean {
|
||||
return codec === 'mp3'
|
||||
@@ -113,7 +113,7 @@ class Mp3Encoder extends CustomAudioEncoder {
|
||||
}
|
||||
|
||||
close() {
|
||||
this.worker.terminate();
|
||||
this.worker?.terminate();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,6 +174,8 @@ class Mp3Encoder extends CustomAudioEncoder {
|
||||
const id = this.nextMessageId++;
|
||||
this.pendingMessages.set(id, { resolve, reject });
|
||||
|
||||
assert(this.worker);
|
||||
|
||||
if (transferables) {
|
||||
this.worker.postMessage({ id, command }, transferables);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user