From 7ab6e5df092c7fefadda293ccfb7b3f62c4ea4e5 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 23 Oct 2024 11:03:43 +0530 Subject: [PATCH] Adjust drift calculations for pass through. (#3129) No functional effect, but was logging more than expected drift in the down stream direction. Reason is that when passing through, we could be using an older report. But, the adjustment was applied to the monotonic clock and not the RTP timestamp. So, it looked like more time had elapsed for the same RTP clock elapsed and logging higher than expected drift. Correcting it so that the log is not misleading/confusing. --- pkg/sfu/rtpstats/rtpstats_sender.go | 30 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/sfu/rtpstats/rtpstats_sender.go b/pkg/sfu/rtpstats/rtpstats_sender.go index c78e513e6..e4bb542b2 100644 --- a/pkg/sfu/rtpstats/rtpstats_sender.go +++ b/pkg/sfu/rtpstats/rtpstats_sender.go @@ -630,17 +630,24 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *livek return nil } - timeSincePublisherSRAdjusted := time.Since(time.Unix(0, publisherSRData.AtAdjusted)) - now := publisherSRData.AtAdjusted + timeSincePublisherSRAdjusted.Nanoseconds() var ( - nowNTP mediatransportutil.NtpTime - nowRTPExt uint64 + reportTime int64 + reportTimeAdjusted int64 + nowNTP mediatransportutil.NtpTime + nowRTPExt uint64 ) if passThrough { + reportTime = publisherSRData.At + reportTimeAdjusted = publisherSRData.AtAdjusted + nowNTP = mediatransportutil.NtpTime(publisherSRData.NtpTimestamp) nowRTPExt = publisherSRData.RtpTimestampExt - tsOffset } else { - nowNTP = mediatransportutil.ToNtpTime(time.Unix(0, now)) + timeSincePublisherSRAdjusted := time.Since(time.Unix(0, publisherSRData.AtAdjusted)) + reportTimeAdjusted = publisherSRData.AtAdjusted + timeSincePublisherSRAdjusted.Nanoseconds() + reportTime = reportTimeAdjusted + + nowNTP = mediatransportutil.ToNtpTime(time.Unix(0, reportTime)) nowRTPExt = publisherSRData.RtpTimestampExt - tsOffset + uint64(timeSincePublisherSRAdjusted.Nanoseconds()*int64(r.params.ClockRate)/1e9) } @@ -650,8 +657,8 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *livek NtpTimestamp: uint64(nowNTP), RtpTimestamp: uint32(nowRTPExt), RtpTimestampExt: nowRTPExt, - At: now, - AtAdjusted: now, + At: reportTime, + AtAdjusted: reportTimeAdjusted, Packets: packetCount, Octets: octetCount, } @@ -661,10 +668,11 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *livek "feed", WrappedRTCPSenderReportStateLogger{publisherSRData}, "tsOffset", tsOffset, "timeNow", time.Now(), - "now", time.Unix(0, now), - "timeSinceHighest", time.Duration(now-r.highestTime), - "timeSinceFirst", time.Duration(now-r.firstTime), - "timeSincePublisherSRAdjusted", timeSincePublisherSRAdjusted, + "reportTime", time.Unix(0, reportTime), + "reportTimeAdjusted", time.Unix(0, reportTimeAdjusted), + "timeSinceHighest", time.Since(time.Unix(0, r.highestTime)), + "timeSinceFirst", time.Since(time.Unix(0, r.firstTime)), + "timeSincePublisherSRAdjusted", time.Since(time.Unix(0, publisherSRData.AtAdjusted)), "timeSincePublisherSR", time.Since(time.Unix(0, publisherSRData.At)), "nowRTPExt", nowRTPExt, "rtpStats", lockedRTPStatsSenderLogEncoder{r},