Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy FFMPEG WASM workers when the dispose lifecycle event happens #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});