Terminate Workers and fix memory leak

This commit is contained in:
Stefano Brilli 2020-03-30 10:03:14 +02:00
parent 2e0b8c2a43
commit 833c2e23ba
3 changed files with 12 additions and 4 deletions

View File

@ -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 {

View File

@ -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);
return result;
result = await this.atracdencProcess!.encode(data.buffer, bitrate);
}
this.ffmpegProcess.worker.terminate();
this.atracdencProcess!.terminate();
return result;
}
}

View File

@ -111,6 +111,8 @@ export class NetMDUSBService implements NetMDService {
written = writtenBytes;
updateProgress();
});
w.terminate();
}
async play() {