Skip to content

Commit

Permalink
webrtc: fix ffmpeg leaks?
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 30, 2024
1 parent f4dcb8e commit be98083
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions plugins/webrtc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/webrtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/webrtc",
"version": "0.2.17",
"version": "0.2.18",
"scripts": {
"scrypted-setup-project": "scrypted-setup-project",
"prescrypted-setup-project": "scrypted-package-json",
Expand Down
5 changes: 3 additions & 2 deletions plugins/webrtc/src/ffmpeg-to-wrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ class WebRTCTrack implements RTCOutputMediaObjectTrack, RTCInputMediaObjectTrack

constructor(public connectionManagement: WebRTCConnectionManagement, public video: RTCRtpTransceiver, public audio: RTCRtpTransceiver, intercom: Intercom) {
this.control = new ScryptedSessionControl(intercom, audio);
this.connectionManagement.activeTracks.add(this);
}

async onStop(): Promise<void> {
Expand Down Expand Up @@ -623,7 +624,7 @@ export class WebRTCConnectionManagement implements RTCConnectionManagement {

async close(): Promise<void> {
for (const track of this.activeTracks) {
track.cleanup(true);
track.cleanup(false);
}
this.activeTracks.clear();
this.pc.close();
Expand Down Expand Up @@ -662,7 +663,7 @@ export async function createRTCPeerConnectionSink(
});

track.control.killed.promise.then(() => {
track.cleanup(true);
track.cleanup(false);
connection.pc.close();
});

Expand Down
3 changes: 2 additions & 1 deletion plugins/webrtc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,10 @@ export async function fork() {

const cleanup = new Deferred<string>();
cleanup.promise.catch(e => this.console.log('cleaning up rtc connection:', e.message));
cleanup.promise.finally(() => setTimeout(() => process.exit(), 10000));
cleanup.promise.finally(() => setTimeout(() => process.exit(), 30000));

const connection = new WebRTCConnectionManagement(console, clientSession, maximumCompatibilityMode, clientOptions, options);
cleanup.promise.finally(() => connection.close().catch(() => { }));
const { pc } = connection;
waitClosed(pc).then(() => cleanup.resolve('peer connection closed'));

Expand Down

0 comments on commit be98083

Please sign in to comment.