Skip to content

Commit 8ae891e

Browse files
committed
fix tests
1 parent 6bcde8d commit 8ae891e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pkg/synchronizer/synchronizer_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ func TestUnacceptableDrift_ResetsToEstimatedPTS(t *testing.T) {
124124

125125
func TestOnSenderReport_SlewsTowardDesiredOffset(t *testing.T) {
126126
const (
127-
maxAdjustment = 5 * time.Millisecond
127+
maxAdjustment = 2 * time.Millisecond // TrackSynchronizer's cMaxAdjustment
128128
ts0 = uint32(900_000)
129129
stepRTP = uint32(48000 * 20 / 1000) // 20 ms @ 48 kHz
130130
stepDur = 20 * time.Millisecond
131131
desired = 50 * time.Millisecond // target offset from SR
132132
)
133133

134-
s := synchronizer.NewSynchronizerWithOptions(synchronizer.WithMaxTsDiff(1 * time.Second))
134+
s := synchronizer.NewSynchronizerWithOptions(synchronizer.WithMaxTsDiff(5 * time.Second))
135135
tr := fakeAudio48k(0xA0010004)
136136

137137
tsync := s.AddTrack(tr, "p1")
@@ -155,13 +155,15 @@ func TestOnSenderReport_SlewsTowardDesiredOffset(t *testing.T) {
155155
RTPTime: cur,
156156
})
157157

158-
// Converge in N = ceil(desired / 5ms) steps (5ms maxAdjustment)
159-
N := int((desired + 5*time.Millisecond - 1) / (5 * time.Millisecond))
158+
// Converge in N = ceil(desired / 2ms) steps (2ms cMaxAdjustment) adjusted for throttling
159+
N := int((desired + maxAdjustment - 1) / (maxAdjustment))
160+
throttle := time.Duration(float64(maxAdjustment.Nanoseconds()) * 100.0 / 2.0)
160161

161162
for i := 0; i < N; i++ {
162163
cur += stepRTP
163164
_, err := tsync.GetPTS(pkt(cur))
164165
require.NoError(t, err)
166+
time.Sleep(throttle)
165167
}
166168

167169
// After N steps, total adjusted delta over base should be:
@@ -178,12 +180,13 @@ func TestOnSenderReport_SlewsTowardDesiredOffset(t *testing.T) {
178180
// Regression: late video start (~2s) + tiny SR offset (~10ms) must NOT emit a big negative drift
179181
func TestOnSenderReport_LateVideoStart_SmallSROffset_NoHugeNegativeDrift(t *testing.T) {
180182
const (
181-
lateStart = 2 * time.Second
182-
srOffset = 50 * time.Millisecond
183-
stepSlew = 5 * time.Millisecond // TrackSynchronizer's maxAdjustment
183+
lateStart = 2 * time.Second
184+
srOffset = 50 * time.Millisecond
185+
stepSlew = 2 * time.Millisecond // TrackSynchronizer's cMaxAdjustment
186+
adjustmentPercent = 2.0 // TrackSynchronizer's cAdjustmentWindowPercent
184187
)
185188

186-
s := synchronizer.NewSynchronizerWithOptions(synchronizer.WithMaxTsDiff(2 * time.Second))
189+
s := synchronizer.NewSynchronizerWithOptions(synchronizer.WithMaxTsDiff(5 * time.Second))
187190

188191
// 1) Audio publishes immediately → establishes startedAt
189192
audio := fakeAudio48k(0xA0010005)
@@ -222,8 +225,9 @@ func TestOnSenderReport_LateVideoStart_SmallSROffset_NoHugeNegativeDrift(t *test
222225
step33ms := uint32(90000 * 33 / 1000) // ~33 ms per 30fps frame at 90 kHz
223226
stepDur := 33 * time.Millisecond
224227

225-
// Converge in N = ceil(srOffset / stepSlew) steps (50ms / 5ms = 10)
228+
// Converge in N = ceil(srOffset / stepSlew) steps (50ms / 5ms = 10) adjusted for throttling
226229
N := int((srOffset + stepSlew - 1) / stepSlew)
230+
throttle := time.Duration(float64(stepSlew.Nanoseconds()) * 100.0 / adjustmentPercent)
227231

228232
cur := tsV0
229233
var adj time.Duration
@@ -233,6 +237,7 @@ func TestOnSenderReport_LateVideoStart_SmallSROffset_NoHugeNegativeDrift(t *test
233237
cur += step33ms
234238
adj, err = vSync.GetPTS(pkt(cur))
235239
require.NoError(t, err)
240+
time.Sleep(throttle)
236241
}
237242

238243
// After N steps, the extra beyond content cadence should be ~srOffset

pkg/synchronizer/track.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
const (
34-
cMaxAdjustment = 2 * time.Microsecond
34+
cMaxAdjustment = 2 * time.Millisecond
3535
// Throttle PTS adjustment to a limited amount ina time window.
3636
// This setting determines how long a certain amount of adjustment
3737
// throttles the next adjustment.

0 commit comments

Comments
 (0)