Debian Codegraph @

source_description.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 "fmtscip-go gomod github.com/golang/go/src go1.24.0 fmt/"
9 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
10 )
11
12 // SDESType is the item type used in the RTCP SDES control packet.
13 type SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType# uint8
14
15 // RTP SDES item types registered with IANA.
16 // See: https://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml#rtp-parameters-5
17 // .
18 const (
19 SDESEndscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEnd. SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType# = iota // end of SDES list RFC 3550, 6.5
20 SDESCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESCNAME. // canonical name RFC 3550, 6.5.1
21 SDESNamescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESName. // user name RFC 3550, 6.5.2
22 SDESEmailscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEmail. // user's electronic mail address RFC 3550, 6.5.3
23 SDESPhonescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESPhone. // user's phone number RFC 3550, 6.5.4
24 SDESLocationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESLocation. // geographic user location RFC 3550, 6.5.5
25 SDESToolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESTool. // name of application or tool RFC 3550, 6.5.6
26 SDESNotescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESNote. // notice about the source RFC 3550, 6.5.7
27 SDESPrivatescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESPrivate. // private extensions RFC 3550, 6.5.8 (not implemented)
28 )
29
30 //nolint:cyclop
31 func (s SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType#String().() string {
32 switch s {
33 case SDESEndscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEnd.:
34 return "END"
35 case SDESCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESCNAME.:
36 return "CNAME"
37 case SDESNamescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESName.:
38 return "NAME"
39 case SDESEmailscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEmail.:
40 return "EMAIL"
41 case SDESPhonescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESPhone.:
42 return "PHONE"
43 case SDESLocationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESLocation.:
44 return "LOC"
45 case SDESToolscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESTool.:
46 return "TOOL"
47 case SDESNotescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESNote.:
48 return "NOTE"
49 case SDESPrivatescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESPrivate.:
50 return "PRIV"
51 default:
52 return string(s)
53 }
54 }
55
56 const (
57 sdesSourceLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesSourceLen. = 4
58 sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen. = 1
59 sdesTypeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeOffset. = 0
60 sdesOctetCountLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountLen. = 1
61 sdesOctetCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountOffset. = 1
62 sdesMaxOctetCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesMaxOctetCount. = (1 << 8) - 1
63 sdesTextOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTextOffset. = 2
64 )
65
66 // A SourceDescription (SDES) packet describes the sources in an RTP stream.
67 type SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription# struct {
68 Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. []SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#
69 }
70
71 // NewCNAMESourceDescription creates a new SourceDescription with a single CNAME item.
72 func NewCNAMESourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/NewCNAMESourceDescription().(ssrc uint32, cname string) *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription# {
73 return &SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#{
74 Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks.: []SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#{{
75 Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source.: ssrc,
76 Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items.: []SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#{{
77 Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Type.: SDESCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESCNAME.,
78 Textscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Text.: cname,
79 }},
80 }},
81 }
82 }
83
84 // Marshal encodes the SourceDescription in binary.
85 func (s SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Marshal().() ([]byte, error) {
86 /*
87 * 0 1 2 3
88 * 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
89 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
90 * header |V=2|P| SC | PT=SDES=202 | length |
91 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
92 * chunk | SSRC/CSRC_1 |
93 * 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 * | SDES items |
95 * | ... |
96 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
97 * chunk | SSRC/CSRC_2 |
98 * 2 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
99 * | SDES items |
100 * | ... |
101 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
102 */
103
104 rawPacket := make([]byte, s.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#MarshalSize().())
105 packetBody := rawPacket[headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.:]
106
107 chunkOffset := 0
108 for _, c := range s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. {
109 data, err := c.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Marshal().()
110 if err != nil {
111 return nil, err
112 }
113 copy(packetBody[chunkOffset:], data)
114 chunkOffset += len(data)
115 }
116
117 if len(s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks.) > countMaxscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/countMax. {
118 return nil, errTooManyChunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errTooManyChunks.
119 }
120
121 hData, err := s.Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Header().().Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Marshal().()
122 if err != nil {
123 return nil, err
124 }
125 copy(rawPacket, hData)
126
127 return rawPacket, nil
128 }
129
130 // Unmarshal decodes the SourceDescription from binary.
131 func (s *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Unmarshal().(rawPacket []byte) error {
132 /*
133 * 0 1 2 3
134 * 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
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 * header |V=2|P| SC | PT=SDES=202 | length |
137 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
138 * chunk | SSRC/CSRC_1 |
139 * 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * | SDES items |
141 * | ... |
142 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
143 * chunk | SSRC/CSRC_2 |
144 * 2 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145 * | SDES items |
146 * | ... |
147 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
148 */
149
150 var header Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#
151 if err := header.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Unmarshal().(rawPacket); err != nil {
152 return err
153 }
154
155 if header.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type. != TypeSourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeSourceDescription. {
156 return errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType.
157 }
158
159 for i := headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength.; i < len(rawPacket); {
160 var chunk SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#
161 if err := chunk.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Unmarshal().(rawPacket[i:]); err != nil {
162 return err
163 }
164 s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. = append(s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks., chunk)
165
166 i += chunk.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#len().()
167 }
168
169 if len(s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks.) != int(header.Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.) {
170 return errInvalidHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errInvalidHeader.
171 }
172
173 return nil
174 }
175
176 // MarshalSize returns the size of the packet once marshaled.
177 func (s *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#MarshalSize().() int {
178 chunksLength := 0
179 for _, c := range s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. {
180 chunksLength += c.lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#len().()
181 }
182
183 return headerLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/headerLength. + chunksLength
184 }
185
186 // Header returns the Header associated with this packet.
187 func (s *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Header().() Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header# {
188 return Headerscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#{
189 Countscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Count.: uint8(len(s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks.)), //nolint:gosec // G115
190 Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Type.: TypeSourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TypeSourceDescription.,
191 Lengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Header#Length.: uint16((s.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#MarshalSize().() / 4) - 1), //nolint:gosec // G115
192 }
193 }
194
195 // A SourceDescriptionChunk contains items describing a single RTP source.
196 type SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk# struct {
197 // The source (ssrc) or contributing source (csrc) identifier this packet describes
198 Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source. uint32
199 Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items. []SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#
200 }
201
202 // Marshal encodes the SourceDescriptionChunk in binary.
203 func (s SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Marshal().() ([]byte, error) {
204 /*
205 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
206 * | SSRC/CSRC_1 |
207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * | SDES items |
209 * | ... |
210 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
211 */
212
213 rawPacket := make([]byte, sdesSourceLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesSourceLen.)
214 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().(rawPacket, s.Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source.)
215
216 for _, it := range s.Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items. {
217 data, err := it.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Marshal().()
218 if err != nil {
219 return nil, err
220 }
221 rawPacket = append(rawPacket, data...) //nolint:makezero
222 }
223
224 // The list of items in each chunk MUST be terminated by one or more null octets
225 rawPacket = append(rawPacket, uint8(SDESEndscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEnd.)) //nolint:makezero
226
227 // additional null octets MUST be included if needed to pad until the next 32-bit boundary
228 rawPacket = append(rawPacket, make([]byte, getPaddingscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getPadding().(len(rawPacket)))...) //nolint:makezero
229
230 return rawPacket, nil
231 }
232
233 // Unmarshal decodes the SourceDescriptionChunk from binary.
234 func (s *SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Unmarshal().(rawPacket []byte) error {
235 /*
236 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
237 * | SSRC/CSRC_1 |
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239 * | SDES items |
240 * | ... |
241 * +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
242 */
243
244 if len(rawPacket) < (sdesSourceLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesSourceLen. + sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen.) {
245 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
246 }
247
248 s.Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source. = 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)
249
250 for i := 4; i < len(rawPacket); {
251 if pktType := SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType#(rawPacket[i]); pktType == SDESEndscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEnd. {
252 return nil
253 }
254
255 var it SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#
256 if err := it.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Unmarshal().(rawPacket[i:]); err != nil {
257 return err
258 }
259 s.Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items. = append(s.Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items., it)
260 i += it.Lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Len().()
261 }
262
263 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
264 }
265
266 func (s SourceDescriptionChunkscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#) lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#len().() int {
267 chunkLen := sdesSourceLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesSourceLen.
268 for _, it := range s.Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items. {
269 chunkLen += it.Lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Len().()
270 }
271 chunkLen += sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen. // for terminating null octet
272
273 // align to 32-bit boundary
274 chunkLen += getPaddingscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/getPadding().(chunkLen)
275
276 return chunkLen
277 }
278
279 // A SourceDescriptionItem is a part of a SourceDescription that describes a stream.
280 type SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem# struct {
281 // The type identifier for this item. eg, SDESCNAME for canonical name description.
282 //
283 // Type zero or SDESEnd is interpreted as the end of an item list and cannot be used.
284 Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Type. SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType#
285 // Text is a unicode text blob associated with the item. Its meaning varies based on the item's Type.
286 Textscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Text. string
287 }
288
289 // Len returns the length of the SourceDescriptionItem when encoded as binary.
290 func (s SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#) Lenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Len().() int {
291 /*
292 * 0 1 2 3
293 * 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
294 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295 * | CNAME=1 | length | user and domain name ...
296 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297 */
298 return sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen. + sdesOctetCountLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountLen. + len([]byte(s.Textscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Text.))
299 }
300
301 // Marshal encodes the SourceDescriptionItem in binary.
302 func (s SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#) Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Marshal().() ([]byte, error) {
303 /*
304 * 0 1 2 3
305 * 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
306 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
307 * | CNAME=1 | length | user and domain name ...
308 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
309 */
310
311 if s.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Type. == SDESEndscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESEnd. {
312 return nil, errSDESMissingTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errSDESMissingType.
313 }
314
315 rawPacket := make([]byte, sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen.+sdesOctetCountLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountLen.)
316
317 rawPacket[sdesTypeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeOffset.] = uint8(s.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Type.) //nolint:gosec // rawPacket is created with length 2
318
319 txtBytes := []byte(s.Textscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Text.)
320 octetCount := len(txtBytes)
321 if octetCount > sdesMaxOctetCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesMaxOctetCount. {
322 return nil, errSDESTextTooLongscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errSDESTextTooLong.
323 }
324 rawPacket[sdesOctetCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountOffset.] = uint8(octetCount) //nolint:gosec // rawPacket is created with length 2
325
326 rawPacket = append(rawPacket, txtBytes...) //nolint:makezero
327
328 return rawPacket, nil
329 }
330
331 // Unmarshal decodes the SourceDescriptionItem from binary.
332 func (s *SourceDescriptionItemscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#) Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Unmarshal().(rawPacket []byte) error {
333 /*
334 * 0 1 2 3
335 * 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
336 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
337 * | CNAME=1 | length | user and domain name ...
338 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
339 */
340
341 if len(rawPacket) < (sdesTypeLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeLen. + sdesOctetCountLenscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountLen.) {
342 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
343 }
344
345 s.Typescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Type. = SDESTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SDESType#(rawPacket[sdesTypeOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTypeOffset.])
346
347 octetCount := int(rawPacket[sdesOctetCountOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesOctetCountOffset.])
348 if sdesTextOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTextOffset.+octetCount > len(rawPacket) {
349 return errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.
350 }
351
352 txtBytes := rawPacket[sdesTextOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTextOffset. : sdesTextOffsetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesTextOffset.+octetCount]
353 s.Textscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionItem#Text. = string(txtBytes)
354
355 return nil
356 }
357
358 // DestinationSSRC returns an array of SSRC values that this packet refers to.
359 func (s *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) DestinationSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#DestinationSSRC().() []uint32 {
360 out := make([]uint32, len(s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks.))
361 for i, v := range s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. {
362 out[i] = v.Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source.
363 }
364
365 return out
366 }
367
368 func (s *SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#) Stringscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#String().() string {
369 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#
370 out.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("Source Description:\n")
371 for _, c := range s.Chunksscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#Chunks. {
372 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, "\t%x: %s\n", c.Sourcescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Source., c.Itemsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescriptionChunk#Items.)
373 }
374
375 return out.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().()
376 }