| 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# = (*PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#)(nil) // assert is a Packet |
| 13 | |
| 14 | func TestPictureLossIndicationUnmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestPictureLossIndicationUnmarshal().(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 PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# |
| 19 | WantError error |
| 20 | }{ |
| 21 | { |
| 22 | Name: "valid", |
| 23 | Data: []byte{ |
| 24 | // v=2, p=0, FMT=1, PSFB, len=1 |
| 25 | 0x81, 0xce, 0x00, 0x02, |
| 26 | // ssrc=0x0 |
| 27 | 0x00, 0x00, 0x00, 0x00, |
| 28 | // ssrc=0x4bc4fcb4 |
| 29 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 30 | }, |
| 31 | Want: PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#{ |
| 32 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC.: 0x0, |
| 33 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.: 0x4bc4fcb4, |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | Name: "packet too short", |
| 38 | Data: []byte{ |
| 39 | 0x00, 0x00, 0x00, 0x00, |
| 40 | }, |
| 41 | WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort., |
| 42 | }, |
| 43 | { |
| 44 | Name: "invalid header", |
| 45 | Data: []byte{ |
| 46 | 0x00, 0x00, 0x00, 0x00, |
| 47 | 0x00, 0x00, 0x00, 0x00, |
| 48 | 0x00, 0x00, 0x00, 0x00, |
| 49 | }, |
| 50 | WantError: errBadVersionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadVersion., |
| 51 | }, |
| 52 | { |
| 53 | Name: "wrong type", |
| 54 | Data: []byte{ |
| 55 | // v=2, p=0, FMT=1, RR, len=1 |
| 56 | 0x81, 0xc9, 0x00, 0x02, |
| 57 | // ssrc=0x0 |
| 58 | 0x00, 0x00, 0x00, 0x00, |
| 59 | // ssrc=0x4bc4fcb4 |
| 60 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 61 | }, |
| 62 | WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType., |
| 63 | }, |
| 64 | { |
| 65 | Name: "wrong fmt", |
| 66 | Data: []byte{ |
| 67 | // v=2, p=0, FMT=2, RR, len=1 |
| 68 | 0x82, 0xc9, 0x00, 0x02, |
| 69 | // ssrc=0x0 |
| 70 | 0x00, 0x00, 0x00, 0x00, |
| 71 | // ssrc=0x4bc4fcb4 |
| 72 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 73 | }, |
| 74 | WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType., |
| 75 | }, |
| 76 | } { |
| 77 | var pli PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# |
| 78 | err := pli.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Unmarshal().(test.Data) |
| 79 | 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) |
| 80 | if err != nil { |
| 81 | continue |
| 82 | } |
| 83 | |
| 84 | 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, pli, "Unmarshal %q", test.Name) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func TestPictureLossIndicationRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestPictureLossIndicationRoundTrip().(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#) { |
| 89 | for _, test := range []struct { |
| 90 | Name string |
| 91 | Packet PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# |
| 92 | WantError error |
| 93 | }{ |
| 94 | { |
| 95 | Name: "valid", |
| 96 | Packet: PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#{ |
| 97 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC.: 1, |
| 98 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.: 2, |
| 99 | }, |
| 100 | }, |
| 101 | { |
| 102 | Name: "also valid", |
| 103 | Packet: PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#{ |
| 104 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC.: 5000, |
| 105 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.: 6000, |
| 106 | }, |
| 107 | }, |
| 108 | } { |
| 109 | data, err := test.Packet.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Marshal().() |
| 110 | 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) |
| 111 | if err != nil { |
| 112 | continue |
| 113 | } |
| 114 | |
| 115 | var decoded PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# |
| 116 | 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`/PictureLossIndication#Unmarshal().(data), "Unmarshal %q", test.Name) |
| 117 | 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 round trip mismatch", test.Name) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func TestPictureLossIndicationUnmarshalHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestPictureLossIndicationUnmarshalHeader().(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#) { |
| 122 | for _, test := range []struct { |
| 123 | Name string |
| 124 | Data []byte |
| 125 | Want Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# |
| 126 | WantError error |
| 127 | }{ |
| 128 | { |
| 129 | Name: "valid header", |
| 130 | Data: []byte{ |
| 131 | // v=2, p=0, FMT=1, PSFB, len=1 |
| 132 | 0x81, 0xce, 0x00, 0x02, |
| 133 | // ssrc=0x0 |
| 134 | 0x00, 0x00, 0x00, 0x00, |
| 135 | // ssrc=0x4bc4fcb4 |
| 136 | 0x4b, 0xc4, 0xfc, 0xb4, |
| 137 | }, |
| 138 | Want: Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{ |
| 139 | Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatPLIscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatPLI., |
| 140 | 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., |
| 141 | Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: pliLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/pliLength., |
| 142 | }, |
| 143 | }, |
| 144 | } { |
| 145 | var pli PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication# |
| 146 | err := pli.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Unmarshal().(test.Data) |
| 147 | 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", test.Name) |
| 148 | if err != nil { |
| 149 | continue |
| 150 | } |
| 151 | |
| 152 | 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, pli.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#Header().(), "Unmarshal header %q", test.Name) |
| 153 | } |
| 154 | } |