Debian Codegraph @

packet_stringifier_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcp
5
6 import (
7 "testing"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 //nolint:maintidx
13 func TestPrint(t *testing.T) {
14 type Tests struct {
15 packet Packet
16 expected string
17 }
18
19 tests := []Tests{
20 {
21 &ExtendedReport{
22 SenderSSRC: 0x01020304,
23 Reports: []ReportBlock{
24 &LossRLEReportBlock{
25 XRHeader: XRHeader{
26 BlockType: LossRLEReportBlockType,
27 },
28 SSRC: 0x12345689,
29 BeginSeq: 5,
30 EndSeq: 12,
31 Chunks: []Chunk{
32 Chunk(0x4006),
33 Chunk(0x0006),
34 Chunk(0x8765),
35 Chunk(0x0000),
36 },
37 },
38 &DuplicateRLEReportBlock{
39 XRHeader: XRHeader{
40 BlockType: DuplicateRLEReportBlockType,
41 },
42 SSRC: 0x12345689,
43 BeginSeq: 5,
44 EndSeq: 12,
45 Chunks: []Chunk{
46 Chunk(0x4123),
47 Chunk(0x3FFF),
48 Chunk(0xFFFF),
49 Chunk(0x0000),
50 },
51 },
52 &PacketReceiptTimesReportBlock{
53 XRHeader: XRHeader{
54 BlockType: PacketReceiptTimesReportBlockType,
55 },
56 SSRC: 0x98765432,
57 BeginSeq: 15432,
58 EndSeq: 15577,
59 ReceiptTime: []uint32{
60 0x11111111,
61 0x22222222,
62 0x33333333,
63 0x44444444,
64 0x55555555,
65 },
66 },
67 &ReceiverReferenceTimeReportBlock{
68 XRHeader: XRHeader{
69 BlockType: ReceiverReferenceTimeReportBlockType,
70 },
71 NTPTimestamp: 0x0102030405060708,
72 },
73 &DLRRReportBlock{
74 XRHeader: XRHeader{
75 BlockType: DLRRReportBlockType,
76 },
77 Reports: []DLRRReport{
78 {
79 SSRC: 0x88888888,
80 LastRR: 0x12345678,
81 DLRR: 0x99999999,
82 },
83 {
84 SSRC: 0x09090909,
85 LastRR: 0x12345678,
86 DLRR: 0x99999999,
87 },
88 {
89 SSRC: 0x11223344,
90 LastRR: 0x12345678,
91 DLRR: 0x99999999,
92 },
93 },
94 },
95 &StatisticsSummaryReportBlock{
96 XRHeader{
97 BlockType: StatisticsSummaryReportBlockType,
98 },
99 true, true, true, ToHIPv4,
100 0xFEDCBA98,
101 0x1234, 0x5678,
102 0x11111111,
103 0x22222222,
104 0x33333333,
105 0x44444444,
106 0x55555555,
107 0x66666666,
108 0x01, 0x02, 0x03, 0x04,
109 },
110 &VoIPMetricsReportBlock{
111 XRHeader{
112 BlockType: VoIPMetricsReportBlockType,
113 },
114 0x89ABCDEF,
115 0x05, 0x06, 0x07, 0x08,
116 0x1111, 0x2222, 0x3333, 0x4444,
117 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
118 0x00,
119 0x1122, 0x3344, 0x5566,
120 },
121 },
122 },
123 // nolint
124 "rtcp.ExtendedReport:\n" +
125 "\tSenderSSRC: 0x1020304\n" +
126 "\tReports:\n" +
127 "\t\t0 (rtcp.LossRLEReportBlock):\n" +
128 "\t\t\tXRHeader:\n" +
129 "\t\t\t\tBlockType: [LossRLEReportBlockType]\n" +
130 "\t\t\t\tTypeSpecific: 0x0\n" +
131 "\t\t\t\tBlockLength: 0\n" +
132 "\t\t\tT: 0\n" +
133 "\t\t\tSSRC: 0x12345689\n" +
134 "\t\t\tBeginSeq: 5\n" +
135 "\t\t\tEndSeq: 12\n" +
136 "\t\t\tChunks:\n" +
137 "\t\t\t\t0: [[RunLength type=1, length=6]]\n" +
138 "\t\t\t\t1: [[RunLength type=0, length=6]]\n" +
139 "\t\t\t\t2: [[BitVector 0b000011101100101]]\n" +
140 "\t\t\t\t3: [[TerminatingNull]]\n" +
141 "\t\t1 (rtcp.DuplicateRLEReportBlock):\n" +
142 "\t\t\tXRHeader:\n" +
143 "\t\t\t\tBlockType: [DuplicateRLEReportBlockType]\n" +
144 "\t\t\t\tTypeSpecific: 0x0\n" +
145 "\t\t\t\tBlockLength: 0\n" +
146 "\t\t\tT: 0\n" +
147 "\t\t\tSSRC: 0x12345689\n" +
148 "\t\t\tBeginSeq: 5\n" +
149 "\t\t\tEndSeq: 12\n" +
150 "\t\t\tChunks:\n" +
151 "\t\t\t\t0: [[RunLength type=1, length=291]]\n" +
152 "\t\t\t\t1: [[RunLength type=0, length=16383]]\n" +
153 "\t\t\t\t2: [[BitVector 0b111111111111111]]\n" +
154 "\t\t\t\t3: [[TerminatingNull]]\n" +
155 "\t\t2 (rtcp.PacketReceiptTimesReportBlock):\n" +
156 "\t\t\tXRHeader:\n" +
157 "\t\t\t\tBlockType: [PacketReceiptTimesReportBlockType]\n" +
158 "\t\t\t\tTypeSpecific: 0x0\n" +
159 "\t\t\t\tBlockLength: 0\n" +
160 "\t\t\tT: 0\n" +
161 "\t\t\tSSRC: 0x98765432\n" +
162 "\t\t\tBeginSeq: 15432\n" +
163 "\t\t\tEndSeq: 15577\n" +
164 "\t\t\tReceiptTime: [286331153 572662306 858993459 1145324612 1431655765]\n" +
165 "\t\t3 (rtcp.ReceiverReferenceTimeReportBlock):\n" +
166 "\t\t\tXRHeader:\n" +
167 "\t\t\t\tBlockType: [ReceiverReferenceTimeReportBlockType]\n" +
168 "\t\t\t\tTypeSpecific: 0x0\n" +
169 "\t\t\t\tBlockLength: 0\n" +
170 "\t\t\tNTPTimestamp: 72623859790382856\n" +
171 "\t\t4 (rtcp.DLRRReportBlock):\n" +
172 "\t\t\tXRHeader:\n" +
173 "\t\t\t\tBlockType: [DLRRReportBlockType]\n" +
174 "\t\t\t\tTypeSpecific: 0x0\n" +
175 "\t\t\t\tBlockLength: 0\n" +
176 "\t\t\tReports:\n" +
177 "\t\t\t\t0:\n" +
178 "\t\t\t\t\tSSRC: 0x88888888\n" +
179 "\t\t\t\t\tLastRR: 305419896\n" +
180 "\t\t\t\t\tDLRR: 2576980377\n" +
181 "\t\t\t\t1:\n" +
182 "\t\t\t\t\tSSRC: 0x9090909\n" +
183 "\t\t\t\t\tLastRR: 305419896\n" +
184 "\t\t\t\t\tDLRR: 2576980377\n" +
185 "\t\t\t\t2:\n" +
186 "\t\t\t\t\tSSRC: 0x11223344\n" +
187 "\t\t\t\t\tLastRR: 305419896\n" +
188 "\t\t\t\t\tDLRR: 2576980377\n" +
189 "\t\t5 (rtcp.StatisticsSummaryReportBlock):\n" +
190 "\t\t\tXRHeader:\n" +
191 "\t\t\t\tBlockType: [StatisticsSummaryReportBlockType]\n" +
192 "\t\t\t\tTypeSpecific: 0x0\n" +
193 "\t\t\t\tBlockLength: 0\n" +
194 "\t\t\tLossReports: true\n" +
195 "\t\t\tDuplicateReports: true\n" +
196 "\t\t\tJitterReports: true\n" +
197 "\t\t\tTTLorHopLimit: [[ToH = IPv4]]\n" +
198 "\t\t\tSSRC: 0xFEDCBA98\n" +
199 "\t\t\tBeginSeq: 4660\n" +
200 "\t\t\tEndSeq: 22136\n" +
201 "\t\t\tLostPackets: 286331153\n" +
202 "\t\t\tDupPackets: 572662306\n" +
203 "\t\t\tMinJitter: 858993459\n" +
204 "\t\t\tMaxJitter: 1145324612\n" +
205 "\t\t\tMeanJitter: 1431655765\n" +
206 "\t\t\tDevJitter: 1717986918\n" +
207 "\t\t\tMinTTLOrHL: 1\n" +
208 "\t\t\tMaxTTLOrHL: 2\n" +
209 "\t\t\tMeanTTLOrHL: 3\n" +
210 "\t\t\tDevTTLOrHL: 4\n" +
211 "\t\t6 (rtcp.VoIPMetricsReportBlock):\n" +
212 "\t\t\tXRHeader:\n" +
213 "\t\t\t\tBlockType: [VoIPMetricsReportBlockType]\n" +
214 "\t\t\t\tTypeSpecific: 0x0\n" +
215 "\t\t\t\tBlockLength: 0\n" +
216 "\t\t\tSSRC: 0x89ABCDEF\n" +
217 "\t\t\tLossRate: 5\n" +
218 "\t\t\tDiscardRate: 6\n" +
219 "\t\t\tBurstDensity: 7\n" +
220 "\t\t\tGapDensity: 8\n" +
221 "\t\t\tBurstDuration: 4369\n" +
222 "\t\t\tGapDuration: 8738\n" +
223 "\t\t\tRoundTripDelay: 13107\n" +
224 "\t\t\tEndSystemDelay: 17476\n" +
225 "\t\t\tSignalLevel: 17\n" +
226 "\t\t\tNoiseLevel: 34\n" +
227 "\t\t\tRERL: 51\n" +
228 "\t\t\tGmin: 68\n" +
229 "\t\t\tRFactor: 85\n" +
230 "\t\t\tExtRFactor: 102\n" +
231 "\t\t\tMOSLQ: 119\n" +
232 "\t\t\tMOSCQ: 136\n" +
233 "\t\t\tRXConfig: 153\n" +
234 "\t\t\tJBNominal: 4386\n" +
235 "\t\t\tJBMaximum: 13124\n" +
236 "\t\t\tJBAbsMax: 21862\n",
237 },
238 {
239 &FullIntraRequest{
240 SenderSSRC: 0x0,
241 MediaSSRC: 0x4bc4fcb4,
242 FIR: []FIREntry{
243 {
244 SSRC: 0x12345678,
245 SequenceNumber: 0x42,
246 },
247 {
248 SSRC: 0x98765432,
249 SequenceNumber: 0x57,
250 },
251 },
252 },
253 // nolint
254 "rtcp.FullIntraRequest:\n" +
255 "\tSenderSSRC: 0\n" +
256 "\tMediaSSRC: 1271200948\n" +
257 "\tFIR:\n" +
258 "\t\t0:\n" +
259 "\t\t\tSSRC: 305419896\n" +
260 "\t\t\tSequenceNumber: 66\n" +
261 "\t\t1:\n" +
262 "\t\t\tSSRC: 2557891634\n" +
263 "\t\t\tSequenceNumber: 87\n",
264 },
265 {
266 &Goodbye{
267 Sources: []uint32{
268 0x01020304,
269 0x05060708,
270 },
271 Reason: "because",
272 },
273 "rtcp.Goodbye:\n" +
274 "\tSources: [16909060 84281096]\n" +
275 "\tReason: because\n",
276 },
277 {
278 &ReceiverReport{
279 SSRC: 0x902f9e2e,
280 Reports: []ReceptionReport{{
281 SSRC: 0xbc5e9a40,
282 FractionLost: 0,
283 TotalLost: 0,
284 LastSequenceNumber: 0x46e1,
285 Jitter: 273,
286 LastSenderReport: 0x9f36432,
287 Delay: 150137,
288 }},
289 ProfileExtensions: []byte{},
290 },
291 "rtcp.ReceiverReport:\n" +
292 "\tSSRC: 2419039790\n" +
293 "\tReports:\n" +
294 "\t\t0:\n" +
295 "\t\t\tSSRC: 3160316480\n" +
296 "\t\t\tFractionLost: 0\n" +
297 "\t\t\tTotalLost: 0\n" +
298 "\t\t\tLastSequenceNumber: 18145\n" +
299 "\t\t\tJitter: 273\n" +
300 "\t\t\tLastSenderReport: 166945842\n" +
301 "\t\t\tDelay: 150137\n" +
302 "\tProfileExtensions: []\n",
303 },
304 {
305 NewCNAMESourceDescription(0x902f9e2e, "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}"),
306 "rtcp.SourceDescription:\n" +
307 "\tChunks:\n" +
308 "\t\t0:\n" +
309 "\t\t\tSource: 2419039790\n" +
310 "\t\t\tItems:\n" +
311 "\t\t\t\t0:\n" +
312 "\t\t\t\t\tType: [CNAME]\n" +
313 "\t\t\t\t\tText: {9c00eb92-1afb-9d49-a47d-91f64eee69f5}\n",
314 },
315 {
316 &PictureLossIndication{
317 SenderSSRC: 0x902f9e2e,
318 MediaSSRC: 0x902f9e2e,
319 },
320 // nolint
321 "rtcp.PictureLossIndication:\n" +
322 "\tSenderSSRC: 2419039790\n" +
323 "\tMediaSSRC: 2419039790\n",
324 },
325 {
326 &RapidResynchronizationRequest{
327 SenderSSRC: 0x902f9e2e,
328 MediaSSRC: 0x902f9e2e,
329 },
330 "rtcp.RapidResynchronizationRequest:\n" +
331 "\tSenderSSRC: 2419039790\n" +
332 "\tMediaSSRC: 2419039790\n",
333 },
334 {
335 &ReceiverEstimatedMaximumBitrate{
336 SenderSSRC: 1,
337 Bitrate: 8927168,
338 SSRCs: []uint32{1215622422},
339 },
340 "rtcp.ReceiverEstimatedMaximumBitrate:\n" +
341 "\tSenderSSRC: 1\n" +
342 "\tBitrate: 8.927168e+06\n" +
343 "\tSSRCs: [1215622422]\n",
344 },
345 {
346 &SenderReport{
347 SSRC: 0x902f9e2e,
348 NTPTime: 0xda8bd1fcdddda05a,
349 RTPTime: 0xaaf4edd5,
350 PacketCount: 1,
351 OctetCount: 2,
352 Reports: []ReceptionReport{{
353 SSRC: 0xbc5e9a40,
354 FractionLost: 0,
355 TotalLost: 0,
356 LastSequenceNumber: 0x46e1,
357 Jitter: 273,
358 LastSenderReport: 0x9f36432,
359 Delay: 150137,
360 }},
361 ProfileExtensions: []byte{
362 0x81, 0xca, 0x0, 0x6,
363 0x2b, 0x7e, 0xc0, 0xc5,
364 0x1, 0x10, 0x4c, 0x63,
365 0x49, 0x66, 0x7a, 0x58,
366 0x6f, 0x6e, 0x44, 0x6f,
367 0x72, 0x64, 0x53, 0x65,
368 0x57, 0x36, 0x0, 0x0,
369 },
370 },
371 "rtcp.SenderReport:\n" +
372 "\tSSRC: 2419039790\n" +
373 "\tNTPTime: 15747911406015324250\n" +
374 "\tRTPTime: 2868178389\n" +
375 "\tPacketCount: 1\n" +
376 "\tOctetCount: 2\n" +
377 "\tReports:\n" +
378 "\t\t0:\n" +
379 "\t\t\tSSRC: 3160316480\n" +
380 "\t\t\tFractionLost: 0\n" +
381 "\t\t\tTotalLost: 0\n" +
382 "\t\t\tLastSequenceNumber: 18145\n" +
383 "\t\t\tJitter: 273\n" +
384 "\t\t\tLastSenderReport: 166945842\n" +
385 "\t\t\tDelay: 150137\n" +
386 "\tProfileExtensions: " +
387 "[129 202 0 6 43 126 192 197 1 16 76 99 73 102 122 88 111 110 68 111 114 100 83 101 87 54 0 0]\n",
388 },
389 {
390 &SliceLossIndication{
391 SenderSSRC: 0x902f9e2e,
392 MediaSSRC: 0x902f9e2e,
393 SLI: []SLIEntry{{0xaaa, 0, 0x2C}},
394 },
395 "rtcp.SliceLossIndication:\n" +
396 "\tSenderSSRC: 2419039790\n" +
397 "\tMediaSSRC: 2419039790\n" +
398 "\tSLI:\n" +
399 "\t\t0:\n" +
400 "\t\t\tFirst: 2730\n" +
401 "\t\t\tNumber: 0\n" +
402 "\t\t\tPicture: 44\n",
403 },
404 {
405 &SourceDescription{
406 Chunks: []SourceDescriptionChunk{
407 {
408 Source: 0x10000000,
409 Items: []SourceDescriptionItem{
410 {
411 Type: SDESCNAME,
412 Text: "A",
413 },
414 {
415 Type: SDESPhone,
416 Text: "B",
417 },
418 },
419 },
420 },
421 },
422 "rtcp.SourceDescription:\n" +
423 "\tChunks:\n" +
424 "\t\t0:\n" +
425 "\t\t\tSource: 268435456\n" +
426 "\t\t\tItems:\n" +
427 "\t\t\t\t0:\n" +
428 "\t\t\t\t\tType: [CNAME]\n" +
429 "\t\t\t\t\tText: A\n" +
430 "\t\t\t\t1:\n" +
431 "\t\t\t\t\tType: [PHONE]\n" +
432 "\t\t\t\t\tText: B\n",
433 },
434 {
435 &TransportLayerCC{
436 Header: Header{
437 Padding: true,
438 Count: FormatTCC,
439 Type: TypeTransportSpecificFeedback,
440 Length: 5,
441 },
442 SenderSSRC: 4195875351,
443 MediaSSRC: 1124282272,
444 BaseSequenceNumber: 153,
445 PacketStatusCount: 1,
446 ReferenceTime: 4057090,
447 FbPktCount: 23,
448 // 0b00100000, 0b00000001
449 PacketChunks: []PacketStatusChunk{
450 &RunLengthChunk{
451 Type: TypeTCCRunLengthChunk,
452 PacketStatusSymbol: TypeTCCPacketReceivedSmallDelta,
453 RunLength: 1,
454 },
455 },
456 // 0b10010100
457 RecvDeltas: []*RecvDelta{
458 {
459 Type: TypeTCCPacketReceivedSmallDelta,
460 Delta: 37000,
461 },
462 },
463 },
464 "rtcp.TransportLayerCC:\n" +
465 "\tHeader:\n" +
466 "\t\tPadding: true\n" +
467 "\t\tCount: 15\n" +
468 "\t\tType: [TSFB]\n" +
469 "\t\tLength: 5\n" +
470 "\tSenderSSRC: 4195875351\n" +
471 "\tMediaSSRC: 1124282272\n" +
472 "\tBaseSequenceNumber: 153\n" +
473 "\tPacketStatusCount: 1\n" +
474 "\tReferenceTime: 4057090\n" +
475 "\tFbPktCount: 23\n" +
476 "\tPacketChunks:\n" +
477 "\t\t0 (rtcp.RunLengthChunk):\n" +
478 "\t\t\tPacketStatusChunk: <nil>\n" +
479 "\t\t\tType: 0\n" +
480 "\t\t\tPacketStatusSymbol: 1\n" +
481 "\t\t\tRunLength: 1\n" +
482 "\tRecvDeltas:\n" +
483 "\t\t0:\n" +
484 "\t\t\tType: 1\n" +
485 "\t\t\tDelta: 37000\n",
486 },
487 {
488 &TransportLayerNack{
489 SenderSSRC: 0x902f9e2e,
490 MediaSSRC: 0x902f9e2e,
491 Nacks: []NackPair{{1, 0xAA}, {1034, 0x05}},
492 },
493 "rtcp.TransportLayerNack:\n" +
494 "\tSenderSSRC: 2419039790\n" +
495 "\tMediaSSRC: 2419039790\n" +
496 "\tNacks:\n" +
497 "\t\t0:\n" +
498 "\t\t\tPacketID: 1\n" +
499 "\t\t\tLostPackets: 170\n" +
500 "\t\t1:\n" +
501 "\t\t\tPacketID: 1034\n" +
502 "\t\t\tLostPackets: 5\n",
503 },
504 }
505
506 for i, test := range tests {
507 assert.Equalf(t, test.expected, stringify(test.packet), "Error stringifying test %d", i)
508 }
509 }