Skip to content

Commit

Permalink
Drop initial incomplete packets (#597)
Browse files Browse the repository at this point in the history
* drop initial incomplete packets

* simplify, fix test

* fix tail when last head is dropped before initialization
  • Loading branch information
frostbyte73 authored Jan 17, 2025
1 parent d0bd4b8 commit 67a3d4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion pkg/jitter/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ func (b *Buffer) Push(pkt *rtp.Packet) {
outsidePrevRange := outsideRange(pkt.SequenceNumber, b.prevSN)

if !b.initialized {
if p.start && (b.head == nil || before16(pkt.SequenceNumber, b.head.packet.SequenceNumber)) {
if p.start {
for {
if b.head != nil && before16(b.head.packet.SequenceNumber, pkt.SequenceNumber) {
// drop packet
b.head = b.head.next
if b.head == nil {
b.tail = nil
}
} else {
break
}
}

// initialize on the first start packet
b.initialized = true
b.prevSN = pkt.SequenceNumber - 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/jitter/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestJitterBuffer(t *testing.T) {
require.Len(t, b.Pop(false), 0)

b.Push(testPacket(3, 31))
b.Push(testHeadPacket(6, 32))
b.Push(testHeadPacket(1, 31))
b.Push(testHeadPacket(6, 32))

require.Len(t, b.Pop(false), 0)

Expand Down

0 comments on commit 67a3d4b

Please sign in to comment.