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.
This commit is contained in:
Raja Subramanian
2024-10-23 11:03:43 +05:30
committed by GitHub
parent 487a3fc3fb
commit 7ab6e5df09
+19 -11
View File
@@ -630,17 +630,24 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *livek
return nil return nil
} }
timeSincePublisherSRAdjusted := time.Since(time.Unix(0, publisherSRData.AtAdjusted))
now := publisherSRData.AtAdjusted + timeSincePublisherSRAdjusted.Nanoseconds()
var ( var (
nowNTP mediatransportutil.NtpTime reportTime int64
nowRTPExt uint64 reportTimeAdjusted int64
nowNTP mediatransportutil.NtpTime
nowRTPExt uint64
) )
if passThrough { if passThrough {
reportTime = publisherSRData.At
reportTimeAdjusted = publisherSRData.AtAdjusted
nowNTP = mediatransportutil.NtpTime(publisherSRData.NtpTimestamp) nowNTP = mediatransportutil.NtpTime(publisherSRData.NtpTimestamp)
nowRTPExt = publisherSRData.RtpTimestampExt - tsOffset nowRTPExt = publisherSRData.RtpTimestampExt - tsOffset
} else { } 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) 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), NtpTimestamp: uint64(nowNTP),
RtpTimestamp: uint32(nowRTPExt), RtpTimestamp: uint32(nowRTPExt),
RtpTimestampExt: nowRTPExt, RtpTimestampExt: nowRTPExt,
At: now, At: reportTime,
AtAdjusted: now, AtAdjusted: reportTimeAdjusted,
Packets: packetCount, Packets: packetCount,
Octets: octetCount, Octets: octetCount,
} }
@@ -661,10 +668,11 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *livek
"feed", WrappedRTCPSenderReportStateLogger{publisherSRData}, "feed", WrappedRTCPSenderReportStateLogger{publisherSRData},
"tsOffset", tsOffset, "tsOffset", tsOffset,
"timeNow", time.Now(), "timeNow", time.Now(),
"now", time.Unix(0, now), "reportTime", time.Unix(0, reportTime),
"timeSinceHighest", time.Duration(now-r.highestTime), "reportTimeAdjusted", time.Unix(0, reportTimeAdjusted),
"timeSinceFirst", time.Duration(now-r.firstTime), "timeSinceHighest", time.Since(time.Unix(0, r.highestTime)),
"timeSincePublisherSRAdjusted", timeSincePublisherSRAdjusted, "timeSinceFirst", time.Since(time.Unix(0, r.firstTime)),
"timeSincePublisherSRAdjusted", time.Since(time.Unix(0, publisherSRData.AtAdjusted)),
"timeSincePublisherSR", time.Since(time.Unix(0, publisherSRData.At)), "timeSincePublisherSR", time.Since(time.Unix(0, publisherSRData.At)),
"nowRTPExt", nowRTPExt, "nowRTPExt", nowRTPExt,
"rtpStats", lockedRTPStatsSenderLogEncoder{r}, "rtpStats", lockedRTPStatsSenderLogEncoder{r},