Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
livekitAndroidXuningTest
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
davidliu
2024-04-13 20:14:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-04-13 20:14:30 +0900
Commit
83e70df5393230178d4380c0ad89175a68c34862
83e70df5
1 parent
6b2671b9
Fix ConcurrentModificationException in RemoteVideoTrack (#413)
显示空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
28 行增加
和
6 行删除
livekit-android-sdk/src/main/java/io/livekit/android/room/track/RemoteVideoTrack.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/track/RemoteVideoTrack.kt
查看文件 @
83e70df
...
...
@@ -23,7 +23,11 @@ import io.livekit.android.events.TrackEvent
import io.livekit.android.room.track.video.VideoSinkVisibility
import io.livekit.android.room.track.video.ViewVisibility
import io.livekit.android.util.LKLog
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import livekit.org.webrtc.RtpReceiver
import livekit.org.webrtc.VideoSink
import javax.inject.Named
...
...
@@ -40,7 +44,8 @@ class RemoteVideoTrack(
private var coroutineScope = CoroutineScope(dispatcher + SupervisorJob())
private val sinkVisibilityMap = mutableMapOf<VideoSink, VideoSinkVisibility>()
private val visibilities = sinkVisibilityMap.values
private val visibilities
get() = sinkVisibilityMap.values
/**
* @suppress
...
...
@@ -80,7 +85,9 @@ class RemoteVideoTrack(
fun addRenderer(renderer: VideoSink, visibility: VideoSinkVisibility) {
super.addRenderer(renderer)
if (autoManageVideo) {
synchronized(sinkVisibilityMap) {
sinkVisibilityMap[renderer] = visibility
}
visibility.addObserver { _, _ -> recalculateVisibility() }
recalculateVisibility()
} else {
...
...
@@ -90,7 +97,11 @@ class RemoteVideoTrack(
override fun removeRenderer(renderer: VideoSink) {
super.removeRenderer(renderer)
val visibility = sinkVisibilityMap.remove(renderer)
val visibility = synchronized(sinkVisibilityMap) {
sinkVisibilityMap.remove(renderer)
}
visibility?.close()
if (autoManageVideo && visibility != null) {
recalculateVisibility()
...
...
@@ -99,29 +110,40 @@ class RemoteVideoTrack(
override fun stop() {
super.stop()
synchronized(sinkVisibilityMap) {
sinkVisibilityMap.values.forEach { it.close() }
sinkVisibilityMap.clear()
}
}
private fun hasVisibleSinks(): Boolean {
synchronized(sinkVisibilityMap) {
return visibilities.any { it.isVisible() }
}
}
private fun largestVideoViewSize(): Dimensions {
var maxWidth = 0
var maxHeight = 0
synchronized(sinkVisibilityMap) {
visibilities.forEach { visibility ->
val size = visibility.size()
maxWidth = max(maxWidth, size.width)
maxHeight = max(maxHeight, size.height)
}
}
return Dimensions(maxWidth, maxHeight)
}
private fun recalculateVisibility() {
val isVisible = hasVisibleSinks()
val newDimensions = largestVideoViewSize()
var isVisible: Boolean
var newDimensions: Dimensions
synchronized(sinkVisibilityMap) {
isVisible = hasVisibleSinks()
newDimensions = largestVideoViewSize()
}
val eventsToPost = mutableListOf<TrackEvent>()
if (isVisible != lastVisibility) {
...
...
请
注册
或
登录
后发表评论