Debian Codegraph @

rfc8888.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 "encoding/binaryscip-go gomod github.com/golang/go/src go1.24.0 `encoding/binary`/"
8 "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/"
9 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
10 "mathscip-go gomod github.com/golang/go/src go1.24.0 math/"
11 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
12 )
13
14 // https://www.rfc-editor.org/rfc/rfc8888.html#name-rtcp-congestion-control-fee
15 // 0 1 2 3
16 // 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
17 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
18 // |V=2|P| FMT=11 | PT = 205 | length |
19 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20 // | SSRC of RTCP packet sender |
21 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 // | SSRC of 1st RTP Stream |
23 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 // | begin_seq | num_reports |
25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26 // |R|ECN| Arrival time offset | ... .
27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 // . .
29 // . .
30 // . .
31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 // | SSRC of nth RTP Stream |
33 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 // | begin_seq | num_reports |
35 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 // |R|ECN| Arrival time offset | ... |
37 // . .
38 // . .
39 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 // | Report Timestamp (32 bits) |
41 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42
43 var (
44 errReportBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errReportBlockLength. = 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().("feedback report blocks must be at least 8 bytes")
45 errIncorrectNumReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errIncorrectNumReports. = 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().("feedback report block contains less reports than num_reports")
46 errMetricBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMetricBlockLength. = 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().("feedback report metric blocks must be exactly 2 bytes")
47 )
48
49 // ECN represents the two ECN bits.
50 type ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN# uint8
51
52 const (
53 //nolint:misspell
54 // ECNNonECT signals Non ECN-Capable Transport, Non-ECT.
55 ECNNonECTscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNNonECT. ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN# = iota // 00
56
57 //nolint:misspell
58 // ECNECT1 signals ECN Capable Transport, ECT(0).
59 ECNECT1scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNECT1. // 01
60
61 //nolint:misspell
62 // ECNECT0 signals ECN Capable Transport, ECT(1).
63 ECNECT0scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNECT0. // 10
64
65 // ECNCE signals ECN Congestion Encountered, CE.
66 ECNCEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNCE. // 11
67 )
68
69 func (e ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN#String().() string {
70 switch e {
71 case ECNNonECTscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNNonECT.:
72 //nolint:misspell
73 return "Non-ECT (00)"
74 case ECNECT0scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNECT0.:
75 //nolint:misspell
76 return "ECT(0) (01)"
77 case ECNECT1scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNECT1.:
78 //nolint:misspell
79 return "ECT(1) (10)"
80 case ECNCEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNCE.:
81 //nolint:misspell
82 return "CE (11)"
83 }
84
85 return "invalid ECN value"
86 }
87
88 const (
89 reportTimestampLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportTimestampLength. = 4
90 reportBlockOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportBlockOffset. = 8
91 )
92
93 // CCFeedbackReport is a Congestion Control Feedback Report as defined in
94 // https://www.rfc-editor.org/rfc/rfc8888.html#name-rtcp-congestion-control-fee
95 type CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport# struct {
96 // SSRC of sender
97 SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#SenderSSRC. uint32
98
99 // Report Blocks
100 ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. []CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#
101
102 // Basetime
103 ReportTimestampscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportTimestamp. uint32
104 }
105
106 // DestinationSSRC returns an array of SSRC values that this packet refers to.
107 func (b CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#DestinationSSRC().() []uint32 {
108 ssrcs := make([]uint32, len(b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks.))
109 for i, block := range b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. {
110 ssrcs[i] = block.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MediaSSRC.
111 }
112
113 return ssrcs
114 }
115
116 // Len returns the length of the report in bytes.
117 func (b *CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) Lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Len().() int {
118 return b.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#MarshalSize().()
119 }
120
121 // MarshalSize returns the size of the packet once marshaled.
122 func (b *CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#MarshalSize().() int {
123 n := 0
124 for _, block := range b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. {
125 n += block.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#len().()
126 }
127
128 return reportBlockOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportBlockOffset. + n + reportTimestampLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportTimestampLength.
129 }
130
131 // Header returns the Header associated with this packet.
132 func (b *CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Header().() Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# {
133 return Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{
134 Paddingscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Padding.: false,
135 Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: FormatCCFBscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/FormatCCFB.,
136 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.,
137 Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: uint16(b.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#MarshalSize().()/4 - 1), //nolint:gosec // G115
138 }
139 }
140
141 // Marshal encodes the Congestion Control Feedback Report in binary.
142 func (b CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Marshal().() ([]byte, error) {
143 header := b.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Header().()
144 headerBuf, err := header.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Marshal().()
145 if err != nil {
146 return nil, err
147 }
148 length := 4 * (int(header.Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.) + 1)
149 buf := make([]byte, length)
150 copy(buf[:headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.], headerBuf)
151 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().(buf[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:], b.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#SenderSSRC.)
152 offset := reportBlockOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportBlockOffset.
153 for _, block := range b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. {
154 b, err := block.marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#marshal().()
155 if err != nil {
156 return nil, err
157 }
158 copy(buf[offset:], b)
159 offset += block.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#len().()
160 }
161
162 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().(buf[offset:], b.ReportTimestampscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportTimestamp.)
163
164 return buf, nil
165 }
166
167 func (b CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#String().() string {
168 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#
169 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, "CCFB:\n\tHeader %v\n", b.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Header().())
170 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, "CCFB:\n\tSender SSRC %d\n", b.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#SenderSSRC.)
171 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, "\tReport Timestamp %d\n", b.ReportTimestampscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportTimestamp.)
172 out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\tFeedback Reports \n")
173 for _, report := range b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. {
174 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 ", report)
175 }
176 out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\n")
177
178 return out.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().()
179 }
180
181 // Unmarshal decodes the Congestion Control Feedback Report from binary.
182 func (b *CCFeedbackReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#Unmarshal().(rawPacket []byte) error {
183 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.+reportTimestampLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportTimestampLength. {
184 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
185 }
186
187 var h Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#
188 if err := h.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil {
189 return err
190 }
191 if h.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. {
192 return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType.
193 }
194
195 b.SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#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.:])
196
197 reportTimestampOffset := len(rawPacket) - reportTimestampLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportTimestampLength.
198 b.ReportTimestampscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportTimestamp. = 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[reportTimestampOffset:])
199
200 offset := reportBlockOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportBlockOffset.
201 b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. = []CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#{}
202 for offset < reportTimestampOffset {
203 var block CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#
204 if err := block.unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#unmarshal().(rawPacket[offset:]); err != nil {
205 return err
206 }
207 b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks. = append(b.ReportBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReport#ReportBlocks., block)
208 offset += block.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#len().()
209 }
210
211 return nil
212 }
213
214 const (
215 ssrcOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcOffset. = 0
216 beginSequenceOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/beginSequenceOffset. = 4
217 numReportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numReportsOffset. = 6
218 reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset. = 8
219
220 maxMetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/maxMetricBlocks. = 16384
221 )
222
223 // CCFeedbackReportBlock is a Feedback Report Block.
224 type CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock# struct {
225 // SSRC of the RTP stream on which this block is reporting
226 MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MediaSSRC. uint32
227 BeginSequencescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#BeginSequence. uint16
228 MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks. []CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#
229 }
230
231 // len returns the length of the report block in bytes.
232 func (b *CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#) lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#len().() int {
233 n := len(b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks.)
234 if n%2 != 0 {
235 n++
236 }
237
238 return reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset. + 2*n
239 }
240
241 func (b CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#String().() string {
242 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#
243 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, "\tReport Block Media SSRC %d\n", b.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MediaSSRC.)
244 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, "\tReport Begin Sequence Nr %d\n", b.BeginSequencescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#BeginSequence.)
245 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, "\tReport length %d\n\t", len(b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks.))
246 for i, block := range b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks. {
247 //nolint:gosec // G115
248 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, "{nr: %d, rx: %v, ts: %v, ecn: %v} ",
249 b.BeginSequencescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#BeginSequence.+uint16(i),
250 block.Receivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#Received.,
251 block.ArrivalTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ArrivalTimeOffset.,
252 block.ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ECN.)
253 }
254 out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("\n")
255
256 return out.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().()
257 }
258
259 // marshal encodes the Congestion Control Feedback Report Block in binary.
260 func (b CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#) marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#marshal().() ([]byte, error) {
261 if len(b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks.) > maxMetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/maxMetricBlocks. {
262 return nil, errTooManyReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errTooManyReports.
263 }
264
265 buf := make([]byte, b.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#len().())
266 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().(buf[ssrcOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ssrcOffset.:], b.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MediaSSRC.)
267 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().(buf[beginSequenceOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/beginSequenceOffset.:], b.BeginSequencescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#BeginSequence.)
268
269 length := uint16(len(b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks.)) //nolint:gosec // G115
270
271 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().(buf[numReportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numReportsOffset.:], length)
272
273 for i, block := range b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks. {
274 b, err := block.marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#marshal().()
275 if err != nil {
276 return nil, err
277 }
278 copy(buf[reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset.+i*2:], b)
279 }
280
281 return buf, nil
282 }
283
284 // Unmarshal decodes the Congestion Control Feedback Report Block from binary.
285 func (b *CCFeedbackReportBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#) unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#unmarshal().(rawPacket []byte) error {
286 if len(rawPacket) < reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset. {
287 return errReportBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errReportBlockLength.
288 }
289 b.MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#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[:beginSequenceOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/beginSequenceOffset.])
290 b.BeginSequencescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#BeginSequence. = 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[beginSequenceOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/beginSequenceOffset.:numReportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numReportsOffset.])
291 numReports := int(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[numReportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/numReportsOffset.:]))
292 if numReports == 0 {
293 return nil
294 }
295
296 if numReports > mathscip-go gomod github.com/golang/go/src go1.24.0 math/.MaxUint16scip-go gomod github.com/golang/go/src go1.24.0 math/MaxUint16. {
297 return errIncorrectNumReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errIncorrectNumReports.
298 }
299
300 if len(rawPacket) < reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset.+numReports*2 {
301 return errIncorrectNumReportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errIncorrectNumReports.
302 }
303
304 b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks. = make([]CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#, numReports)
305 for i := range numReports {
306 var mb CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#
307 offset := reportsOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/reportsOffset. + 2*i
308 if err := mb.unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#unmarshal().(rawPacket[offset : offset+2]); err != nil {
309 return err
310 }
311 b.MetricBlocksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackReportBlock#MetricBlocks.[i] = mb
312 }
313
314 return nil
315 }
316
317 const (
318 metricBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/metricBlockLength. = 2
319 )
320
321 // CCFeedbackMetricBlock is a Feedback Metric Block.
322 type CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock# struct {
323 Receivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#Received. bool
324 ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ECN. ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN#
325
326 // Offset in 1/1024 seconds before Report Timestamp
327 ArrivalTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ArrivalTimeOffset. uint16
328 }
329
330 // Marshal encodes the Congestion Control Feedback Metric Block in binary.
331 func (b CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#) marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#marshal().() ([]byte, error) {
332 buf := make([]byte, 2)
333 r := uint16(0)
334 if b.Receivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#Received. {
335 r = 1
336 }
337 dst, err := setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(0, 1, 0, r)
338 if err != nil {
339 return nil, err
340 }
341 dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, 2, 1, uint16(b.ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ECN.))
342 if err != nil {
343 return nil, err
344 }
345 dst, err = setNBitsOfUint16scip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/setNBitsOfUint16().(dst, 13, 3, b.ArrivalTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ArrivalTimeOffset.)
346 if err != nil {
347 return nil, err
348 }
349
350 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().(buf, dst)
351
352 return buf, nil
353 }
354
355 // Unmarshal decodes the Congestion Control Feedback Metric Block from binary.
356 func (b *CCFeedbackMetricBlockscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#) unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#unmarshal().(rawPacket []byte) error {
357 if len(rawPacket) != metricBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/metricBlockLength. {
358 return errMetricBlockLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMetricBlockLength.
359 }
360 b.Receivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#Received. = rawPacket[0]&0x80 != 0
361 if !b.Receivedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#Received. {
362 b.ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ECN. = ECNNonECTscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECNNonECT.
363 b.ArrivalTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ArrivalTimeOffset. = 0
364
365 return nil
366 }
367 b.ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ECN. = ECNscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ECN#(rawPacket[0] >> 5 & 0x03)
368 b.ArrivalTimeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CCFeedbackMetricBlock#ArrivalTimeOffset. = 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) & 0x1FFF
369
370 return nil
371 }