From 000273d451c6ad41f45d1dc53e04a702a97041a3 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 29 Oct 2026 00:26:05 +0100 Subject: [PATCH] Keep the earliest pending video cleanup retry instead of postponing it twice --- .../java/com/utun/chat/data/CallVideoPlayer.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/CallVideoPlayer.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/CallVideoPlayer.kt index fd005b0e..c52f0f1e 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/CallVideoPlayer.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/CallVideoPlayer.kt @@ -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) {