Ignore out-of-order receiver side sender reports. (#2567)
This commit is contained in:
@@ -276,16 +276,14 @@ func (r *RTPStatsReceiver) SetRtcpSenderReportData(srData *RTCPSenderReportData)
|
|||||||
srDataCopy := *srData
|
srDataCopy := *srData
|
||||||
srDataCopy.RTPTimestampExt = uint64(srDataCopy.RTPTimestamp) + tsCycles
|
srDataCopy.RTPTimestampExt = uint64(srDataCopy.RTPTimestamp) + tsCycles
|
||||||
|
|
||||||
r.maybeAdjustFirstPacketTime(srDataCopy.RTPTimestamp, r.timestamp.GetStart())
|
|
||||||
|
|
||||||
if r.srNewest != nil && srDataCopy.RTPTimestampExt < r.srNewest.RTPTimestampExt {
|
if r.srNewest != nil && srDataCopy.RTPTimestampExt < r.srNewest.RTPTimestampExt {
|
||||||
// This can happen when a track is replaced with a null and then restored -
|
// This can happen when a track is replaced with a null and then restored -
|
||||||
// i. e. muting replacing with null and unmute restoring the original track.
|
// i. e. muting replacing with null and unmute restoring the original track.
|
||||||
// Under such a condition reset the sender reports to start from this point.
|
// Or it could be due bad report generation.
|
||||||
// Resetting will ensure sample rate calculations do not go haywire due to negative time.
|
// In any case, ignore out-of-order reports.
|
||||||
if r.outOfOrderSsenderReportCount%10 == 0 {
|
if r.outOfOrderSsenderReportCount%10 == 0 {
|
||||||
r.logger.Infow(
|
r.logger.Infow(
|
||||||
"received sender report, out-of-order, resetting",
|
"received sender report, out-of-order, skipping",
|
||||||
"first", r.srFirst,
|
"first", r.srFirst,
|
||||||
"last", r.srNewest,
|
"last", r.srNewest,
|
||||||
"current", &srDataCopy,
|
"current", &srDataCopy,
|
||||||
@@ -293,11 +291,11 @@ func (r *RTPStatsReceiver) SetRtcpSenderReportData(srData *RTCPSenderReportData)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
r.outOfOrderSsenderReportCount++
|
r.outOfOrderSsenderReportCount++
|
||||||
|
return
|
||||||
r.srFirst = nil
|
|
||||||
r.srNewest = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.maybeAdjustFirstPacketTime(srDataCopy.RTPTimestamp, r.timestamp.GetStart())
|
||||||
|
|
||||||
if r.srNewest != nil {
|
if r.srNewest != nil {
|
||||||
timeSinceLast := srData.NTPTimestamp.Time().Sub(r.srNewest.NTPTimestamp.Time()).Seconds()
|
timeSinceLast := srData.NTPTimestamp.Time().Sub(r.srNewest.NTPTimestamp.Time()).Seconds()
|
||||||
rtpDiffSinceLast := srDataCopy.RTPTimestampExt - r.srNewest.RTPTimestampExt
|
rtpDiffSinceLast := srDataCopy.RTPTimestampExt - r.srNewest.RTPTimestampExt
|
||||||
|
|||||||
@@ -665,16 +665,21 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, calculatedClockRate ui
|
|||||||
nowRTPExtUsingTime := r.extStartTS + uint64(timeSinceFirst.Nanoseconds()*int64(r.params.ClockRate)/1e9)
|
nowRTPExtUsingTime := r.extStartTS + uint64(timeSinceFirst.Nanoseconds()*int64(r.params.ClockRate)/1e9)
|
||||||
nowRTPExt := nowRTPExtUsingTime
|
nowRTPExt := nowRTPExtUsingTime
|
||||||
|
|
||||||
// It is possible that publisher is pacing at a slower rate.
|
/*
|
||||||
// That would make `highestTS` to be lagging the RTP time stamp in the RTCP Sender Report from publisher.
|
// TODO: Bad reports or unpaced publishing contorts the calculated clock rate a lot resulting in
|
||||||
// Check for that using calculated clock rate and use the later time stamp if applicable.
|
// subsscriber sender reports jumping around. Needs more thinking.
|
||||||
var nowRTPExtUsingRate uint64
|
//
|
||||||
if calculatedClockRate != 0 {
|
// It is possible that publisher is pacing at a slower rate.
|
||||||
nowRTPExtUsingRate = r.extStartTS + uint64(float64(calculatedClockRate)*timeSinceFirst.Seconds())
|
// That would make `highestTS` to be lagging the RTP time stamp in the RTCP Sender Report from publisher.
|
||||||
if nowRTPExtUsingRate > nowRTPExt {
|
// Check for that using calculated clock rate and use the later time stamp if applicable.
|
||||||
nowRTPExt = nowRTPExtUsingRate
|
var nowRTPExtUsingRate uint64
|
||||||
|
if calculatedClockRate != 0 {
|
||||||
|
nowRTPExtUsingRate = r.extStartTS + uint64(float64(calculatedClockRate)*timeSinceFirst.Seconds())
|
||||||
|
if nowRTPExtUsingRate > nowRTPExt {
|
||||||
|
nowRTPExt = nowRTPExtUsingRate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
srData := &RTCPSenderReportData{
|
srData := &RTCPSenderReportData{
|
||||||
NTPTimestamp: nowNTP,
|
NTPTimestamp: nowNTP,
|
||||||
@@ -704,7 +709,7 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, calculatedClockRate ui
|
|||||||
"timeSinceFirst", timeSinceFirst.String(),
|
"timeSinceFirst", timeSinceFirst.String(),
|
||||||
"nowRTPExtUsingTime", nowRTPExtUsingTime,
|
"nowRTPExtUsingTime", nowRTPExtUsingTime,
|
||||||
"calculatedClockRate", calculatedClockRate,
|
"calculatedClockRate", calculatedClockRate,
|
||||||
"nowRTPExtUsingRate", nowRTPExtUsingRate,
|
// TODO "nowRTPExtUsingRate", nowRTPExtUsingRate,
|
||||||
"timeSinceLastReport", timeSinceLastReport.String(),
|
"timeSinceLastReport", timeSinceLastReport.String(),
|
||||||
"rtpDiffSinceLastReport", rtpDiffSinceLastReport,
|
"rtpDiffSinceLastReport", rtpDiffSinceLastReport,
|
||||||
"windowClockRate", windowClockRate,
|
"windowClockRate", windowClockRate,
|
||||||
@@ -734,7 +739,7 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, calculatedClockRate ui
|
|||||||
"timeSinceFirst", timeSinceFirst.String(),
|
"timeSinceFirst", timeSinceFirst.String(),
|
||||||
"nowRTPExtUsingTime", nowRTPExtUsingTime,
|
"nowRTPExtUsingTime", nowRTPExtUsingTime,
|
||||||
"calculatedClockRate", calculatedClockRate,
|
"calculatedClockRate", calculatedClockRate,
|
||||||
"nowRTPExtUsingRate", nowRTPExtUsingRate,
|
// TODO "nowRTPExtUsingRate", nowRTPExtUsingRate,
|
||||||
)
|
)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user