Keep the earliest pending video cleanup retry instead of postponing it twice
This commit is contained in:
1 parent
d8fd73d917
commit
000273d451
1 file changed
+11
-3
@@ -28,7 +28,9 @@ internal class CallVideoPlayer(private val id: Long, private val failure: (Strin
|
||||
private var playout = 0L
|
||||
private val cleanupHandler = Handler(Looper.getMainLooper())
|
||||
private var cleanupDelay = 250L
|
||||
private var cleanupScheduled = false
|
||||
private val cleanupRetry = Runnable {
|
||||
synchronized(this) { cleanupScheduled = false }
|
||||
try { stop() } catch (e: Exception) { LogManager.addLog("WARN", "call", "video RX cleanup retry pending call=$id: $e") }
|
||||
}
|
||||
private data class Presentation(val surface: Surface, val pts: Long, val at: Long = 0)
|
||||
@@ -113,16 +115,22 @@ internal class CallVideoPlayer(private val id: Long, private val failure: (Strin
|
||||
}
|
||||
|
||||
private fun scheduleCleanup() {
|
||||
cleanupHandler.removeCallbacks(cleanupRetry)
|
||||
if (!worker.isAlive && decoder == null && playout == 0L && ownedOutputs.isEmpty()) {
|
||||
cleanupHandler.removeCallbacks(cleanupRetry); cleanupScheduled = false
|
||||
if (retained.remove(this)) LogManager.addLog("INFO", "call", "video RX cleanup confirmed call=$id")
|
||||
cleanupDelay = 250
|
||||
return
|
||||
}
|
||||
retained.add(this)
|
||||
val delay = cleanupDelay; cleanupDelay = (cleanupDelay * 2).coerceAtMost(30_000)
|
||||
if (!cleanupHandler.postDelayed(cleanupRetry, delay))
|
||||
if (cleanupScheduled) return
|
||||
val delay = cleanupDelay
|
||||
cleanupScheduled = cleanupHandler.postDelayed(cleanupRetry, delay)
|
||||
if (!cleanupScheduled) {
|
||||
LogManager.addLog("ERROR", "call", "video RX cleanup retry rejected call=$id; owner retained delayMs=$delay")
|
||||
} else {
|
||||
cleanupDelay = (cleanupDelay * 2).coerceAtMost(30_000)
|
||||
LogManager.addLog("DEBUG", "call", "video RX cleanup scheduled call=$id delayMs=$delay")
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportFailure(detail: String) {
|
||||
|
||||
Reference in new issue
Block a user