Skip to content

Commit 6d35fb4

Browse files
committed
jitterbuffer: Improve performance
Rework the jitterbuffer for SampleBuilder use
1 parent 6c28872 commit 6d35fb4

File tree

6 files changed

+909
-343
lines changed

6 files changed

+909
-343
lines changed

pkg/jitterbuffer/jitter_buffer.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type (
6666
// order, and allows removing in either sequence number order or via a
6767
// provided timestamp.
6868
type JitterBuffer struct {
69-
packets *PriorityQueue
69+
packets *RBTree
7070
minStartCount uint16
7171
overflowLen uint16
7272
lastSequence uint16
@@ -132,6 +132,7 @@ func (jb *JitterBuffer) PlayoutHead() uint16 {
132132
return jb.playoutHead
133133
}
134134

135+
// Length returns the current number of packets in the buffer
135136
func (jb *JitterBuffer) Length() uint16 {
136137
jb.mutex.Lock()
137138
defer jb.mutex.Unlock()
@@ -177,7 +178,7 @@ func (jb *JitterBuffer) Push(packet *rtp.Packet) {
177178
}
178179

179180
jb.updateStats(packet.SequenceNumber)
180-
jb.packets.Push(packet, packet.SequenceNumber)
181+
jb.packets.Push(packet)
181182
jb.updateState()
182183
}
183184

@@ -259,8 +260,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
259260
// PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence
260261
// without removing it from the buffer.
261262
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
262-
jb.mutex.Lock()
263-
defer jb.mutex.Unlock()
264263
packet, err := jb.packets.Find(sq)
265264
if err != nil {
266265
return nil, err

pkg/jitterbuffer/jitter_buffer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func TestJitterBuffer(t *testing.T) {
132132
assert.Equal(jb.packets.Length(), uint16(100))
133133
assert.Equal(jb.state, Emitting)
134134
head, err := jb.PopAtTimestamp(uint32(513))
135+
assert.NotNil(head)
135136
assert.Equal(head.SequenceNumber, uint16(math.MaxUint16-32+1))
136137
assert.Equal(err, nil)
137138
head, err = jb.PopAtTimestamp(uint32(513))

0 commit comments

Comments
 (0)