forked from pion/rtcp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
full_intra_request_test.go
226 lines (218 loc) · 4.64 KB
/
full_intra_request_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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package rtcp
import (
"errors"
"reflect"
"testing"
)
func TestFullIntraRequestUnmarshal(t *testing.T) {
for _, test := range []struct {
Name string
Data []byte
Want FullIntraRequest
WantError error
}{
{
Name: "valid",
Data: []byte{
// v=2, p=0, FMT=4, PSFB, len=3
0x84, 0xce, 0x00, 0x03,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
// ssrc=0x12345678
0x12, 0x34, 0x56, 0x78,
// Seqno=0x42
0x42, 0x00, 0x00, 0x00,
},
Want: FullIntraRequest{
SenderSSRC: 0x0,
MediaSSRC: 0x4bc4fcb4,
FIR: []FIREntry{
{
SSRC: 0x12345678,
SequenceNumber: 0x42,
},
},
},
},
{
Name: "also valid",
Data: []byte{
// v=2, p=0, FMT=4, PSFB, len=3
0x84, 0xce, 0x00, 0x05,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
// ssrc=0x12345678
0x12, 0x34, 0x56, 0x78,
// Seqno=0x42
0x42, 0x00, 0x00, 0x00,
// ssrc=0x98765432
0x98, 0x76, 0x54, 0x32,
// Seqno=0x57
0x57, 0x00, 0x00, 0x00,
},
Want: FullIntraRequest{
SenderSSRC: 0x0,
MediaSSRC: 0x4bc4fcb4,
FIR: []FIREntry{
{
SSRC: 0x12345678,
SequenceNumber: 0x42,
},
{
SSRC: 0x98765432,
SequenceNumber: 0x57,
},
},
},
},
{
Name: "packet too short",
Data: []byte{
0x00, 0x00, 0x00, 0x00,
},
WantError: errPacketTooShort,
},
{
Name: "invalid header",
Data: []byte{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
WantError: errBadVersion,
},
{
Name: "wrong type",
Data: []byte{
// v=2, p=0, FMT=4, RR, len=3
0x84, 0xc9, 0x00, 0x03,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
// ssrc=0x12345678
0x12, 0x34, 0x56, 0x78,
// Seqno=0x42
0x42, 0x00, 0x00, 0x00,
},
WantError: errWrongType,
},
{
Name: "wrong fmt",
Data: []byte{
// v=2, p=0, FMT=2, PSFB, len=3
0x82, 0xce, 0x00, 0x03,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
// ssrc=0x12345678
0x12, 0x34, 0x56, 0x78,
// Seqno=0x42
0x42, 0x00, 0x00, 0x00,
},
WantError: errWrongType,
},
} {
var fir FullIntraRequest
err := fir.Unmarshal(test.Data)
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Unmarshal %q rr: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
if got, want := fir, test.Want; !reflect.DeepEqual(got, want) {
t.Fatalf("Unmarshal %q rr: got %v, want %v", test.Name, got, want)
}
}
}
func TestFullIntraRequestRoundTrip(t *testing.T) {
for _, test := range []struct {
Name string
Packet FullIntraRequest
WantError error
}{
{
Name: "valid",
Packet: FullIntraRequest{
SenderSSRC: 1,
MediaSSRC: 2,
FIR: []FIREntry{{
SSRC: 3,
SequenceNumber: 42,
}},
},
},
{
Name: "also valid",
Packet: FullIntraRequest{
SenderSSRC: 5000,
MediaSSRC: 6000,
FIR: []FIREntry{{
SSRC: 3,
SequenceNumber: 57,
}},
},
},
} {
data, err := test.Packet.Marshal()
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Marshal %q: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
var decoded FullIntraRequest
if err := decoded.Unmarshal(data); err != nil {
t.Fatalf("Unmarshal %q: %v", test.Name, err)
}
if got, want := decoded, test.Packet; !reflect.DeepEqual(got, want) {
t.Fatalf("%q rr round trip: got %#v, want %#v", test.Name, got, want)
}
}
}
func TestFullIntraRequestUnmarshalHeader(t *testing.T) {
for _, test := range []struct {
Name string
Data []byte
Want Header
WantError error
}{
{
Name: "valid header",
Data: []byte{
// v=2, p=0, FMT=1, PSFB, len=1
0x84, 0xce, 0x00, 0x02,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
0x00, 0x00, 0x00, 0x00,
},
Want: Header{
Count: FormatFIR,
Type: TypePayloadSpecificFeedback,
Length: 2,
},
},
} {
var fir FullIntraRequest
err := fir.Unmarshal(test.Data)
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Unmarshal header %q rr: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
if got, want := fir.Header(), test.Want; !reflect.DeepEqual(got, want) {
t.Fatalf("Unmarshal header %q rr: got %v, want %v", test.Name, got, want)
}
}
}