davidliu
Committed by GitHub

Fix restartTrack causing crash on disconnect (#361)

... ... @@ -787,10 +787,14 @@ internal constructor(
if (track != null) {
track.stop()
unpublishTrack(track)
unpublishTrack(track, stopOnUnpublish = false)
// We have the original track object reference, meaning we own it. Dispose here.
track.dispose()
try {
track.dispose()
} catch (e: Exception) {
LKLog.d(e) { "Exception thrown when cleaning up local participant track $pub:" }
}
}
}
}
... ...
... ... @@ -226,9 +226,15 @@ constructor(
oldCapturer.dispose()
oldSource.dispose()
// sender owns rtcTrack, so it'll take care of disposing it.
oldRtcTrack.setEnabled(false)
// We always own our copy of rtcTrack, so we need to dispose it.
// Note: For the first rtcTrack we pass to the PeerConnection, PeerConnection actually
// passes it down to the native, and then ends up holding onto a separate copy at the
// Java layer. This means our initial rtcTrack isn't owned by PeerConnection, and is
// our responsibility to dispose.
oldRtcTrack.dispose()
// Close resources associated to the old track. new track resources is registered in createTrack.
val oldCloseable = closeableManager.unregisterResource(oldRtcTrack)
oldCloseable?.close()
... ... @@ -253,7 +259,7 @@ constructor(
rtcTrack = newTrack.rtcTrack
this.options = options
startCapture()
sender?.setTrack(newTrack.rtcTrack, true)
sender?.setTrack(newTrack.rtcTrack, false)
}
internal fun setPublishingLayers(
... ...