| 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 | func TestFullIntraRequestUnmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestFullIntraRequestUnmarshal().(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#) { |
| 13 | for _, test := range []struct { |
| 14 | Name string |
| 15 | Data []byte |
| 16 | Want FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 17 | WantError error |
| 18 | }{ |
| 19 | { |
| 20 | Name: "valid", |
| 21 | Data: []byte{ |
| 22 | // v=2, p=0, FMT=4, PSFB, len=4 |
| 23 | 0x84, 0xce, 0x00, 0x04, |
| 24 | // ssrc=0x0 |
| 25 | 0x00, 0x00, 0x00, 0x00, |
| 26 | // ssrc=0x4bc4fcb4 |
| 27 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 28 | // ssrc=0x12345678 |
| 29 | 0x12, 0x34, 0x56, 0x78, |
| 30 | // Seqno=0x42 |
| 31 | 0x42, 0x00, 0x00, 0x00, |
| 32 | }, |
| 33 | Want: FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#{ |
| 34 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#SenderSSRC.: 0x0, |
| 35 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#MediaSSRC.: 0x4bc4fcb4, |
| 36 | FIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#FIR.: []FIREntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#{ |
| 37 | { |
| 38 | SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SSRC.: 0x12345678, |
| 39 | SequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SequenceNumber.: 0x42, |
| 40 | }, |
| 41 | }, |
| 42 | }, |
| 43 | }, |
| 44 | { |
| 45 | Name: "also valid", |
| 46 | Data: []byte{ |
| 47 | // v=2, p=0, FMT=4, PSFB, len=6 |
| 48 | 0x84, 0xce, 0x00, 0x06, |
| 49 | // ssrc=0x0 |
| 50 | 0x00, 0x00, 0x00, 0x00, |
| 51 | // ssrc=0x4bc4fcb4 |
| 52 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 53 | // ssrc=0x12345678 |
| 54 | 0x12, 0x34, 0x56, 0x78, |
| 55 | // Seqno=0x42 |
| 56 | 0x42, 0x00, 0x00, 0x00, |
| 57 | // ssrc=0x98765432 |
| 58 | 0x98, 0x76, 0x54, 0x32, |
| 59 | // Seqno=0x57 |
| 60 | 0x57, 0x00, 0x00, 0x00, |
| 61 | }, |
| 62 | Want: FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#{ |
| 63 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#SenderSSRC.: 0x0, |
| 64 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#MediaSSRC.: 0x4bc4fcb4, |
| 65 | FIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#FIR.: []FIREntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#{ |
| 66 | { |
| 67 | SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SSRC.: 0x12345678, |
| 68 | SequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SequenceNumber.: 0x42, |
| 69 | }, |
| 70 | { |
| 71 | SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SSRC.: 0x98765432, |
| 72 | SequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SequenceNumber.: 0x57, |
| 73 | }, |
| 74 | }, |
| 75 | }, |
| 76 | }, |
| 77 | { |
| 78 | Name: "packet too short", |
| 79 | Data: []byte{ |
| 80 | 0x00, 0x00, 0x00, 0x00, |
| 81 | }, |
| 82 | WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort., |
| 83 | }, |
| 84 | { |
| 85 | Name: "invalid header", |
| 86 | Data: []byte{ |
| 87 | 0x00, 0x00, 0x00, 0x00, |
| 88 | 0x00, 0x00, 0x00, 0x00, |
| 89 | 0x00, 0x00, 0x00, 0x00, |
| 90 | 0x00, 0x00, 0x00, 0x00, |
| 91 | 0x00, 0x00, 0x00, 0x00, |
| 92 | }, |
| 93 | WantError: errBadVersionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadVersion., |
| 94 | }, |
| 95 | { |
| 96 | Name: "wrong type", |
| 97 | Data: []byte{ |
| 98 | // v=2, p=0, FMT=4, RR, len=4 |
| 99 | 0x84, 0xc9, 0x00, 0x04, |
| 100 | // ssrc=0x0 |
| 101 | 0x00, 0x00, 0x00, 0x00, |
| 102 | // ssrc=0x4bc4fcb4 |
| 103 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 104 | // ssrc=0x12345678 |
| 105 | 0x12, 0x34, 0x56, 0x78, |
| 106 | // Seqno=0x42 |
| 107 | 0x42, 0x00, 0x00, 0x00, |
| 108 | }, |
| 109 | WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType., |
| 110 | }, |
| 111 | { |
| 112 | Name: "wrong fmt", |
| 113 | Data: []byte{ |
| 114 | // v=2, p=0, FMT=2, PSFB, len=4 |
| 115 | 0x82, 0xce, 0x00, 0x04, |
| 116 | // ssrc=0x0 |
| 117 | 0x00, 0x00, 0x00, 0x00, |
| 118 | // ssrc=0x4bc4fcb4 |
| 119 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 120 | // ssrc=0x12345678 |
| 121 | 0x12, 0x34, 0x56, 0x78, |
| 122 | // Seqno=0x42 |
| 123 | 0x42, 0x00, 0x00, 0x00, |
| 124 | }, |
| 125 | WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType., |
| 126 | }, |
| 127 | { |
| 128 | Name: "wrong length", |
| 129 | Data: []byte{ |
| 130 | // v=2, p=0, FMT=4, PSFB, len=3 |
| 131 | 0x84, 0xce, 0x00, 0x03, |
| 132 | // ssrc=0x0 |
| 133 | 0x00, 0x00, 0x00, 0x00, |
| 134 | // ssrc=0x4bc4fcb4 |
| 135 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 136 | // ssrc=0x12345678 |
| 137 | 0x12, 0x34, 0x56, 0x78, |
| 138 | }, |
| 139 | WantError: errBadLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadLength., |
| 140 | }, |
| 141 | } { |
| 142 | var fir FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 143 | err := fir.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#Unmarshal().(test.Data) |
| 144 | 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 rr mismatch", test.Name) |
| 145 | if err != nil { |
| 146 | continue |
| 147 | } |
| 148 | |
| 149 | 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, fir, "Unmarshal %q rr mismatch", test.Name) |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | func TestFullIntraRequestRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestFullIntraRequestRoundTrip().(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#) { |
| 154 | for _, test := range []struct { |
| 155 | Name string |
| 156 | Packet FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 157 | WantError error |
| 158 | }{ |
| 159 | { |
| 160 | Name: "valid", |
| 161 | Packet: FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#{ |
| 162 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#SenderSSRC.: 1, |
| 163 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#MediaSSRC.: 2, |
| 164 | FIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#FIR.: []FIREntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#{{ |
| 165 | SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SSRC.: 3, |
| 166 | SequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SequenceNumber.: 42, |
| 167 | }}, |
| 168 | }, |
| 169 | }, |
| 170 | { |
| 171 | Name: "also valid", |
| 172 | Packet: FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#{ |
| 173 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#SenderSSRC.: 5000, |
| 174 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#MediaSSRC.: 6000, |
| 175 | FIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#FIR.: []FIREntryscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#{{ |
| 176 | SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SSRC.: 3, |
| 177 | SequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FIREntry#SequenceNumber.: 57, |
| 178 | }}, |
| 179 | }, |
| 180 | }, |
| 181 | } { |
| 182 | data, err := test.Packet.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#Marshal().() |
| 183 | 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) |
| 184 | if err != nil { |
| 185 | continue |
| 186 | } |
| 187 | |
| 188 | var decoded FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 189 | 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`/FullIntraRequest#Unmarshal().(data), "Unmarshal %q", test.Name) |
| 190 | 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.Packet, decoded, "%q rr header mismatch", test.Name) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | func TestFullIntraRequestUnmarshalHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestFullIntraRequestUnmarshalHeader().(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#) { |
| 195 | for _, test := range []struct { |
| 196 | Name string |
| 197 | Data []byte |
| 198 | Want Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# |
| 199 | WantError error |
| 200 | }{ |
| 201 | { |
| 202 | Name: "valid header", |
| 203 | Data: []byte{ |
| 204 | // v=2, p=0, FMT=1, PSFB, len=4 |
| 205 | 0x84, 0xce, 0x00, 0x04, |
| 206 | // ssrc=0x0 |
| 207 | 0x00, 0x00, 0x00, 0x00, |
| 208 | // ssrc=0x4bc4fcb4 |
| 209 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 210 | // ssrc=0x00000000 |
| 211 | 0x00, 0x00, 0x00, 0x00, |
| 212 | // Seqno=0x22 |
| 213 | 0x22, 0x00, 0x00, 0x00, |
| 214 | }, |
| 215 | Want: Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{ |
| 216 | Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatFIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatFIR., |
| 217 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type.: TypePayloadSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypePayloadSpecificFeedback., |
| 218 | Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: 4, |
| 219 | }, |
| 220 | }, |
| 221 | } { |
| 222 | var fir FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 223 | err := fir.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#Unmarshal().(test.Data) |
| 224 | 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 header %q rr mismatch", test.Name) |
| 225 | if err != nil { |
| 226 | continue |
| 227 | } |
| 228 | |
| 229 | 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, fir.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#Header().(), "Unmarshal header %q rr mismatch", test.Name) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | func TestFullIntraRequestUnmarshalMaxLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestFullIntraRequestUnmarshalMaxLength().(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#) { |
| 234 | rawPacket := make([]byte, headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+4*0xFFFE) |
| 235 | rawPacket[0] = 0x84 |
| 236 | rawPacket[1] = 0xce |
| 237 | rawPacket[2] = 0xff |
| 238 | rawPacket[3] = 0xfe |
| 239 | |
| 240 | var fir FullIntraRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest# |
| 241 | err := fir.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#Unmarshal().(rawPacket) |
| 242 | 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) |
| 243 | 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, fir.FIRscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FullIntraRequest#FIR., (4*0xFFFE-firOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/firOffset.)/8) |
| 244 | } |