-
Notifications
You must be signed in to change notification settings - Fork 115
/
abscapturetimeextension_test.go
86 lines (80 loc) · 2.57 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtp
import (
"testing"
"time"
)
func TestAbsCaptureTimeExtension_Roundtrip(t *testing.T) {
t.Run("positive captureClockOffset", func(t *testing.T) {
t0 := time.Now()
e1 := NewAbsCaptureTimeExtension(t0)
b1, err1 := e1.Marshal()
if err1 != nil {
t.Fatal(err1)
}
var o1 AbsCaptureTimeExtension
if err := o1.Unmarshal(b1); err != nil {
t.Fatal(err)
}
dt1 := o1.CaptureTime().Sub(t0).Seconds()
if dt1 < -0.001 || dt1 > 0.001 {
t.Fatalf("timestamp differs, want %v got %v (dt=%f)", t0, o1.CaptureTime(), dt1)
}
if o1.EstimatedCaptureClockOffsetDuration() != nil {
t.Fatalf("duration differs, want nil got %d", o1.EstimatedCaptureClockOffsetDuration())
}
e2 := NewAbsCaptureTimeExtensionWithCaptureClockOffset(t0, 1250*time.Millisecond)
b2, err2 := e2.Marshal()
if err2 != nil {
t.Fatal(err2)
}
var o2 AbsCaptureTimeExtension
if err := o2.Unmarshal(b2); err != nil {
t.Fatal(err)
}
dt2 := o1.CaptureTime().Sub(t0).Seconds()
if dt2 < -0.001 || dt2 > 0.001 {
t.Fatalf("timestamp differs, want %v got %v (dt=%f)", t0, o2.CaptureTime(), dt2)
}
if *o2.EstimatedCaptureClockOffsetDuration() != 1250*time.Millisecond {
t.Fatalf("duration differs, want 250ms got %d", *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, err1 := e1.Marshal()
if err1 != nil {
t.Fatal(err1)
}
var o1 AbsCaptureTimeExtension
if err := o1.Unmarshal(b1); err != nil {
t.Fatal(err)
}
dt1 := o1.CaptureTime().Sub(t0).Seconds()
if dt1 < -0.001 || dt1 > 0.001 {
t.Fatalf("timestamp differs, want %v got %v (dt=%f)", t0, o1.CaptureTime(), dt1)
}
if o1.EstimatedCaptureClockOffsetDuration() != nil {
t.Fatalf("duration differs, want nil got %d", o1.EstimatedCaptureClockOffsetDuration())
}
e2 := NewAbsCaptureTimeExtensionWithCaptureClockOffset(t0, -250*time.Millisecond)
b2, err2 := e2.Marshal()
if err2 != nil {
t.Fatal(err2)
}
var o2 AbsCaptureTimeExtension
if err := o2.Unmarshal(b2); err != nil {
t.Fatal(err)
}
dt2 := o1.CaptureTime().Sub(t0).Seconds()
if dt2 < -0.001 || dt2 > 0.001 {
t.Fatalf("timestamp differs, want %v got %v (dt=%f)", t0, o2.CaptureTime(), dt2)
}
if *o2.EstimatedCaptureClockOffsetDuration() != -250*time.Millisecond {
t.Fatalf("duration differs, want -250ms got %v", *o2.EstimatedCaptureClockOffsetDuration())
}
})
}