Skip to content

Commit 339f38e

Browse files
committed
jitterbuffer: Improve performance
Rework the jitterbuffer for SampleBuilder use
1 parent f37e752 commit 339f38e

File tree

5 files changed

+880
-321
lines changed

5 files changed

+880
-321
lines changed

pkg/jitterbuffer/jitter_buffer.go

Lines changed: 1 addition & 3 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
@@ -259,8 +259,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
259259
// PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence
260260
// without removing it from the buffer.
261261
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
262-
jb.mutex.Lock()
263-
defer jb.mutex.Unlock()
264262
packet, err := jb.packets.Find(sq)
265263
if err != nil {
266264
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)