@@ -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
116115func 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