Switch to rate since first time. (#1704)

With short term measurements, the adjustment itself was causing
some oscillations and drift tend to settle at some small value
and oscillated around it due to push/pull affecting small window
measurement.
This commit is contained in:
Raja Subramanian
2023-05-10 11:01:51 +05:30
committed by GitHub
parent 678cd06241
commit 4419cd56b8
+8 -16
View File
@@ -177,7 +177,6 @@ type RTPStats struct {
srData *RTCPSenderReportData srData *RTCPSenderReportData
lastSRTime time.Time lastSRTime time.Time
lastSRNTP mediatransportutil.NtpTime lastSRNTP mediatransportutil.NtpTime
lastSRRTP uint32
pidController *PIDController pidController *PIDController
nextSnapshotId uint32 nextSnapshotId uint32
@@ -287,7 +286,6 @@ func (r *RTPStats) Seed(from *RTPStats) {
} }
r.lastSRTime = from.lastSRTime r.lastSRTime = from.lastSRTime
r.lastSRNTP = from.lastSRNTP r.lastSRNTP = from.lastSRNTP
r.lastSRRTP = from.lastSRRTP
r.nextSnapshotId = from.nextSnapshotId r.nextSnapshotId = from.nextSnapshotId
for id, ss := range from.snapshots { for id, ss := range from.snapshots {
@@ -848,17 +846,13 @@ func (r *RTPStats) GetRtcpSenderReport(ssrc uint32) (*rtcp.SenderReport, float64
nowRTP := r.highestTS + uint32(timeSinceHighest.Nanoseconds()*int64(r.params.ClockRate)/1e9) nowRTP := r.highestTS + uint32(timeSinceHighest.Nanoseconds()*int64(r.params.ClockRate)/1e9)
// TODO-REMOVE-AFTER-DEBUG-START // TODO-REMOVE-AFTER-DEBUG-START
pidOutput := float64(0.0) rtpDiffSinceFirst := getExtTS(nowRTP, r.tsCycles) - r.extStartTS
if !r.lastSRTime.IsZero() { rate := float64(rtpDiffSinceFirst) / timeSinceFirst.Seconds()
timeSinceLast := now.Sub(r.lastSRTime) pidOutput := r.pidController.Update(
rtpDiffSinceLast := nowRTP - r.lastSRRTP float64(r.params.ClockRate),
rate := float64(rtpDiffSinceLast) / timeSinceLast.Seconds() rate,
pidOutput = r.pidController.Update( now,
float64(r.params.ClockRate), )
rate,
now,
)
}
// TODO-REMOVE-AFTER-DEBUG-STOP // TODO-REMOVE-AFTER-DEBUG-STOP
// TODO-REMOVE-AFTER-DEBUG-START // TODO-REMOVE-AFTER-DEBUG-START
@@ -868,7 +862,6 @@ func (r *RTPStats) GetRtcpSenderReport(ssrc uint32) (*rtcp.SenderReport, float64
rtpDiffLocal := int32(nowRTP - r.highestTS) rtpDiffLocal := int32(nowRTP - r.highestTS)
rtpOffsetLocal := int32(nowRTP - r.highestTS - uint32(ntpDiffLocal.Nanoseconds()*int64(r.params.ClockRate)/1e9)) rtpOffsetLocal := int32(nowRTP - r.highestTS - uint32(ntpDiffLocal.Nanoseconds()*int64(r.params.ClockRate)/1e9))
rtpDiffSinceFirst := getExtTS(nowRTP, r.tsCycles) - r.extStartTS
drift := int64(rtpDiffSinceFirst - uint64(timeSinceFirst.Nanoseconds()*int64(r.params.ClockRate)/1e9)) drift := int64(rtpDiffSinceFirst - uint64(timeSinceFirst.Nanoseconds()*int64(r.params.ClockRate)/1e9))
driftMs := (float64(drift) * 1000) / float64(r.params.ClockRate) driftMs := (float64(drift) * 1000) / float64(r.params.ClockRate)
r.logger.Debugw( r.logger.Debugw(
@@ -885,13 +878,12 @@ func (r *RTPStats) GetRtcpSenderReport(ssrc uint32) (*rtcp.SenderReport, float64
"rtpDiffSinceFirst", rtpDiffSinceFirst, "rtpDiffSinceFirst", rtpDiffSinceFirst,
"drift", drift, "drift", drift,
"driftMs", driftMs, "driftMs", driftMs,
"rate", float64(rtpDiffSinceFirst)/timeSinceFirst.Seconds(), "rate", rate,
) )
// TODO-REMOVE-AFTER-DEBUG-END // TODO-REMOVE-AFTER-DEBUG-END
r.lastSRTime = now r.lastSRTime = now
r.lastSRNTP = nowNTP r.lastSRNTP = nowNTP
r.lastSRRTP = nowRTP
return &rtcp.SenderReport{ return &rtcp.SenderReport{
SSRC: ssrc, SSRC: ssrc,