Skip to content

Commit 1eede19

Browse files
authored
Fix start time adjustment logging (#757)
* Start time adjustment fixes * more log * fix logging * fix logging and remove quantised jumps * bring back quantised steps * comment
1 parent 84e4b7c commit 1eede19

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/synchronizer/track.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,14 @@ func (t *TrackSynchronizer) maybeAdjustStartTime(asr *augmentedSenderReport) int
638638
timeSinceStart := time.Duration(nowNano - startTimeNano)
639639
now := startTimeNano + timeSinceStart.Nanoseconds()
640640
adjustedStartTimeNano := now - samplesDuration.Nanoseconds()
641+
requestedAdjustment := startTimeNano - adjustedStartTimeNano
641642

642643
getLoggingFields := func() []interface{} {
643644
return []interface{}{
644645
"nowTime", time.Unix(0, now),
645-
"before", t.startTime,
646+
"before", time.Unix(0, startTimeNano),
646647
"after", time.Unix(0, adjustedStartTimeNano),
647-
"adjustment", time.Duration(startTimeNano - adjustedStartTimeNano),
648+
"requestedAdjustment", time.Duration(requestedAdjustment),
648649
"nowTS", nowTS,
649650
"timeSinceReceive", timeSinceReceive,
650651
"timeSinceStart", timeSinceStart,
@@ -656,18 +657,18 @@ func (t *TrackSynchronizer) maybeAdjustStartTime(asr *augmentedSenderReport) int
656657
}
657658

658659
if adjustedStartTimeNano < startTimeNano {
659-
if startTimeNano-adjustedStartTimeNano > cStartTimeAdjustThreshold.Nanoseconds() {
660+
if requestedAdjustment > cStartTimeAdjustThreshold.Nanoseconds() {
660661
t.logger.Warnw(
661662
"adjusting start time, too big, ignoring", nil,
662663
getLoggingFields()...,
663664
)
664665
} else {
665-
applied := t.applyQuantizedStartTimeAdvance(time.Duration(startTimeNano - adjustedStartTimeNano))
666-
t.logger.Infow("adjusting start time", append(getLoggingFields(), "applied", applied)...)
666+
applied := t.applyQuantizedStartTimeAdvance(time.Duration(requestedAdjustment))
667+
t.logger.Infow("adjusting start time", append(getLoggingFields(), "appliedAdjustment", applied)...)
667668
}
668669
}
669670

670-
return startTimeNano - adjustedStartTimeNano
671+
return requestedAdjustment
671672
}
672673

673674
func (t *TrackSynchronizer) acceptable(d time.Duration) bool {
@@ -696,6 +697,9 @@ func (t *TrackSynchronizer) isPacketTooOld(packetTime time.Time) bool {
696697
return t.oldPacketThreshold != 0 && mono.Now().Sub(packetTime) > t.oldPacketThreshold
697698
}
698699

700+
// avoid applying small changes to start time as it will cause subsequent PTSes
701+
// to have micro jumps potentially causing audible distortion,
702+
// the bet is more infrequent larger jumps is better than more frequent smaller jumps
699703
func (t *TrackSynchronizer) applyQuantizedStartTimeAdvance(deltaTotal time.Duration) time.Duration {
700704
// include any prior residual
701705
deltaTotal += t.startTimeAdjustResidual
@@ -738,6 +742,7 @@ func (t *TrackSynchronizer) MarshalLogObject(e zapcore.ObjectEncoder) error {
738742
e.AddTime("nextPTSAdjustmentAt", t.nextPTSAdjustmentAt)
739743
e.AddObject("propagationDelayEstimator", t.propagationDelayEstimator)
740744
e.AddDuration("totalStartTimeAdjustment", t.totalStartTimeAdjustment)
745+
e.AddDuration("startTimeAdjustResidual", t.startTimeAdjustResidual)
741746
e.AddUint32("numEmitted", t.numEmitted)
742747
e.AddUint32("numDroppedOld", t.numDroppedOld)
743748
e.AddUint32("numDroppedOutOfOrder", t.numDroppedOutOfOrder)

0 commit comments

Comments
 (0)