From a77a13f5db708ae4cea47bf2812d6dc6653f7a36 Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Mon, 26 Aug 2024 16:09:31 +0200 Subject: [PATCH] Don't unlock the mutex when its not locked (#1165) --- .../video/android/core/call/RtcSession.kt | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/RtcSession.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/RtcSession.kt index 210b903166..ddec0150ec 100644 --- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/RtcSession.kt +++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/call/RtcSession.kt @@ -907,9 +907,10 @@ public class RtcSession internal constructor( return@synchronized } - val enabledRids = event.changePublishQuality.video_senders.firstOrNull()?.layers?.associate { - it.name to it.active - } + val enabledRids = + event.changePublishQuality.video_senders.firstOrNull()?.layers?.associate { + it.name to it.active + } dynascaleLogger.i { "enabled rids: $enabledRids}" } val params = sender.parameters val updatedEncodings: MutableList = mutableListOf() @@ -1069,9 +1070,10 @@ public class RtcSession internal constructor( fun handleEvent(event: VideoEvent) { logger.i { "[rtc handleEvent] #sfu; event: $event" } if (event is JoinCallResponseEvent) { - logger.i { "[rtc handleEvent] unlocking joinEventReceivedMutex" } - - joinEventReceivedMutex.unlock() + if (joinEventReceivedMutex.isLocked) { + logger.i { "[rtc handleEvent] unlocking joinEventReceivedMutex" } + joinEventReceivedMutex.unlock() + } } if (event is SfuDataEvent) { coroutineScope.launch { @@ -1410,7 +1412,13 @@ public class RtcSession internal constructor( track_id = track.id(), track_type = trackType, layers = layers, - mid = transceiver.mid ?: extractMid(sdp, track, screenShareTrack, trackType, transceivers), + mid = transceiver.mid ?: extractMid( + sdp, + track, + screenShareTrack, + trackType, + transceivers, + ), ) } return tracks @@ -1429,6 +1437,7 @@ public class RtcSession internal constructor( TrackType.TRACK_TYPE_VIDEO } } + else -> TrackType.TRACK_TYPE_UNSPECIFIED } @@ -1475,7 +1484,10 @@ public class RtcSession internal constructor( return media.mid.toString() } - private fun createVideoLayers(transceiver: RtpTransceiver, captureResolution: CaptureFormat): List { + private fun createVideoLayers( + transceiver: RtpTransceiver, + captureResolution: CaptureFormat, + ): List { // we tell the Sfu which resolutions we're sending return transceiver.sender.parameters.encodings.map { val scaleBy = it.scaleResolutionDownBy ?: 1.0 @@ -1715,7 +1727,13 @@ public class RtcSession internal constructor( } } - suspend fun switchSfu(sfuName: String, sfuUrl: String, sfuToken: String, remoteIceServers: List, failedToSwitch: () -> Unit) { + suspend fun switchSfu( + sfuName: String, + sfuUrl: String, + sfuToken: String, + remoteIceServers: List, + failedToSwitch: () -> Unit, + ) { logger.i { "[switchSfu] from ${this.sfuUrl} to $sfuUrl" } val timer = clientImpl.debugInfo.trackTime("call.switchSfu")