@@ -53,28 +53,37 @@ type Packet struct {
53
53
}
54
54
55
55
const (
56
- headerLength = 4
57
- versionShift = 6
58
- versionMask = 0x3
59
- paddingShift = 5
60
- paddingMask = 0x1
61
- extensionShift = 4
62
- extensionMask = 0x1
63
- extensionProfileOneByte = 0xBEDE
64
- extensionProfileTwoByte = 0x1000
65
- extensionIDReserved = 0xF
66
- ccMask = 0xF
67
- markerShift = 7
68
- markerMask = 0x1
69
- ptMask = 0x7F
70
- seqNumOffset = 2
71
- seqNumLength = 2
72
- timestampOffset = 4
73
- timestampLength = 4
74
- ssrcOffset = 8
75
- ssrcLength = 4
76
- csrcOffset = 12
77
- csrcLength = 4
56
+ // ExtensionProfileOneByte is the RTP One Byte Header Extension Profile, defined in RFC 8285.
57
+ ExtensionProfileOneByte = 0xBEDE
58
+ // ExtensionProfileTwoByte is the RTP Two Byte Header Extension Profile, defined in RFC 8285.
59
+ ExtensionProfileTwoByte = 0x1000
60
+ // CryptexProfileOneByte is the Cryptex One Byte Header Extension Profile, defined in RFC 9335.
61
+ CryptexProfileOneByte = 0xC0DE
62
+ // CryptexProfileTwoByte is the Cryptex Two Byte Header Extension Profile, defined in RFC 9335.
63
+ CryptexProfileTwoByte = 0xC2DE
64
+ )
65
+
66
+ const (
67
+ headerLength = 4
68
+ versionShift = 6
69
+ versionMask = 0x3
70
+ paddingShift = 5
71
+ paddingMask = 0x1
72
+ extensionShift = 4
73
+ extensionMask = 0x1
74
+ extensionIDReserved = 0xF
75
+ ccMask = 0xF
76
+ markerShift = 7
77
+ markerMask = 0x1
78
+ ptMask = 0x7F
79
+ seqNumOffset = 2
80
+ seqNumLength = 2
81
+ timestampOffset = 4
82
+ timestampLength = 4
83
+ ssrcOffset = 8
84
+ ssrcLength = 4
85
+ csrcOffset = 12
86
+ csrcLength = 4
78
87
)
79
88
80
89
// String helps with debugging by printing packet information in a readable way.
@@ -164,7 +173,7 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit,cy
164
173
return n , fmt .Errorf ("size %d < %d: %w" , len (buf ), extensionEnd , errHeaderSizeInsufficientForExtension )
165
174
}
166
175
167
- if h .ExtensionProfile == extensionProfileOneByte || h .ExtensionProfile == extensionProfileTwoByte {
176
+ if h .ExtensionProfile == ExtensionProfileOneByte || h .ExtensionProfile == ExtensionProfileTwoByte {
168
177
var (
169
178
extid uint8
170
179
payloadLen int
@@ -177,7 +186,7 @@ func (h *Header) Unmarshal(buf []byte) (n int, err error) { //nolint:gocognit,cy
177
186
continue
178
187
}
179
188
180
- if h .ExtensionProfile == extensionProfileOneByte {
189
+ if h .ExtensionProfile == ExtensionProfileOneByte {
181
190
extid = buf [n ] >> 4
182
191
payloadLen = int (buf [n ]&^0xF0 + 1 )
183
192
n ++
@@ -312,14 +321,14 @@ func (h Header) MarshalTo(buf []byte) (n int, err error) { //nolint:cyclop
312
321
313
322
switch h .ExtensionProfile {
314
323
// RFC 8285 RTP One Byte Header Extension
315
- case extensionProfileOneByte :
324
+ case ExtensionProfileOneByte :
316
325
for _ , extension := range h .Extensions {
317
326
buf [n ] = extension .id << 4 | (uint8 (len (extension .payload )) - 1 ) // nolint: gosec // G115
318
327
n ++
319
328
n += copy (buf [n :], extension .payload )
320
329
}
321
330
// RFC 8285 RTP Two Byte Header Extension
322
- case extensionProfileTwoByte :
331
+ case ExtensionProfileTwoByte :
323
332
for _ , extension := range h .Extensions {
324
333
buf [n ] = extension .id
325
334
n ++
@@ -363,12 +372,12 @@ func (h Header) MarshalSize() int {
363
372
364
373
switch h .ExtensionProfile {
365
374
// RFC 8285 RTP One Byte Header Extension
366
- case extensionProfileOneByte :
375
+ case ExtensionProfileOneByte :
367
376
for _ , extension := range h .Extensions {
368
377
extSize += 1 + len (extension .payload )
369
378
}
370
379
// RFC 8285 RTP Two Byte Header Extension
371
- case extensionProfileTwoByte :
380
+ case ExtensionProfileTwoByte :
372
381
for _ , extension := range h .Extensions {
373
382
extSize += 2 + len (extension .payload )
374
383
}
@@ -388,15 +397,15 @@ func (h *Header) SetExtension(id uint8, payload []byte) error { //nolint:gocogni
388
397
if h .Extension { // nolint: nestif
389
398
switch h .ExtensionProfile {
390
399
// RFC 8285 RTP One Byte Header Extension
391
- case extensionProfileOneByte :
400
+ case ExtensionProfileOneByte :
392
401
if id < 1 || id > 14 {
393
402
return fmt .Errorf ("%w actual(%d)" , errRFC8285OneByteHeaderIDRange , id )
394
403
}
395
404
if len (payload ) > 16 {
396
405
return fmt .Errorf ("%w actual(%d)" , errRFC8285OneByteHeaderSize , len (payload ))
397
406
}
398
407
// RFC 8285 RTP Two Byte Header Extension
399
- case extensionProfileTwoByte :
408
+ case ExtensionProfileTwoByte :
400
409
if id < 1 {
401
410
return fmt .Errorf ("%w actual(%d)" , errRFC8285TwoByteHeaderIDRange , id )
402
411
}
@@ -428,9 +437,9 @@ func (h *Header) SetExtension(id uint8, payload []byte) error { //nolint:gocogni
428
437
429
438
switch payloadLen := len (payload ); {
430
439
case payloadLen <= 16 :
431
- h .ExtensionProfile = extensionProfileOneByte
440
+ h .ExtensionProfile = ExtensionProfileOneByte
432
441
case payloadLen > 16 && payloadLen < 256 :
433
- h .ExtensionProfile = extensionProfileTwoByte
442
+ h .ExtensionProfile = ExtensionProfileTwoByte
434
443
}
435
444
436
445
h .Extensions = append (h .Extensions , Extension {id : id , payload : payload })
0 commit comments