davidliu
Committed by GitHub

Fix restartTrack causing crash on disconnect (#361)

@@ -787,10 +787,14 @@ internal constructor( @@ -787,10 +787,14 @@ internal constructor(
787 787
788 if (track != null) { 788 if (track != null) {
789 track.stop() 789 track.stop()
790 - unpublishTrack(track) 790 + unpublishTrack(track, stopOnUnpublish = false)
791 791
792 // We have the original track object reference, meaning we own it. Dispose here. 792 // We have the original track object reference, meaning we own it. Dispose here.
  793 + try {
793 track.dispose() 794 track.dispose()
  795 + } catch (e: Exception) {
  796 + LKLog.d(e) { "Exception thrown when cleaning up local participant track $pub:" }
  797 + }
794 } 798 }
795 } 799 }
796 } 800 }
@@ -226,9 +226,15 @@ constructor( @@ -226,9 +226,15 @@ constructor(
226 oldCapturer.dispose() 226 oldCapturer.dispose()
227 oldSource.dispose() 227 oldSource.dispose()
228 228
229 - // sender owns rtcTrack, so it'll take care of disposing it.  
230 oldRtcTrack.setEnabled(false) 229 oldRtcTrack.setEnabled(false)
231 230
  231 + // We always own our copy of rtcTrack, so we need to dispose it.
  232 + // Note: For the first rtcTrack we pass to the PeerConnection, PeerConnection actually
  233 + // passes it down to the native, and then ends up holding onto a separate copy at the
  234 + // Java layer. This means our initial rtcTrack isn't owned by PeerConnection, and is
  235 + // our responsibility to dispose.
  236 + oldRtcTrack.dispose()
  237 +
232 // Close resources associated to the old track. new track resources is registered in createTrack. 238 // Close resources associated to the old track. new track resources is registered in createTrack.
233 val oldCloseable = closeableManager.unregisterResource(oldRtcTrack) 239 val oldCloseable = closeableManager.unregisterResource(oldRtcTrack)
234 oldCloseable?.close() 240 oldCloseable?.close()
@@ -253,7 +259,7 @@ constructor( @@ -253,7 +259,7 @@ constructor(
253 rtcTrack = newTrack.rtcTrack 259 rtcTrack = newTrack.rtcTrack
254 this.options = options 260 this.options = options
255 startCapture() 261 startCapture()
256 - sender?.setTrack(newTrack.rtcTrack, true) 262 + sender?.setTrack(newTrack.rtcTrack, false)
257 } 263 }
258 264
259 internal fun setPublishingLayers( 265 internal fun setPublishingLayers(