-
Notifications
You must be signed in to change notification settings - Fork 2
/
rtp-extention_test.go
142 lines (116 loc) · 3.2 KB
/
rtp-extention_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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package rtp
import (
"fmt"
"testing"
)
func TestGenExt(t *testing.T) {
if true {
p := NewRTPPacket([]byte{1, 2, 3, 4}, 8 /*pt*/, 22 /*seq*/, 33 /*ts*/, 44 /*ssrc*/)
//fmt.Printf( "pre ext packet %s \n", p.String() )
err := p.SetGeneralExt(9, []byte{0xA, 0xB, 0xC, 0xD})
if err != nil {
t.Errorf(err.Error())
}
//fmt.Printf( "post ext packet %s \n", p.String() )
err = p.SetPayload([]byte{200, 11, 12, 13})
if err != nil {
t.Errorf(err.Error())
}
fmt.Printf("TestGenExt packet %s \n", p.String())
if false {
ext1 := p.GetGeneralExt(1)
if ext1 != nil {
t.Errorf("Problem fetching missing general extention")
}
}
ext2 := p.GetGeneralExt(9)
if ext2 == nil {
t.Errorf("Problem general extention not found")
} else if len(ext2) != 4 {
t.Errorf("Problem general extention wrong length")
} else if ext2[1] != 0xB {
t.Errorf("Problem general extention wrong data")
}
payload := p.GetPayload()
if len(payload) != 4 {
t.Errorf("payload size is wrong")
} else {
if payload[0] != 200 {
t.Errorf("payload data is wrong")
}
}
}
}
func TestMultiGenExt(t *testing.T) {
if true {
p := NewRTPPacket([]byte{1, 2, 3, 4}, 8 /*pt*/, 22 /*seq*/, 33 /*ts*/, 44 /*ssrc*/)
//fmt.Printf( "pre ext packet %s \n", p.String() )
// example from section 4.2 of rfc5285
err := p.SetHdrExt(0xBEDE, []byte{0xA0, 0x1, 0xB1, 0x1, 0x2, 0, 0, 0xC3, 1, 2, 3, 4})
if err != nil {
t.Errorf(err.Error())
}
err = p.SetPayload([]byte{200, 11, 12, 13})
if err != nil {
t.Errorf(err.Error())
}
fmt.Printf("TestMultiGenExt packet %s \n", p.String())
fmt.Printf("TestMultiGenExt -------- \n")
ext := p.GetGeneralExt(1)
if ext != nil {
t.Errorf("Problem fetching missing general extention")
}
//fmt.Printf("TestMultiGenExt -------- \n")
ext = p.GetGeneralExt(0xA)
if ext == nil {
t.Errorf("Problem general extention not found")
} else if len(ext) != 1 {
t.Errorf("Problem general extention wrong length")
} else if ext[0] != 0x1 {
t.Errorf("Problem general extention wrong data")
}
//fmt.Printf("TestMultiGenExt -------- \n")
ext = p.GetGeneralExt(0xC)
if ext == nil {
t.Errorf("Problem general extention not found")
} else if len(ext) != 4 {
t.Errorf("Problem general extention wrong length")
} else if ext[3] != 0x4 {
t.Errorf("Problem general extention wrong data")
}
//fmt.Printf("TestMultiGenExt -------- \n")
payload := p.GetPayload()
if len(payload) != 4 {
t.Errorf("payload size is wrong")
} else {
if payload[0] != 200 {
t.Errorf("payload data is wrong")
}
}
}
}
func TestClientVolume(t *testing.T) {
if true {
s := NewRTPSession( true )
err := s.SetExtMap(11, "urn:ietf:params:rtp-hdrext:ssrc-audio-level")
if err != nil {
t.Errorf(err.Error())
}
p := NewRTPPacket([]byte{1, 2, 3, 4}, 8 /*pt*/, 22 /*seq*/, 33 /*ts*/, 44 /*ssrc*/)
err = p.SetExtClientVolume(s, true, -12)
if err != nil {
t.Errorf(err.Error())
}
err = p.SetPayload([]byte{200, 11, 12, 13})
if err != nil {
t.Errorf(err.Error())
}
vad, dBov := p.GetExtClientVolume(s)
if vad != true {
t.Errorf("Vad bit is wrong")
}
if dBov != -12 {
t.Errorf("dBov bit is wrong. Got %d", dBov)
}
}
}