Terminate Workers and fix memory leak
This commit is contained in:
parent
2e0b8c2a43
commit
833c2e23ba
|
@ -22,6 +22,10 @@ export class AtracdencProcess {
|
|||
return eventData.data.result as Uint8Array;
|
||||
}
|
||||
|
||||
terminate() {
|
||||
this.worker.terminate();
|
||||
}
|
||||
|
||||
handleMessage(ev: MessageEvent) {
|
||||
this.messageCallback!(ev);
|
||||
this.messageCallback = undefined;
|
||||
|
@ -65,7 +69,6 @@ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScop
|
|||
},
|
||||
[result]
|
||||
);
|
||||
self.close();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
|
|
@ -80,11 +80,12 @@ export class FFMpegAudioExportService implements AudioExportService {
|
|||
}
|
||||
|
||||
async export({ format }: { format: string }) {
|
||||
let result: ArrayBuffer;
|
||||
if (format === `SP`) {
|
||||
const outFileName = `${this.outFileNameNoExt}.raw`;
|
||||
await this.ffmpegProcess.transcode(this.inFileName, outFileName, '-f s16be -ar 44100');
|
||||
let { data } = await this.ffmpegProcess.read(outFileName);
|
||||
return data.buffer;
|
||||
result = data.buffer;
|
||||
} else {
|
||||
const outFileName = `${this.outFileNameNoExt}.wav`;
|
||||
await this.ffmpegProcess.transcode(this.inFileName, outFileName, '-f wav -ar 44100');
|
||||
|
@ -101,8 +102,10 @@ export class FFMpegAudioExportService implements AudioExportService {
|
|||
bitrate = `64`;
|
||||
break;
|
||||
}
|
||||
let result = await this.atracdencProcess!.encode(data.buffer, bitrate);
|
||||
result = await this.atracdencProcess!.encode(data.buffer, bitrate);
|
||||
}
|
||||
this.ffmpegProcess.worker.terminate();
|
||||
this.atracdencProcess!.terminate();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,8 @@ export class NetMDUSBService implements NetMDService {
|
|||
written = writtenBytes;
|
||||
updateProgress();
|
||||
});
|
||||
|
||||
w.terminate();
|
||||
}
|
||||
|
||||
async play() {
|
||||
|
|
Loading…
Reference in New Issue