Committed by
GitHub
Fix track disposal crashing on disconnect (#307)
正在显示
2 个修改的文件
包含
16 行增加
和
7 行删除
| @@ -669,6 +669,8 @@ internal constructor( | @@ -669,6 +669,8 @@ internal constructor( | ||
| 669 | if (track != null) { | 669 | if (track != null) { |
| 670 | track.stop() | 670 | track.stop() |
| 671 | unpublishTrack(track) | 671 | unpublishTrack(track) |
| 672 | + | ||
| 673 | + // We have the original track object reference, meaning we own it. Dispose here. | ||
| 672 | track.dispose() | 674 | track.dispose() |
| 673 | } | 675 | } |
| 674 | } | 676 | } |
| @@ -18,7 +18,11 @@ package io.livekit.android.room.participant | @@ -18,7 +18,11 @@ package io.livekit.android.room.participant | ||
| 18 | 18 | ||
| 19 | import io.livekit.android.events.ParticipantEvent | 19 | import io.livekit.android.events.ParticipantEvent |
| 20 | import io.livekit.android.room.SignalClient | 20 | import io.livekit.android.room.SignalClient |
| 21 | -import io.livekit.android.room.track.* | 21 | +import io.livekit.android.room.track.RemoteAudioTrack |
| 22 | +import io.livekit.android.room.track.RemoteTrackPublication | ||
| 23 | +import io.livekit.android.room.track.RemoteVideoTrack | ||
| 24 | +import io.livekit.android.room.track.Track | ||
| 25 | +import io.livekit.android.room.track.TrackException | ||
| 22 | import io.livekit.android.util.CloseableCoroutineScope | 26 | import io.livekit.android.util.CloseableCoroutineScope |
| 23 | import io.livekit.android.util.LKLog | 27 | import io.livekit.android.util.LKLog |
| 24 | import io.livekit.android.webrtc.RTCStatsGetter | 28 | import io.livekit.android.webrtc.RTCStatsGetter |
| @@ -57,7 +61,7 @@ class RemoteParticipant( | @@ -57,7 +61,7 @@ class RemoteParticipant( | ||
| 57 | info.identity, | 61 | info.identity, |
| 58 | signalClient, | 62 | signalClient, |
| 59 | ioDispatcher, | 63 | ioDispatcher, |
| 60 | - defaultDispatcher | 64 | + defaultDispatcher, |
| 61 | ) { | 65 | ) { |
| 62 | super.updateFromInfo(info) | 66 | super.updateFromInfo(info) |
| 63 | } | 67 | } |
| @@ -83,7 +87,7 @@ class RemoteParticipant( | @@ -83,7 +87,7 @@ class RemoteParticipant( | ||
| 83 | publication = RemoteTrackPublication( | 87 | publication = RemoteTrackPublication( |
| 84 | trackInfo, | 88 | trackInfo, |
| 85 | participant = this, | 89 | participant = this, |
| 86 | - ioDispatcher = ioDispatcher | 90 | + ioDispatcher = ioDispatcher, |
| 87 | ) | 91 | ) |
| 88 | 92 | ||
| 89 | newTrackPublications[trackSid] = publication | 93 | newTrackPublications[trackSid] = publication |
| @@ -147,7 +151,7 @@ class RemoteParticipant( | @@ -147,7 +151,7 @@ class RemoteParticipant( | ||
| 147 | name = "", | 151 | name = "", |
| 148 | autoManageVideo = autoManageVideo, | 152 | autoManageVideo = autoManageVideo, |
| 149 | dispatcher = ioDispatcher, | 153 | dispatcher = ioDispatcher, |
| 150 | - receiver = receiver | 154 | + receiver = receiver, |
| 151 | ) | 155 | ) |
| 152 | 156 | ||
| 153 | else -> throw TrackException.InvalidTrackTypeException("invalid track type: $kind") | 157 | else -> throw TrackException.InvalidTrackTypeException("invalid track type: $kind") |
| @@ -176,7 +180,11 @@ class RemoteParticipant( | @@ -176,7 +180,11 @@ class RemoteParticipant( | ||
| 176 | 180 | ||
| 177 | val track = publication.track | 181 | val track = publication.track |
| 178 | if (track != null) { | 182 | if (track != null) { |
| 179 | - track.stop() | 183 | + try { |
| 184 | + track.stop() | ||
| 185 | + } catch (e: IllegalStateException) { | ||
| 186 | + // track may already be disposed, ignore. | ||
| 187 | + } | ||
| 180 | internalListener?.onTrackUnsubscribed(track, publication, this) | 188 | internalListener?.onTrackUnsubscribed(track, publication, this) |
| 181 | listener?.onTrackUnsubscribed(track, publication, this) | 189 | listener?.onTrackUnsubscribed(track, publication, this) |
| 182 | eventBus.postEvent(ParticipantEvent.TrackUnsubscribed(this, track, publication), scope) | 190 | eventBus.postEvent(ParticipantEvent.TrackUnsubscribed(this, track, publication), scope) |
| @@ -186,7 +194,6 @@ class RemoteParticipant( | @@ -186,7 +194,6 @@ class RemoteParticipant( | ||
| 186 | listener?.onTrackUnpublished(publication, this) | 194 | listener?.onTrackUnpublished(publication, this) |
| 187 | eventBus.postEvent(ParticipantEvent.TrackUnpublished(this, publication), scope) | 195 | eventBus.postEvent(ParticipantEvent.TrackUnpublished(this, publication), scope) |
| 188 | } | 196 | } |
| 189 | - track?.dispose() | ||
| 190 | publication.track = null | 197 | publication.track = null |
| 191 | } | 198 | } |
| 192 | 199 | ||
| @@ -198,7 +205,7 @@ class RemoteParticipant( | @@ -198,7 +205,7 @@ class RemoteParticipant( | ||
| 198 | 205 | ||
| 199 | eventBus.postEvent( | 206 | eventBus.postEvent( |
| 200 | ParticipantEvent.TrackSubscriptionPermissionChanged(this, pub, pub.subscriptionAllowed), | 207 | ParticipantEvent.TrackSubscriptionPermissionChanged(this, pub, pub.subscriptionAllowed), |
| 201 | - coroutineScope | 208 | + coroutineScope, |
| 202 | ) | 209 | ) |
| 203 | } | 210 | } |
| 204 | } | 211 | } |
-
请 注册 或 登录 后发表评论