| 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 | // Author: adwpc |
| 7 | |
| 8 | import ( |
| 9 | "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/" |
| 10 | "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/" |
| 11 | "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/" |
| 12 | "mathscip-go gomod github.com/golang/go/src go1.24.0 math/" |
| 13 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 14 | ) |
| 15 | |
| 16 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#page-5 |
| 17 | // 0 1 2 3 |
| 18 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 19 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 20 | // |V=2|P| FMT=15 | PT=205 | length | |
| 21 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 22 | // | SSRC of packet sender | |
| 23 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 24 | // | SSRC of media source | |
| 25 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 26 | // | base sequence number | packet status count | |
| 27 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 | // | reference time | fb pkt. count | |
| 29 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 | // | packet chunk | packet chunk | |
| 31 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 32 | // . . |
| 33 | // . . |
| 34 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 35 | // | packet chunk | recv delta | recv delta | |
| 36 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 37 | // . . |
| 38 | // . . |
| 39 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 40 | // | recv delta | recv delta | zero padding | |
| 41 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 42 | |
| 43 | // for packet status chunk. |
| 44 | const ( |
| 45 | // type of packet status chunk. |
| 46 | TypeTCCRunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCRunLengthChunk. = 0 |
| 47 | TypeTCCStatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCStatusVectorChunk. = 1 |
| 48 | |
| 49 | // len of packet status chunk. |
| 50 | packetStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusChunkLength. = 2 |
| 51 | ) |
| 52 | |
| 53 | // type of packet status symbol and recv delta. |
| 54 | const ( |
| 55 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1.1 |
| 56 | TypeTCCPacketNotReceivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketNotReceived. = uint16(iota) |
| 57 | TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. |
| 58 | TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. |
| 59 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#page-7 |
| 60 | // see Example 2: "packet received, w/o recv delta". |
| 61 | TypeTCCPacketReceivedWithoutDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedWithoutDelta. |
| 62 | ) |
| 63 | |
| 64 | // for status vector chunk. |
| 65 | const ( |
| 66 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1.4 |
| 67 | TypeTCCSymbolSizeOneBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeOneBit. = 0 |
| 68 | TypeTCCSymbolSizeTwoBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeTwoBit. = 1 |
| 69 | |
| 70 | // Notice: RFC is wrong: "packet received" (0) and "packet not received" (1) |
| 71 | // if S == TypeTCCSymbolSizeOneBit, symbol list will be: TypeTCCPacketNotReceived TypeTCCPacketReceivedSmallDelta |
| 72 | // if S == TypeTCCSymbolSizeTwoBit, symbol list will be same as above: |
| 73 | //. |
| 74 | ) |
| 75 | |
| 76 | func numOfBitsOfSymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numOfBitsOfSymbolSize().() map[uint16]uint16 { |
| 77 | return map[uint16]uint16{ |
| 78 | TypeTCCSymbolSizeOneBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeOneBit.: 1, |
| 79 | TypeTCCSymbolSizeTwoBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeTwoBit.: 2, |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | var ( |
| 84 | errPacketStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketStatusChunkLength. = errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("packet status chunk must be 2 bytes") |
| 85 | errDeltaExceedLimitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errDeltaExceedLimit. = errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("delta exceed limit") |
| 86 | ) |
| 87 | |
| 88 | // PacketStatusChunk has two kinds: |
| 89 | // RunLengthChunk and StatusVectorChunk. |
| 90 | type PacketStatusChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk# interface { |
| 91 | Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk#Marshal.() ([]byte, error) |
| 92 | Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk#Unmarshal.(rawPacket []byte) error |
| 93 | } |
| 94 | |
| 95 | // RunLengthChunk T=TypeTCCRunLengthChunk |
| 96 | // 0 1 |
| 97 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
| 98 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 99 | // |T| S | Run Length | |
| 100 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 101 | // . |
| 102 | type RunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk# struct { |
| 103 | PacketStatusChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusChunk. |
| 104 | |
| 105 | // T = TypeTCCRunLengthChunk |
| 106 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Type. uint16 |
| 107 | |
| 108 | // S: type of packet status |
| 109 | // kind: TypeTCCPacketNotReceived or... |
| 110 | PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol. uint16 |
| 111 | |
| 112 | // RunLength: count of S |
| 113 | RunLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#RunLength. uint16 |
| 114 | } |
| 115 | |
| 116 | // Marshal .. |
| 117 | func (r RunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Marshal().() ([]byte, error) { |
| 118 | chunk := make([]byte, 2) |
| 119 | |
| 120 | // append 1 bit '0' |
| 121 | dst, err := setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(0, 1, 0, 0) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | |
| 126 | // append 2 bit PacketStatusSymbol |
| 127 | dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, 2, 1, r.PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol.) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | |
| 132 | // append 13 bit RunLength |
| 133 | dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, 13, 3, r.RunLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#RunLength.) |
| 134 | if err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | |
| 138 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint16().(chunk, dst) |
| 139 | |
| 140 | return chunk, nil |
| 141 | } |
| 142 | |
| 143 | // Unmarshal .. |
| 144 | func (r *RunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Unmarshal().(rawPacket []byte) error { |
| 145 | if len(rawPacket) != packetStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusChunkLength. { |
| 146 | return errPacketStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketStatusChunkLength. |
| 147 | } |
| 148 | |
| 149 | // record type |
| 150 | r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Type. = TypeTCCRunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCRunLengthChunk. |
| 151 | |
| 152 | // get PacketStatusSymbol |
| 153 | // r.PacketStatusSymbol = uint16(rawPacket[0] >> 5 & 0x03) |
| 154 | r.PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol. = getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 1, 2) |
| 155 | |
| 156 | // get RunLength |
| 157 | // r.RunLength = uint16(rawPacket[0]&0x1F)*256 + uint16(rawPacket[1]) |
| 158 | r.RunLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#RunLength. = getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 3, 5)<<8 + uint16(rawPacket[1]) |
| 159 | |
| 160 | return nil |
| 161 | } |
| 162 | |
| 163 | // StatusVectorChunk T=typeStatusVecotrChunk |
| 164 | // 0 1 |
| 165 | // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
| 166 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 167 | // |T|S| symbol list | |
| 168 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 169 | // . |
| 170 | type StatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk# struct { |
| 171 | PacketStatusChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#PacketStatusChunk. |
| 172 | // T = TypeTCCRunLengthChunk |
| 173 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Type. uint16 |
| 174 | |
| 175 | // TypeTCCSymbolSizeOneBit or TypeTCCSymbolSizeTwoBit |
| 176 | SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. uint16 |
| 177 | |
| 178 | // when SymbolSize = TypeTCCSymbolSizeOneBit, SymbolList is 14*1bit: |
| 179 | // TypeTCCSymbolListPacketReceived or TypeTCCSymbolListPacketNotReceived |
| 180 | // when SymbolSize = TypeTCCSymbolSizeTwoBit, SymbolList is 7*2bit: |
| 181 | // TypeTCCPacketNotReceived TypeTCCPacketReceivedSmallDelta TypeTCCPacketReceivedLargeDelta or typePacketReserved |
| 182 | SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. []uint16 |
| 183 | } |
| 184 | |
| 185 | // Marshal .. |
| 186 | func (r StatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Marshal().() ([]byte, error) { |
| 187 | chunk := make([]byte, 2) |
| 188 | |
| 189 | // set first bit '1' |
| 190 | dst, err := setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(0, 1, 0, 1) |
| 191 | if err != nil { |
| 192 | return nil, err |
| 193 | } |
| 194 | |
| 195 | // set second bit SymbolSize |
| 196 | dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, 1, 1, r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize.) |
| 197 | if err != nil { |
| 198 | return nil, err |
| 199 | } |
| 200 | |
| 201 | numOfBits := numOfBitsOfSymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numOfBitsOfSymbolSize().()[r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize.] |
| 202 | // append 14 bit SymbolList |
| 203 | for i, s := range r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. { |
| 204 | index := numOfBits*uint16(i) + 2 //nolint:gosec // G115 |
| 205 | dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, numOfBits, index, s) |
| 206 | if err != nil { |
| 207 | return nil, err |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint16().(chunk, dst) |
| 212 | // set SymbolList(bit8-15) |
| 213 | // chunk[1] = uint8(r.SymbolList) & 0x0f |
| 214 | return chunk, nil |
| 215 | } |
| 216 | |
| 217 | // Unmarshal .. |
| 218 | func (r *StatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Unmarshal().(rawPacket []byte) error { |
| 219 | if len(rawPacket) != packetStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusChunkLength. { |
| 220 | return errPacketStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketStatusChunkLength. |
| 221 | } |
| 222 | |
| 223 | r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Type. = TypeTCCStatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCStatusVectorChunk. |
| 224 | r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. = getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 1, 1) |
| 225 | |
| 226 | if r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. == TypeTCCSymbolSizeOneBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeOneBit. { |
| 227 | for i := range uint16(6) { |
| 228 | r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. = append(r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList., getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 2+i, 1)) |
| 229 | } |
| 230 | for i := range uint16(8) { |
| 231 | r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. = append(r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList., getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[1], i, 1)) |
| 232 | } |
| 233 | |
| 234 | return nil |
| 235 | } |
| 236 | if r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. == TypeTCCSymbolSizeTwoBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeTwoBit. { |
| 237 | for i := range uint16(3) { |
| 238 | r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. = append(r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList., getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 2+i*2, 2)) |
| 239 | } |
| 240 | for i := range uint16(4) { |
| 241 | r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList. = append(r.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList., getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[1], i*2, 2)) |
| 242 | } |
| 243 | |
| 244 | return nil |
| 245 | } |
| 246 | |
| 247 | r.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. = getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[0], 2, 6)<<8 + uint16(rawPacket[1]) |
| 248 | |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | const ( |
| 253 | // TypeTCCDeltaScaleFactor https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1.5 |
| 254 | TypeTCCDeltaScaleFactorscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCDeltaScaleFactor. = 250 |
| 255 | ) |
| 256 | |
| 257 | // RecvDelta are represented as multiples of 250us |
| 258 | // small delta is 1 byte: [0,63.75]ms = [0, 63750]us = [0, 255]*250us |
| 259 | // big delta is 2 bytes: [-8192.0, 8191.75]ms = [-8192000, 8191750]us = [-32768, 32767]*250us |
| 260 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#section-3.1.5 |
| 261 | type RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta# struct { |
| 262 | Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. uint16 |
| 263 | // us |
| 264 | Deltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Delta. int64 |
| 265 | } |
| 266 | |
| 267 | // Marshal .. |
| 268 | func (r RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Marshal().() ([]byte, error) { |
| 269 | delta := r.Deltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Delta. / TypeTCCDeltaScaleFactorscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCDeltaScaleFactor. |
| 270 | |
| 271 | // small delta |
| 272 | if r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. && delta >= 0 && delta <= mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxUint8scip-go gomod github.com/golang/go/src go1.24.0 math/MaxUint8. { |
| 273 | deltaChunk := make([]byte, 1) |
| 274 | deltaChunk[0] = byte(delta) //nolint:gosec // deltaChunk is created with length 1 |
| 275 | |
| 276 | return deltaChunk, nil |
| 277 | } |
| 278 | |
| 279 | // big delta |
| 280 | if r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. && delta >= mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MinInt16scip-go gomod github.com/golang/go/src go1.24.0 math/MinInt16. && delta <= mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxInt16scip-go gomod github.com/golang/go/src go1.24.0 math/MaxInt16. { |
| 281 | deltaChunk := make([]byte, 2) |
| 282 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint16().(deltaChunk, uint16(delta)) //nolint:gosec //delta is validated to fit in uint16 |
| 283 | |
| 284 | return deltaChunk, nil |
| 285 | } |
| 286 | |
| 287 | // overflow |
| 288 | return nil, errDeltaExceedLimitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errDeltaExceedLimit. |
| 289 | } |
| 290 | |
| 291 | // Unmarshal .. |
| 292 | func (r *RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Unmarshal().(rawPacket []byte) error { |
| 293 | chunkLen := len(rawPacket) |
| 294 | |
| 295 | // must be 1 or 2 bytes |
| 296 | if chunkLen != 1 && chunkLen != 2 { |
| 297 | return errDeltaExceedLimitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errDeltaExceedLimit. |
| 298 | } |
| 299 | |
| 300 | if chunkLen == 1 { |
| 301 | r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. = TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. |
| 302 | r.Deltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Delta. = TypeTCCDeltaScaleFactorscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCDeltaScaleFactor. * int64(rawPacket[0]) |
| 303 | |
| 304 | return nil |
| 305 | } |
| 306 | |
| 307 | r.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. = TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. |
| 308 | r.Deltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Delta. = TypeTCCDeltaScaleFactorscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCDeltaScaleFactor. * int64(int16(binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint16().(rawPacket))) //nolint:gosec // G115 |
| 309 | |
| 310 | return nil |
| 311 | } |
| 312 | |
| 313 | const ( |
| 314 | // the offset after header. |
| 315 | baseSequenceNumberOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/baseSequenceNumberOffset. = 8 |
| 316 | packetStatusCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusCountOffset. = 10 |
| 317 | referenceTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/referenceTimeOffset. = 12 |
| 318 | fbPktCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/fbPktCountOffset. = 15 |
| 319 | packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset. = 16 |
| 320 | ) |
| 321 | |
| 322 | // TransportLayerCC for sender-BWE |
| 323 | // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01#page-5 |
| 324 | type TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC# struct { |
| 325 | // header |
| 326 | Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header. Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# |
| 327 | |
| 328 | // SSRC of sender |
| 329 | SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#SenderSSRC. uint32 |
| 330 | |
| 331 | // SSRC of the media source |
| 332 | MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MediaSSRC. uint32 |
| 333 | |
| 334 | // Transport wide sequence of rtp extension |
| 335 | BaseSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#BaseSequenceNumber. uint16 |
| 336 | |
| 337 | // PacketStatusCount |
| 338 | PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount. uint16 |
| 339 | |
| 340 | // ReferenceTime |
| 341 | ReferenceTimescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#ReferenceTime. uint32 |
| 342 | |
| 343 | // FbPktCount |
| 344 | FbPktCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#FbPktCount. uint8 |
| 345 | |
| 346 | // PacketChunks |
| 347 | PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks. []PacketStatusChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk# |
| 348 | |
| 349 | // RecvDeltas |
| 350 | RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. []*RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta# |
| 351 | } |
| 352 | |
| 353 | // Header returns the Header associated with this packet. |
| 354 | // func (t *TransportLayerCC) Header() Header { |
| 355 | // return t.Header |
| 356 | // return Header{ |
| 357 | // Padding: true, |
| 358 | // Count: FormatTCC, |
| 359 | // Type: TypeTCCTransportSpecificFeedback, |
| 360 | // // https://tools.ietf.org/html/rfc4585#page-33 |
| 361 | // Length: uint16((t.len() / 4) - 1), |
| 362 | // } |
| 363 | // } |
| 364 | |
| 365 | func (t *TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) packetLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#packetLen().() uint16 { |
| 366 | //nolint:gocognit,cyclop |
| 367 | n := uint16(headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset. + len(t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks.)*2) //nolint:gosec // G115 |
| 368 | for _, d := range t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. { |
| 369 | if d.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. { |
| 370 | n++ |
| 371 | } else { |
| 372 | n += 2 |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return n |
| 377 | } |
| 378 | |
| 379 | // Len return total bytes with padding. |
| 380 | func (t *TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) Lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Len().() uint16 { |
| 381 | return uint16(t.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MarshalSize().()) //nolint:gosec // G115 |
| 382 | } |
| 383 | |
| 384 | // MarshalSize returns the size of the packet once marshaled. |
| 385 | func (t *TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MarshalSize().() int { |
| 386 | n := t.packetLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#packetLen().() |
| 387 | // has padding |
| 388 | if n%4 != 0 { |
| 389 | n = (n/4 + 1) * 4 |
| 390 | } |
| 391 | |
| 392 | return int(n) |
| 393 | } |
| 394 | |
| 395 | func (t TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#String().() string { |
| 396 | var out stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder# |
| 397 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "TransportLayerCC:\n\tHeader %v\n", t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header.) |
| 398 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "TransportLayerCC:\n\tSender Ssrc %d\n", t.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#SenderSSRC.) |
| 399 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "\tMedia Ssrc %d\n", t.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MediaSSRC.) |
| 400 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "\tBase Sequence Number %d\n", t.BaseSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#BaseSequenceNumber.) |
| 401 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "\tStatus Count %d\n", t.PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount.) |
| 402 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "\tReference Time %d\n", t.ReferenceTimescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#ReferenceTime.) |
| 403 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "\tFeedback Packet Count %d\n", t.FbPktCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#FbPktCount.) |
| 404 | out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\tPacketChunks ") |
| 405 | for _, chunk := range t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks. { |
| 406 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "%+v ", chunk) |
| 407 | } |
| 408 | out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\n\tRecvDeltas ") |
| 409 | for _, delta := range t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. { |
| 410 | fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.24.0 fmt/Fprintf().(&out, "%+v ", delta) |
| 411 | } |
| 412 | out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\n") |
| 413 | |
| 414 | return out.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().() |
| 415 | } |
| 416 | |
| 417 | // Marshal encodes the TransportLayerCC in binary. |
| 418 | func (t TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Marshal().() ([]byte, error) { |
| 419 | header, err := t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Marshal().() |
| 420 | if err != nil { |
| 421 | return nil, err |
| 422 | } |
| 423 | |
| 424 | payload := make([]byte, t.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MarshalSize().()-headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.) |
| 425 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(payload, t.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#SenderSSRC.) |
| 426 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(payload[4:], t.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MediaSSRC.) |
| 427 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint16().(payload[baseSequenceNumberOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/baseSequenceNumberOffset.:], t.BaseSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#BaseSequenceNumber.) |
| 428 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint16().(payload[packetStatusCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusCountOffset.:], t.PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount.) |
| 429 | ReferenceTimeAndFbPktCount := appendNBitsToUint32scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/appendNBitsToUint32().(0, 24, t.ReferenceTimescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#ReferenceTime.) |
| 430 | ReferenceTimeAndFbPktCount = appendNBitsToUint32scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/appendNBitsToUint32().(ReferenceTimeAndFbPktCount, 8, uint32(t.FbPktCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#FbPktCount.)) |
| 431 | binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..PutUint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#PutUint32().(payload[referenceTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/referenceTimeOffset.:], ReferenceTimeAndFbPktCount) |
| 432 | |
| 433 | for i, chunk := range t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks. { |
| 434 | b, err := chunk.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk#Marshal.() |
| 435 | if err != nil { |
| 436 | return nil, err |
| 437 | } |
| 438 | copy(payload[packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset.+i*2:], b) |
| 439 | } |
| 440 | |
| 441 | recvDeltaOffset := packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset. + len(t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks.)*2 |
| 442 | var i int |
| 443 | for _, delta := range t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. { |
| 444 | b, err := delta.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Marshal().() |
| 445 | if err == nil { |
| 446 | copy(payload[recvDeltaOffset+i:], b) |
| 447 | i++ |
| 448 | if delta.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. { |
| 449 | i++ |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | if t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Paddingscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Padding. { |
| 455 | payload[len(payload)-1] = uint8(t.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MarshalSize().() - int(t.packetLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#packetLen().())) //nolint:gosec // G115 |
| 456 | } |
| 457 | |
| 458 | return append(header, payload...), nil |
| 459 | } |
| 460 | |
| 461 | // Unmarshal .. |
| 462 | // |
| 463 | //nolint:gocognit,cyclop |
| 464 | func (t *TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Unmarshal().(rawPacket []byte) error { |
| 465 | if len(rawPacket) < (headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength.) { |
| 466 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 467 | } |
| 468 | |
| 469 | if err := t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil { |
| 470 | return err |
| 471 | } |
| 472 | |
| 473 | // https://tools.ietf.org/html/rfc4585#page-33 |
| 474 | // header's length + payload's length |
| 475 | totalLength := 4 * (int(t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.) + 1) |
| 476 | |
| 477 | if totalLength < headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset. { |
| 478 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 479 | } |
| 480 | |
| 481 | if len(rawPacket) < totalLength { |
| 482 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 483 | } |
| 484 | |
| 485 | if t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type. != TypeTransportSpecificFeedbackscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTransportSpecificFeedback. || t.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#Header..Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count. != FormatTCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatTCC. { |
| 486 | return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType. |
| 487 | } |
| 488 | |
| 489 | t.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#SenderSSRC. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint32().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:]) |
| 490 | t.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MediaSSRC. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint32scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint32().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+ssrcLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcLength.:]) |
| 491 | t.BaseSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#BaseSequenceNumber. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint16().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+baseSequenceNumberOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/baseSequenceNumberOffset.:]) |
| 492 | t.PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount. = binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/.BigEndianscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/BigEndian..Uint16scip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/bigEndian#Uint16().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+packetStatusCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusCountOffset.:]) |
| 493 | t.ReferenceTimescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#ReferenceTime. = get24BitsFromBytesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/get24BitsFromBytes().(rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+referenceTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/referenceTimeOffset. : headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+referenceTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/referenceTimeOffset.+3]) |
| 494 | t.FbPktCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#FbPktCount. = rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.+fbPktCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/fbPktCountOffset.] |
| 495 | |
| 496 | packetStatusPos := int(headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + packetChunkOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetChunkOffset.) |
| 497 | var processedPacketNum uint16 |
| 498 | for processedPacketNum < t.PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount. { |
| 499 | if packetStatusPos+packetStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusChunkLength. >= totalLength { |
| 500 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 501 | } |
| 502 | typ := getNBitsFromBytescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getNBitsFromByte().(rawPacket[packetStatusPos : packetStatusPos+1][0], 0, 1) |
| 503 | var iPacketStatus PacketStatusChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PacketStatusChunk# |
| 504 | switch typ { |
| 505 | case TypeTCCRunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCRunLengthChunk.: |
| 506 | packetStatus := &RunLengthChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#{Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Type.: typ} |
| 507 | iPacketStatus = packetStatus |
| 508 | err := packetStatus.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#Unmarshal().(rawPacket[packetStatusPos : packetStatusPos+2]) |
| 509 | if err != nil { |
| 510 | return err |
| 511 | } |
| 512 | |
| 513 | packetNumberToProcess := localMinscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/localMin().(t.PacketStatusCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketStatusCount.-processedPacketNum, packetStatus.RunLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#RunLength.) |
| 514 | if packetStatus.PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol. == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. || |
| 515 | packetStatus.PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol. == TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. { |
| 516 | for range packetNumberToProcess { |
| 517 | t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. = append(t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas., &RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#{Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type.: packetStatus.PacketStatusSymbolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RunLengthChunk#PacketStatusSymbol.}) |
| 518 | } |
| 519 | } |
| 520 | processedPacketNum += packetNumberToProcess |
| 521 | case TypeTCCStatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCStatusVectorChunk.: |
| 522 | packetStatus := &StatusVectorChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#{Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Type.: typ} |
| 523 | iPacketStatus = packetStatus |
| 524 | err := packetStatus.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#Unmarshal().(rawPacket[packetStatusPos : packetStatusPos+2]) |
| 525 | if err != nil { |
| 526 | return err |
| 527 | } |
| 528 | if packetStatus.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. == TypeTCCSymbolSizeOneBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeOneBit. { |
| 529 | for j := 0; j < len(packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.); j++ { |
| 530 | if packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.[j] == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. { |
| 531 | t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. = append(t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas., &RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#{Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type.: TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta.}) |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | if packetStatus.SymbolSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolSize. == TypeTCCSymbolSizeTwoBitscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCSymbolSizeTwoBit. { |
| 536 | for j := 0; j < len(packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.); j++ { |
| 537 | if packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.[j] == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. || |
| 538 | packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.[j] == TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. { |
| 539 | t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. = append(t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas., &RecvDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#{Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type.: packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.[j]}) |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | processedPacketNum += uint16(len(packetStatus.SymbolListscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/StatusVectorChunk#SymbolList.)) //nolint:gosec // G115 |
| 544 | } |
| 545 | packetStatusPos += packetStatusChunkLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/packetStatusChunkLength. |
| 546 | t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks. = append(t.PacketChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#PacketChunks., iPacketStatus) |
| 547 | } |
| 548 | |
| 549 | recvDeltasPos := packetStatusPos |
| 550 | for _, delta := range t.RecvDeltasscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#RecvDeltas. { |
| 551 | if delta.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedSmallDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedSmallDelta. { |
| 552 | if recvDeltasPos+1 > totalLength { |
| 553 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 554 | } |
| 555 | err := delta.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Unmarshal().(rawPacket[recvDeltasPos : recvDeltasPos+1]) |
| 556 | if err != nil { |
| 557 | return err |
| 558 | } |
| 559 | recvDeltasPos++ |
| 560 | } |
| 561 | if delta.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Type. == TypeTCCPacketReceivedLargeDeltascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeTCCPacketReceivedLargeDelta. { |
| 562 | if recvDeltasPos+2 > totalLength { |
| 563 | return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort. |
| 564 | } |
| 565 | err := delta.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RecvDelta#Unmarshal().(rawPacket[recvDeltasPos : recvDeltasPos+2]) |
| 566 | if err != nil { |
| 567 | return err |
| 568 | } |
| 569 | recvDeltasPos += 2 |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | return nil |
| 574 | } |
| 575 | |
| 576 | // DestinationSSRC returns an array of SSRC values that this packet refers to. |
| 577 | func (t TransportLayerCCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#DestinationSSRC().() []uint32 { |
| 578 | return []uint32{t.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TransportLayerCC#MediaSSRC.} |
| 579 | } |
| 580 | |
| 581 | func localMinscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/localMin().(x, y uint16) uint16 { |
| 582 | if x < y { |
| 583 | return x |
| 584 | } |
| 585 | |
| 586 | return y |
| 587 | } |