Ignore lagging layer switches. (#1948)
This commit is contained in:
@@ -36,6 +36,9 @@ const (
|
||||
FirstSnapshotId = 1
|
||||
SnInfoSize = 8192
|
||||
SnInfoMask = SnInfoSize - 1
|
||||
|
||||
firstPacketTimeAdjustWindow = 2 * time.Minute
|
||||
firstPacketTimeAdjustThreshold = 5 * time.Second
|
||||
)
|
||||
|
||||
// -------------------------------------------------------
|
||||
@@ -763,6 +766,40 @@ func (r *RTPStats) GetRtt() uint32 {
|
||||
return r.rtt
|
||||
}
|
||||
|
||||
func (r *RTPStats) MaybeAdjustFirstPacketTime(srData *RTCPSenderReportData) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
r.maybeAdjustFirstPacketTime(srData.RTPTimestampExt)
|
||||
}
|
||||
|
||||
func (r *RTPStats) maybeAdjustFirstPacketTime(extTS uint64) {
|
||||
if time.Since(r.startTime) > firstPacketTimeAdjustWindow {
|
||||
return
|
||||
}
|
||||
|
||||
// for some time after the start, adjust time of first packet.
|
||||
// Helps improve accuracy of expected timestamp calculation.
|
||||
// Adjusting only one way, i. e. if the first sample experienced
|
||||
// abnormal delay (maybe due to pacing or maybe due to queuing
|
||||
// in some network element along the way), push back first time
|
||||
// to an earlier instance.
|
||||
samplesDuration := time.Duration(float64(extTS-r.extStartTS) / float64(r.params.ClockRate) * float64(time.Second))
|
||||
firstTime := time.Now().Add(-samplesDuration)
|
||||
if firstTime.Before(r.firstTime) {
|
||||
r.logger.Infow(
|
||||
"adjusting first packet time",
|
||||
"before", r.firstTime.String(),
|
||||
"after", firstTime.String(),
|
||||
)
|
||||
if r.firstTime.Sub(firstTime) > firstPacketTimeAdjustThreshold {
|
||||
r.logger.Infow("first packet time adjustment too big, ignoring", "adjustment", r.firstTime.Sub(firstTime))
|
||||
} else {
|
||||
r.firstTime = firstTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTPStats) SetRtcpSenderReportData(srData *RTCPSenderReportData) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
@@ -792,6 +829,8 @@ func (r *RTPStats) SetRtcpSenderReportData(srData *RTCPSenderReportData) {
|
||||
srDataCopy := *srData
|
||||
srDataCopy.RTPTimestampExt = uint64(srDataCopy.RTPTimestamp) + cycles
|
||||
|
||||
r.maybeAdjustFirstPacketTime(srDataCopy.RTPTimestampExt)
|
||||
|
||||
// monitor and log RTP timestamp anomalies
|
||||
var ntpDiffSinceLast time.Duration
|
||||
var rtpDiffSinceLast uint32
|
||||
|
||||
Reference in New Issue
Block a user