rtpstats: take mono nanoseconds in GetExpectedRTPTimestamp (#5008)

Callers passed mono.Now() as a time.Time, which made it easy to pass
time.Now() by mistake and mix clocks. Take mono nanoseconds instead.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-10-14 17:44:12 +05:30
committed by GitHub
co-authored by Claude Opus 5.5
parent 43291596c4
commit e357fdffb7
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -2014,7 +2014,7 @@ func (f *Forwarder) processSourceSwitch(extPkt *buffer.ExtPacket, layer int32) (
}
if f.rtpStats != nil {
tsExt, err := f.rtpStats.GetExpectedRTPTimestamp(switchingAt)
tsExt, err := f.rtpStats.GetExpectedRTPTimestamp(switchingAt.UnixNano())
if err == nil {
extExpectedTS = tsExt
if f.lastReferencePayloadType == -1 {
@@ -2453,7 +2453,7 @@ func (f *Forwarder) GetSnTsForBlankFrames(frameRate uint32, numPackets int) ([]S
extLastTS := f.rtpMunger.GetExtLastTimestamp()
extExpectedTS := extLastTS
if f.rtpStats != nil {
tsExt, err := f.rtpStats.GetExpectedRTPTimestamp(mono.Now())
tsExt, err := f.rtpStats.GetExpectedRTPTimestamp(mono.UnixNano())
if err == nil {
extExpectedTS = tsExt
}
+2 -2
View File
@@ -901,7 +901,7 @@ func (r *RTPStatsSender) MaybeAdjustFirstPacketTime(publisherSRData *livekit.RTC
}
}
func (r *RTPStatsSender) GetExpectedRTPTimestamp(at time.Time) (expectedTSExt uint64, err error) {
func (r *RTPStatsSender) GetExpectedRTPTimestamp(atNano int64) (expectedTSExt uint64, err error) {
r.lock.RLock()
defer r.lock.RUnlock()
@@ -910,7 +910,7 @@ func (r *RTPStatsSender) GetExpectedRTPTimestamp(at time.Time) (expectedTSExt ui
return
}
timeDiff := at.Sub(time.Unix(0, r.firstTime))
timeDiff := time.Duration(atNano - r.firstTime)
expectedTSExt = r.extStartTS + r.rtpConverter.ToRTPExt(timeDiff)
return
}