From 91520a36e0fe67256d9c1ff060f4944312494e6b Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Mon, 13 May 2024 15:11:28 +0530 Subject: [PATCH] Add a flag to pass through timestamp. (#2714) * Add a flag to psss through timestamp. Can make it a config later if needed. * log both adjusted and non-adjusted --- pkg/sfu/buffer/rtpstats_sender.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/sfu/buffer/rtpstats_sender.go b/pkg/sfu/buffer/rtpstats_sender.go index 6dafb104..6f32ac0a 100644 --- a/pkg/sfu/buffer/rtpstats_sender.go +++ b/pkg/sfu/buffer/rtpstats_sender.go @@ -31,6 +31,8 @@ const ( cSnInfoMask = cSnInfoSize - 1 cSenderReportInitialWait = time.Second + + cPassthroughNTPTimestamp = true ) // ------------------------------------------------------------------- @@ -645,10 +647,19 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *RTCPS return nil } - timeSincePublisherSR := time.Since(publisherSRData.AtAdjusted) - now := publisherSRData.AtAdjusted.Add(timeSincePublisherSR) - nowNTP := mediatransportutil.ToNtpTime(now) - nowRTPExt := publisherSRData.RTPTimestampExt - tsOffset + uint64(timeSincePublisherSR.Nanoseconds()*int64(r.params.ClockRate)/1e9) + timeSincePublisherSRAdjusted := time.Since(publisherSRData.AtAdjusted) + now := publisherSRData.AtAdjusted.Add(timeSincePublisherSRAdjusted) + var ( + nowNTP mediatransportutil.NtpTime + nowRTPExt uint64 + ) + if cPassthroughNTPTimestamp { + nowNTP = publisherSRData.NTPTimestamp + nowRTPExt = publisherSRData.RTPTimestampExt - tsOffset + } else { + nowNTP = mediatransportutil.ToNtpTime(now) + nowRTPExt = publisherSRData.RTPTimestampExt - tsOffset + uint64(timeSincePublisherSRAdjusted.Nanoseconds()*int64(r.params.ClockRate)/1e9) + } srData := &RTCPSenderReportData{ NTPTimestamp: nowNTP, @@ -666,13 +677,15 @@ func (r *RTPStatsSender) GetRtcpSenderReport(ssrc uint32, publisherSRData *RTCPS "feed", publisherSRData, "tsOffset", tsOffset, "timeNow", time.Now().String(), + "now", now.String(), "extStartTS", r.extStartTS, "extHighestTS", r.extHighestTS, "highestTime", r.highestTime.String(), "timeSinceHighest", now.Sub(r.highestTime).String(), "firstTime", r.firstTime.String(), "timeSinceFirst", now.Sub(r.firstTime).String(), - "timeSincePublisherSR", timeSincePublisherSR.String(), + "timeSincePublisherSRAdjusted", timeSincePublisherSRAdjusted.String(), + "timeSincePublisherSR", time.Since(publisherSRData.At).String(), "nowRTPExt", nowRTPExt, } }