-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathabscapturetimeextension_test.go
61 lines (53 loc) · 1.93 KB
/
abscapturetimeextension_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtp
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAbsCaptureTimeExtension_Roundtrip(t *testing.T) { //nolint:cyclop
t.Run("positive captureClockOffset", func(t *testing.T) {
t0 := time.Now()
e1 := NewAbsCaptureTimeExtension(t0)
b1, err := e1.Marshal()
assert.NoError(t, err)
var o1 AbsCaptureTimeExtension
assert.NoError(t, o1.Unmarshal(b1))
dt1 := o1.CaptureTime().Sub(t0).Seconds()
assert.GreaterOrEqual(t, dt1, -0.001)
assert.LessOrEqual(t, dt1, 0.001)
assert.Nil(t, o1.EstimatedCaptureClockOffsetDuration())
e2 := NewAbsCaptureTimeExtensionWithCaptureClockOffset(t0, 1250*time.Millisecond)
b2, err := e2.Marshal()
assert.NoError(t, err)
var o2 AbsCaptureTimeExtension
assert.NoError(t, o2.Unmarshal(b2))
dt2 := o1.CaptureTime().Sub(t0).Seconds()
assert.GreaterOrEqual(t, dt2, -0.001)
assert.LessOrEqual(t, dt2, 0.001)
assert.Equal(t, 1250*time.Millisecond, *o2.EstimatedCaptureClockOffsetDuration())
})
// This test can verify the for for the issue 247
t.Run("negative captureClockOffset", func(t *testing.T) {
t0 := time.Now()
e1 := NewAbsCaptureTimeExtension(t0)
b1, err := e1.Marshal()
assert.NoError(t, err)
var o1 AbsCaptureTimeExtension
assert.NoError(t, o1.Unmarshal(b1))
dt1 := o1.CaptureTime().Sub(t0).Seconds()
assert.GreaterOrEqual(t, dt1, -0.001)
assert.LessOrEqual(t, dt1, 0.001)
assert.Nil(t, o1.EstimatedCaptureClockOffsetDuration())
e2 := NewAbsCaptureTimeExtensionWithCaptureClockOffset(t0, -250*time.Millisecond)
b2, err := e2.Marshal()
assert.NoError(t, err)
var o2 AbsCaptureTimeExtension
assert.NoError(t, o2.Unmarshal(b2))
dt2 := o1.CaptureTime().Sub(t0).Seconds()
assert.GreaterOrEqual(t, dt2, -0.001)
assert.LessOrEqual(t, dt2, 0.001)
assert.Equal(t, -250*time.Millisecond, *o2.EstimatedCaptureClockOffsetDuration())
})
}