Source File
sequencer.go
Belonging Package
github.com/pion/rtp
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage rtpimport ()// Sequencer generates sequential sequence numbers for building RTP packets.type Sequencer interface {NextSequenceNumber() uint16RollOverCount() uint64}// maxInitialRandomSequenceNumber is the maximum value used for the initial sequence// number when using NewRandomSequencer().// This uses only half the potential sequence number space to avoid issues decrypting// SRTP when the sequence number starts near the rollover and there is packet loss.// See https://webrtc-review.googlesource.com/c/src/+/358360const maxInitialRandomSequenceNumber = 1<<15 - 1// NewRandomSequencer returns a new sequencer starting from a random sequence// number.func () Sequencer {return &sequencer{sequenceNumber: uint16(globalMathRandomGenerator.Intn(maxInitialRandomSequenceNumber)), // nolint: gosec // G115}}// NewFixedSequencer returns a new sequencer starting from a specific// sequence number.func ( uint16) Sequencer {return &sequencer{sequenceNumber: - 1, // -1 because the first sequence number prepends 1}}type sequencer struct {sequenceNumber uint16rollOverCount uint64mutex sync.Mutex}// NextSequenceNumber increment and returns a new sequence number for// building RTP packets.func ( *sequencer) () uint16 {.mutex.Lock()defer .mutex.Unlock().sequenceNumber++if .sequenceNumber == 0 {.rollOverCount++}return .sequenceNumber}// RollOverCount returns the amount of times the 16bit sequence number// has wrapped.func ( *sequencer) () uint64 {.mutex.Lock()defer .mutex.Unlock()return .rollOverCount}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |