Skip to content

Commit

Permalink
Fix wrap around on out of order packet
Browse files Browse the repository at this point in the history
Sequence number cycle calculation was over estimating the cycles
if packets came out of order. A sequence like 65535, 0, 65534 would
increment the cycle counter twice.
  • Loading branch information
boks1971 committed Oct 16, 2023
1 parent f918c62 commit 2d3d6ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/report/receiver_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func TestReceiverInterceptor(t *testing.T) {
SequenceNumber: 0x00,
}})

stream.ReceiveRTP(&rtp.Packet{Header: rtp.Header{
SequenceNumber: 0xfffe,
}})

pkts := <-stream.WrittenRTCP()
assert.Equal(t, len(pkts), 1)
rr, ok := pkts[0].(*rtcp.ReceiverReport)
Expand Down
8 changes: 4 additions & 4 deletions pkg/report/receiver_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func (stream *receiverStream) processRTP(now time.Time, pktHeader *rtp.Header) {
} else { // following frames
stream.setReceived(pktHeader.SequenceNumber)

diff := int32(pktHeader.SequenceNumber) - int32(stream.lastSeqnum)
if diff > 0 || diff < -0x0FFF {
// overflow
if diff < -0x0FFF {
diff := pktHeader.SequenceNumber - stream.lastSeqnum
if diff > 0 && diff < (1<<15) {
// wrap around
if pktHeader.SequenceNumber < stream.lastSeqnum {
stream.seqnumCycles++
}

Expand Down

0 comments on commit 2d3d6ab

Please sign in to comment.