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