Fix large reported loss in RTPStats (#564)
Had to check for half the range to see if start needed to be moved back.
This commit is contained in:
+33
-27
@@ -192,29 +192,7 @@ func (r *RTPStats) Update(rtph *rtp.Header, payloadSize int, paddingSize int, pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adjust start to account for out-of-order packets before a cycle completes
|
// adjust start to account for out-of-order packets before a cycle completes
|
||||||
if !r.isCycleCompleted() && (rtph.SequenceNumber-uint16(r.extStartSN)) > (1<<15) {
|
r.maybeAdjustStartSN(rtph, packetTime)
|
||||||
// LK-DEBUG-REMOVE START
|
|
||||||
r.logger.Debugw(
|
|
||||||
"RTPSTATS_DEBUG moving starting SN back",
|
|
||||||
"diff", rtph.SequenceNumber-uint16(r.extStartSN),
|
|
||||||
"loss added", uint16(r.extStartSN)-rtph.SequenceNumber,
|
|
||||||
"highestSN", r.highestSN,
|
|
||||||
"sn", rtph.SequenceNumber,
|
|
||||||
"startSN", r.extStartSN,
|
|
||||||
"lost", r.packetsLost,
|
|
||||||
"highestTS", r.highestTS,
|
|
||||||
"ts", rtph.Timestamp,
|
|
||||||
"tsDiff", rtph.Timestamp-r.highestTS,
|
|
||||||
"highestTime", r.highestTime,
|
|
||||||
"now", packetTime,
|
|
||||||
"timeDiff(ms)", float64(packetTime-r.highestTime)/float64(1e6),
|
|
||||||
)
|
|
||||||
// LK-DEBUG-REMOVE END
|
|
||||||
// NOTE: current sequence number is counted as loss as it will be deducted in the duplicate check below
|
|
||||||
r.packetsLost += uint32(uint16(r.extStartSN) - rtph.SequenceNumber)
|
|
||||||
r.extStartSN = uint32(rtph.SequenceNumber)
|
|
||||||
r.logger.Debugw("RTPSTATS_DEBUG, setting extStartSN moving back", "extStartSN", r.extStartSN) // LK-DEBUG-REMOVE
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.isSeenSN(rtph.SequenceNumber) {
|
if r.isSeenSN(rtph.SequenceNumber) {
|
||||||
r.bytesDuplicate += pktSize
|
r.bytesDuplicate += pktSize
|
||||||
@@ -289,6 +267,38 @@ func (r *RTPStats) Update(rtph *rtp.Header, payloadSize int, paddingSize int, pa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *RTPStats) maybeAdjustStartSN(rtph *rtp.Header, packetTime int64) {
|
||||||
|
if (r.getExtHighestSN() - r.extStartSN + 1) >= (NumSequenceNumbers / 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rtph.SequenceNumber - uint16(r.extStartSN)) < (1 << 15) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// LK-DEBUG-REMOVE START
|
||||||
|
r.logger.Debugw(
|
||||||
|
"RTPSTATS_DEBUG moving starting SN back",
|
||||||
|
"diff", rtph.SequenceNumber-uint16(r.extStartSN),
|
||||||
|
"loss added", uint16(r.extStartSN)-rtph.SequenceNumber,
|
||||||
|
"highestSN", r.highestSN,
|
||||||
|
"sn", rtph.SequenceNumber,
|
||||||
|
"startSN", r.extStartSN,
|
||||||
|
"lost", r.packetsLost,
|
||||||
|
"highestTS", r.highestTS,
|
||||||
|
"ts", rtph.Timestamp,
|
||||||
|
"tsDiff", rtph.Timestamp-r.highestTS,
|
||||||
|
"highestTime", r.highestTime,
|
||||||
|
"now", packetTime,
|
||||||
|
"timeDiff(ms)", float64(packetTime-r.highestTime)/float64(1e6),
|
||||||
|
)
|
||||||
|
// LK-DEBUG-REMOVE END
|
||||||
|
// NOTE: current sequence number is counted as loss as it will be deducted in the duplicate check
|
||||||
|
r.packetsLost += uint32(uint16(r.extStartSN) - rtph.SequenceNumber)
|
||||||
|
r.extStartSN = uint32(rtph.SequenceNumber)
|
||||||
|
r.logger.Debugw("RTPSTATS_DEBUG, setting extStartSN moving back", "extStartSN", r.extStartSN) // LK-DEBUG-REMOVE
|
||||||
|
}
|
||||||
|
|
||||||
func (r *RTPStats) GetTotalPacketsPrimary() uint32 {
|
func (r *RTPStats) GetTotalPacketsPrimary() uint32 {
|
||||||
r.lock.RLock()
|
r.lock.RLock()
|
||||||
defer r.lock.RUnlock()
|
defer r.lock.RUnlock()
|
||||||
@@ -817,10 +827,6 @@ func (r *RTPStats) getExtHighestSN() uint32 {
|
|||||||
return (uint32(r.cycles) << 16) | uint32(r.highestSN)
|
return (uint32(r.cycles) << 16) | uint32(r.highestSN)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RTPStats) isCycleCompleted() bool {
|
|
||||||
return (r.getExtHighestSN() - r.extStartSN) >= NumSequenceNumbers
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RTPStats) getNumPacketsSeen() uint32 {
|
func (r *RTPStats) getNumPacketsSeen() uint32 {
|
||||||
packetsExpected := r.getExtHighestSN() - r.extStartSN + 1
|
packetsExpected := r.getExtHighestSN() - r.extStartSN + 1
|
||||||
if r.packetsLost > packetsExpected {
|
if r.packetsLost > packetsExpected {
|
||||||
|
|||||||
Reference in New Issue
Block a user