diff --git a/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/TccGeneratorNode.kt b/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/TccGeneratorNode.kt index 78f8facd9..2c8b48935 100644 --- a/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/TccGeneratorNode.kt +++ b/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/TccGeneratorNode.kt @@ -92,10 +92,11 @@ class TccGeneratorNode( private fun addPacket(tccSeqNum: Int, timestamp: Long, isMarked: Boolean, ssrc: Long) { synchronized(lock) { if (packetArrivalTimes.ceilingKey(windowStartSeq) == null) { - // Packets in map are all older than the start of the next tcc feedback packet, - // remove them - // TODO: Chrome does something more advanced, keeping older sequences to replay on packet reordering. - packetArrivalTimes.clear() + // Start new feedback packet, cull old packets. + packetArrivalTimes.entries.removeIf { + entry -> entry.key < tccSeqNum && + timestamp - entry.value >= BACK_WINDOW_MS + } } if (windowStartSeq == -1 || tccSeqNum < windowStartSeq) { windowStartSeq = tccSeqNum @@ -183,4 +184,10 @@ class TccGeneratorNode( addBoolean("enabled", enabled) } } + + companion object { + /** The number of milliseconds of old tcc reports to save */ + /** TODO: Chrome makes this a field trial param; do we need to make it configurable? */ + private val BACK_WINDOW_MS = 500 + } }