mirror of
https://github.com/livekit/livekit.git
synced 2026-10-15 13:20:13 +00:00
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:
co-authored by
Claude Opus 5.5
parent
43291596c4
commit
e357fdffb7
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user