Debian Codegraph @

receiver_report_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcpscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/
5
6 import (
7 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
8
9 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/"
10 )
11
12 var _ Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet# = (*ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#)(nil) // assert is a Packet
13
14 func TestReceiverReportUnmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestReceiverReportUnmarshal().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
15 for _, test := range []struct {
16 Name string
17 Data []byte
18 Want ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#
19 WantError error
20 }{
21 {
22 Name: "valid",
23 Data: []byte{
24 // v=2, p=0, count=1, RR, len=7
25 0x81, 0xc9, 0x0, 0x7,
26 // ssrc=0x902f9e2e
27 0x90, 0x2f, 0x9e, 0x2e,
28 // ssrc=0xbc5e9a40
29 0xbc, 0x5e, 0x9a, 0x40,
30 // fracLost=0, totalLost=0
31 0x0, 0x0, 0x0, 0x0,
32 // lastSeq=0x46e1
33 0x0, 0x0, 0x46, 0xe1,
34 // jitter=273
35 0x0, 0x0, 0x1, 0x11,
36 // lsr=0x9f36432
37 0x9, 0xf3, 0x64, 0x32,
38 // delay=150137
39 0x0, 0x2, 0x4a, 0x79,
40 },
41 Want: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
42 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 0x902f9e2e,
43 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{{
44 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 0xbc5e9a40,
45 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 0,
46 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 0,
47 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 0x46e1,
48 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 273,
49 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 0x9f36432,
50 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 150137,
51 }},
52 ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions.: []byte{},
53 },
54 },
55 {
56 Name: "valid with extension data",
57 Data: []byte{
58 // v=2, p=0, count=1, RR, len=9
59 0x81, 0xc9, 0x0, 0x9,
60 // ssrc=0x902f9e2e
61 0x90, 0x2f, 0x9e, 0x2e,
62 // ssrc=0xbc5e9a40
63 0xbc, 0x5e, 0x9a, 0x40,
64 // fracLost=0, totalLost=0
65 0x0, 0x0, 0x0, 0x0,
66 // lastSeq=0x46e1
67 0x0, 0x0, 0x46, 0xe1,
68 // jitter=273
69 0x0, 0x0, 0x1, 0x11,
70 // lsr=0x9f36432
71 0x9, 0xf3, 0x64, 0x32,
72 // delay=150137
73 0x0, 0x2, 0x4a, 0x79,
74 // profile-specific extension data
75 0x54, 0x45, 0x53, 0x54,
76 0x44, 0x41, 0x54, 0x41,
77 },
78 Want: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
79 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 0x902f9e2e,
80 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{{
81 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 0xbc5e9a40,
82 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 0,
83 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 0,
84 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 0x46e1,
85 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 273,
86 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 0x9f36432,
87 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 150137,
88 }},
89 ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions.: []byte{
90 0x54, 0x45, 0x53, 0x54,
91 0x44, 0x41, 0x54, 0x41,
92 },
93 },
94 },
95 {
96 Name: "short report",
97 Data: []byte{
98 // v=2, p=0, count=1, RR, len=7
99 0x81, 0xc9, 0x00, 0x0c,
100 // ssrc=0x902f9e2e
101 0x90, 0x2f, 0x9e, 0x2e,
102 // fracLost=0, totalLost=0
103 0x00, 0x00, 0x00, 0x00,
104 // report ends early
105 },
106 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
107 },
108 {
109 Name: "wrong type",
110 Data: []byte{
111 // v=2, p=0, count=1, SR, len=7
112 0x81, 0xc8, 0x0, 0x7,
113 // ssrc=0x902f9e2e
114 0x90, 0x2f, 0x9e, 0x2e,
115 // ssrc=0xbc5e9a40
116 0xbc, 0x5e, 0x9a, 0x40,
117 // fracLost=0, totalLost=0
118 0x0, 0x0, 0x0, 0x0,
119 // lastSeq=0x46e1
120 0x0, 0x0, 0x46, 0xe1,
121 // jitter=273
122 0x0, 0x0, 0x1, 0x11,
123 // lsr=0x9f36432
124 0x9, 0xf3, 0x64, 0x32,
125 // delay=150137
126 0x0, 0x2, 0x4a, 0x79,
127 },
128 WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType.,
129 },
130 {
131 Name: "bad count in header",
132 Data: []byte{
133 // v=2, p=0, count=2, RR, len=7
134 0x82, 0xc9, 0x0, 0x7,
135 // ssrc=0x902f9e2e
136 0x90, 0x2f, 0x9e, 0x2e,
137 // ssrc=0xbc5e9a40
138 0xbc, 0x5e, 0x9a, 0x40,
139 // fracLost=0, totalLost=0
140 0x0, 0x0, 0x0, 0x0,
141 // lastSeq=0x46e1
142 0x0, 0x0, 0x46, 0xe1,
143 // jitter=273
144 0x0, 0x0, 0x1, 0x11,
145 // lsr=0x9f36432
146 0x9, 0xf3, 0x64, 0x32,
147 // delay=150137
148 0x0, 0x2, 0x4a, 0x79,
149 },
150 WantError: errInvalidHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errInvalidHeader.,
151 },
152 {
153 Name: "nil",
154 Data: nil,
155 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
156 },
157 } {
158 var rr ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#
159 err := rr.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Unmarshal().(test.Data)
160 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIsf().(t, err, test.WantError, "Unmarshal %q", test.Name)
161 if err != nil {
162 continue
163 }
164
165 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equalf().(t, test.Want, rr, "Unmarshal %q", test.Name)
166 }
167 }
168
169 func tooManyReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/tooManyReports().() []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport# {
170 // a slice with enough ReceptionReports to overflow an 5-bit int
171 var tooManyReports []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#
172 for range 1 << 5 {
173 tooManyReports = append(tooManyReports, ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{
174 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 2,
175 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 2,
176 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 3,
177 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 4,
178 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 5,
179 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 6,
180 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 7,
181 })
182 }
183
184 return tooManyReports
185 }
186
187 func TestReceiverReportRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestReceiverReportRoundTrip().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
188 for _, test := range []struct {
189 Name string
190 Report ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#
191 WantError error
192 }{
193 {
194 Name: "valid",
195 Report: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
196 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 1,
197 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{
198 {
199 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 2,
200 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 2,
201 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 3,
202 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 4,
203 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 5,
204 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 6,
205 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 7,
206 },
207 {
208 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 0,
209 },
210 },
211 ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions.: []byte{},
212 },
213 },
214 {
215 Name: "also valid",
216 Report: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
217 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 2,
218 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{
219 {
220 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 999,
221 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 30,
222 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 12345,
223 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 99,
224 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 22,
225 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 92,
226 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 46,
227 },
228 },
229 ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions.: []byte{},
230 },
231 },
232 {
233 Name: "totallost overflow",
234 Report: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
235 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 1,
236 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{{
237 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 1 << 25,
238 }},
239 },
240 WantError: errInvalidTotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errInvalidTotalLost.,
241 },
242 {
243 Name: "count overflow",
244 Report: ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
245 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 1,
246 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: tooManyReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/tooManyReports().(),
247 },
248 WantError: errTooManyReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errTooManyReports.,
249 },
250 } {
251 data, err := test.Report.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Marshal().()
252 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIsf().(t, err, test.WantError, "Marshal %q", test.Name)
253 if err != nil {
254 continue
255 }
256
257 var decoded ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#
258 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoErrorf().(t, decoded.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Unmarshal().(data), "Unmarshal %q", test.Name)
259 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equalf().(t, test.Report, decoded, "%s rr round trip mismatch", test.Name)
260 }
261 }
262
263 func TestReceiverReportUnmarshalMaxLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestReceiverReportUnmarshalMaxLength().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
264 rawPacket := make([]byte, 4*(0xFFFF+1))
265 rawPacket[0] = 0x80 | countMaxscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/countMax.
266 rawPacket[1] = 0xc9
267 rawPacket[2] = 0xff
268 rawPacket[3] = 0xff
269
270 var rr ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#
271 err := rr.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Unmarshal().(rawPacket)
272 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
273 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Len().(t, rr.Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports., countMaxscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/countMax.)
274 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Len().(t, rr.ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions., len(rawPacket)-rrReportOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/rrReportOffset.-countMaxscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/countMax.*receptionReportLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/receptionReportLength.)
275 }