Skip to content

Commit

Permalink
Destroy FFMPEG WASM workers when the dispose lifecycle event happens
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-kira committed Nov 13, 2024
1 parent 1285cec commit b5d97e4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/js/engine/convert-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class ConvertEngine extends Component {
// download converted file
downloadBlob(fileName, this.player().convertedData);
}

/**
* Remove any temporary data and references
*/
dispose() {
super.dispose();
}
}

// expose component for external plugins
Expand Down
11 changes: 11 additions & 0 deletions src/js/plugins/ffmpeg-wasm-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ class FFmpegWasmEngine extends ConvertEngine {
// notify listeners
this.player().trigger('finishConvert');
}

/**
* Terminate the FFMPEG workers if they have been started
*/
dispose() {
super.dispose();
if (this.ffmpeg !== null && this.ffmpeg.loaded) {
this.ffmpeg.terminate();
this.ffmpeg = null;
}
}
}

// expose plugin
Expand Down
5 changes: 5 additions & 0 deletions src/js/videojs.record.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,11 @@ class Record extends Plugin {
this.engine.off(Event.RECORD_COMPLETE, this.engineStopCallback);
}

// Clean up any resources the converter engine may have used
if (this.converter) {
this.converter.dispose();
}

// stop recording and device
this.stop();
this.stopDevice();
Expand Down
9 changes: 9 additions & 0 deletions test/engine/convert-engine.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ describe('engine.convert-engine', () => {
done();
});
});

it('should call dispose when the player is disposed', (done) => {
let engine = new ConvertEngine(player, {});
spyOn(engine, 'dispose');

player.dispose();

expect(engine.dispose).toHaveBeenCalled();
});
});

0 comments on commit b5d97e4

Please sign in to comment.