Skip to content

Commit ca8b662

Browse files
Remove WithPreJitterBufferReceiveTimeEnabled and always enable it (#843)
1 parent 176dbba commit ca8b662

2 files changed

Lines changed: 44 additions & 63 deletions

File tree

pkg/synchronizer/synchronizer.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ type SynchronizerOption func(*SynchronizerConfig)
3232

3333
// SynchronizerConfig holds configuration for the Synchronizer
3434
type SynchronizerConfig struct {
35-
MaxTsDiff time.Duration
36-
MaxDriftAdjustment time.Duration
37-
DriftAdjustmentWindowPercent float64
38-
AudioPTSAdjustmentDisabled bool
39-
PreJitterBufferReceiveTimeEnabled bool
40-
RTCPSenderReportRebaseEnabled bool
41-
OldPacketThreshold time.Duration
42-
EnableStartGate bool
35+
MaxTsDiff time.Duration
36+
MaxDriftAdjustment time.Duration
37+
DriftAdjustmentWindowPercent float64
38+
AudioPTSAdjustmentDisabled bool
39+
RTCPSenderReportRebaseEnabled bool
40+
OldPacketThreshold time.Duration
41+
EnableStartGate bool
4342

4443
OnStarted func()
4544

@@ -90,14 +89,6 @@ func WithAudioPTSAdjustmentDisabled() SynchronizerOption {
9089
}
9190
}
9291

93-
// WithPreJitterBufferReceiveTimeEnabled - enables use of packet arrival time before it is
94-
// added to the jitter buffer
95-
func WithPreJitterBufferReceiveTimeEnabled() SynchronizerOption {
96-
return func(config *SynchronizerConfig) {
97-
config.PreJitterBufferReceiveTimeEnabled = true
98-
}
99-
}
100-
10192
// WithRTCPSenderReportRebaseEnabled - enables rebasing RTCP Sender Report to local clock
10293
func WithRTCPSenderReportRebaseEnabled() SynchronizerOption {
10394
return func(config *SynchronizerConfig) {

pkg/synchronizer/track.go

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ type TrackSynchronizer struct {
6464
startGate startGate
6565

6666
// config
67-
maxTsDiff time.Duration // maximum acceptable difference between RTP packets
68-
maxDriftAdjustment time.Duration // maximum drift adjustment at a time
69-
driftAdjustmentWindowPercent float64
70-
audioPTSAdjustmentsDisabled bool // disable audio packets PTS adjustments on SRs
71-
preJitterBufferReceiveTimeEnabled bool
72-
rtcpSenderReportRebaseEnabled bool
73-
oldPacketThreshold time.Duration
74-
enableStartGate bool
67+
maxTsDiff time.Duration // maximum acceptable difference between RTP packets
68+
maxDriftAdjustment time.Duration // maximum drift adjustment at a time
69+
driftAdjustmentWindowPercent float64
70+
audioPTSAdjustmentsDisabled bool // disable audio packets PTS adjustments on SRs
71+
rtcpSenderReportRebaseEnabled bool
72+
oldPacketThreshold time.Duration
73+
enableStartGate bool
7574

7675
// timing info
7776
startTime time.Time // time at initialization --> this should be when first packet is received
@@ -115,22 +114,21 @@ type TrackSynchronizer struct {
115114

116115
func newTrackSynchronizer(s *Synchronizer, track TrackRemote) *TrackSynchronizer {
117116
t := &TrackSynchronizer{
118-
sync: s,
119-
track: track,
120-
logger: logger.GetLogger().WithValues("trackID", track.ID(), "codec", track.Codec().MimeType),
121-
RTPConverter: rtputil.NewRTPConverter(int64(track.Codec().ClockRate)),
122-
maxTsDiff: s.config.MaxTsDiff,
123-
maxDriftAdjustment: s.config.MaxDriftAdjustment,
124-
driftAdjustmentWindowPercent: s.config.DriftAdjustmentWindowPercent,
125-
audioPTSAdjustmentsDisabled: s.config.AudioPTSAdjustmentDisabled,
126-
preJitterBufferReceiveTimeEnabled: s.config.PreJitterBufferReceiveTimeEnabled,
127-
rtcpSenderReportRebaseEnabled: s.config.RTCPSenderReportRebaseEnabled,
128-
oldPacketThreshold: s.config.OldPacketThreshold,
129-
enableStartGate: s.config.EnableStartGate,
130-
nextPTSAdjustmentAt: time.Now(),
131-
propagationDelayEstimator: latency.NewOWDEstimator(latency.OWDEstimatorParamsDefault),
132-
maxMediaRunningTimeDelay: s.config.MaxMediaRunningTimeDelay,
133-
lastPTSAdjustedLogBucket: math.MaxInt64,
117+
sync: s,
118+
track: track,
119+
logger: logger.GetLogger().WithValues("trackID", track.ID(), "codec", track.Codec().MimeType),
120+
RTPConverter: rtputil.NewRTPConverter(int64(track.Codec().ClockRate)),
121+
maxTsDiff: s.config.MaxTsDiff,
122+
maxDriftAdjustment: s.config.MaxDriftAdjustment,
123+
driftAdjustmentWindowPercent: s.config.DriftAdjustmentWindowPercent,
124+
audioPTSAdjustmentsDisabled: s.config.AudioPTSAdjustmentDisabled,
125+
rtcpSenderReportRebaseEnabled: s.config.RTCPSenderReportRebaseEnabled,
126+
oldPacketThreshold: s.config.OldPacketThreshold,
127+
enableStartGate: s.config.EnableStartGate,
128+
nextPTSAdjustmentAt: time.Now(),
129+
propagationDelayEstimator: latency.NewOWDEstimator(latency.OWDEstimatorParamsDefault),
130+
maxMediaRunningTimeDelay: s.config.MaxMediaRunningTimeDelay,
131+
lastPTSAdjustedLogBucket: math.MaxInt64,
134132
}
135133

136134
if s.config.EnableStartGate {
@@ -223,7 +221,6 @@ func (t *TrackSynchronizer) initialize(extPkt jitter.ExtPacket) {
223221
"maxDriftAdjustment", t.maxDriftAdjustment,
224222
"driftAdjustmentWindowPercent", t.driftAdjustmentWindowPercent,
225223
"audioPTSAdjustmentDisabled", t.audioPTSAdjustmentsDisabled,
226-
"preJitterBufferReceiveTimeEnabled", t.preJitterBufferReceiveTimeEnabled,
227224
"rtcpSenderReportRebaseEnabled", t.rtcpSenderReportRebaseEnabled,
228225
"oldPacketThreshold", t.oldPacketThreshold,
229226
"enableStartGate", t.enableStartGate,
@@ -255,12 +252,7 @@ func (t *TrackSynchronizer) getPTSWithoutRebase(pkt jitter.ExtPacket) (time.Dura
255252
defer t.Unlock()
256253

257254
now := time.Now()
258-
var pktReceiveTime time.Time
259-
if t.preJitterBufferReceiveTimeEnabled {
260-
pktReceiveTime = pkt.ReceivedAt
261-
} else {
262-
pktReceiveTime = now
263-
}
255+
pktReceiveTime := pkt.ReceivedAt
264256
if t.firstTime.IsZero() {
265257
t.firstTime = now
266258
t.logger.Infow(
@@ -283,22 +275,20 @@ func (t *TrackSynchronizer) getPTSWithoutRebase(pkt jitter.ExtPacket) (time.Dura
283275
return t.lastPTSAdjusted, nil
284276
}
285277

286-
if t.preJitterBufferReceiveTimeEnabled {
287-
// if first packet a frame was too old and dropped,
288-
// drop all packets of the frame irrespective of whether they are old or not
289-
if ts == t.lastTSOldDropped || t.isPacketTooOld(pkt.ReceivedAt) {
290-
t.lastTSOldDropped = ts
291-
t.stats.numDroppedOld++
292-
t.logger.Infow(
293-
"dropping old packet",
294-
"currentTS", ts,
295-
"receivedAt", pkt.ReceivedAt,
296-
"now", time.Now(),
297-
"age", time.Since(pkt.ReceivedAt),
298-
"state", t,
299-
)
300-
return 0, ErrPacketTooOld
301-
}
278+
// if first packet a frame was too old and dropped,
279+
// drop all packets of the frame irrespective of whether they are old or not
280+
if ts == t.lastTSOldDropped || t.isPacketTooOld(pkt.ReceivedAt) {
281+
t.lastTSOldDropped = ts
282+
t.stats.numDroppedOld++
283+
t.logger.Infow(
284+
"dropping old packet",
285+
"currentTS", ts,
286+
"receivedAt", pkt.ReceivedAt,
287+
"now", time.Now(),
288+
"age", time.Since(pkt.ReceivedAt),
289+
"state", t,
290+
)
291+
return 0, ErrPacketTooOld
302292
}
303293

304294
estimatedPTS := pktReceiveTime.Sub(t.startTime)

0 commit comments

Comments
 (0)