Use monotonic clock in packet path. (#2940)
Set up a base time when starting a receiver and use that clock as base for other packet times to ensure that clock is monotonic.
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
@@ -139,6 +140,8 @@ type DummyReceiver struct {
|
||||
maxExpectedLayer int32
|
||||
pausedValid bool
|
||||
paused bool
|
||||
|
||||
baseTime time.Time
|
||||
}
|
||||
|
||||
func NewDummyReceiver(trackID livekit.TrackID, streamId string, codec webrtc.RTPCodecParameters, headerExtensions []webrtc.RTPHeaderExtensionParameter) *DummyReceiver {
|
||||
@@ -148,6 +151,7 @@ func NewDummyReceiver(trackID livekit.TrackID, streamId string, codec webrtc.RTP
|
||||
codec: codec,
|
||||
headerExtensions: headerExtensions,
|
||||
downTracks: make(map[livekit.ParticipantID]sfu.TrackSender),
|
||||
baseTime: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,3 +328,10 @@ func (d *DummyReceiver) GetTrackStats() *livekit.RTPStats {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DummyReceiver) GetMonotonicNowUnixNano() int64 {
|
||||
if r, ok := d.receiver.Load().(sfu.TrackReceiver); ok {
|
||||
return r.GetMonotonicNowUnixNano()
|
||||
}
|
||||
return d.baseTime.Add(time.Since(d.baseTime)).UnixNano()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user