Consistently undo update to sequence number and timestamp when the (#4156)

incoming packet cannot be sequenced.
This commit is contained in:
Raja Subramanian
2025-12-13 15:46:04 +05:30
committed by GitHub
parent 2317c29531
commit 97aba5e77b
3 changed files with 22 additions and 13 deletions
+19 -10
View File
@@ -171,6 +171,11 @@ func (r *RTPStatsReceiver) Update(
)
}
undoUpdates := func() {
r.sequenceNumber.UndoUpdate(resSN)
r.timestamp.UndoUpdate(resTS)
}
if !r.initialized {
if payloadSize == 0 {
// do not start on a padding only packet
@@ -208,6 +213,8 @@ func (r *RTPStatsReceiver) Update(
}
resTS = r.timestamp.Rollover(timestamp, tsRolloverCount)
if resTS.IsUnhandled {
undoUpdates()
flowState.IsNotHandled = true
return
}
@@ -226,9 +233,10 @@ func (r *RTPStatsReceiver) Update(
if gapSN < 0 && gapTS > 0 {
expectedTSJump = int64(r.rtpConverter.ToRTPExt(time.Duration(timeSinceHighest)))
if gapTS > int64(float64(expectedTSJump)*cTSJumpTooHighFactor) {
r.sequenceNumber.UndoUpdate(resSN)
r.timestamp.UndoUpdate(resTS)
undoUpdates()
logger().Warnw("dropping old packet, timestamp", nil)
flowState.IsNotHandled = true
return
}
@@ -237,9 +245,10 @@ func (r *RTPStatsReceiver) Update(
// Case 2:
// Sequence number looks like it is moving forward, but it is actually a very old packet.
if gapTS < 0 && gapSN > 0 {
r.sequenceNumber.UndoUpdate(resSN)
r.timestamp.UndoUpdate(resTS)
undoUpdates()
logger().Warnw("dropping old packet, sequence number", nil)
flowState.IsNotHandled = true
return
}
@@ -253,17 +262,17 @@ func (r *RTPStatsReceiver) Update(
snRolloverCount = 1
}
resSN = r.sequenceNumber.Rollover(sequenceNumber, snRolloverCount)
if resSN.IsUnhandled {
flowState.IsNotHandled = true
return
if !resSN.IsUnhandled {
logger().Warnw("forcing sequence number rollover", nil)
}
logger().Warnw("forcing sequence number rollover", nil)
}
if resSN.IsUnhandled {
flowState.IsNotHandled = true
undoUpdates()
logger().Warnw("dropping packet, cannot find sequence", nil)
flowState.IsNotHandled = true
return
}
}