Skip to content

Commit ab615fe

Browse files
committed
jitterbuffer: Improve performance
Rework the jittebuffer for SampleBuilder use
1 parent dfa6291 commit ab615fe

5 files changed

+905
-320
lines changed

pkg/jitterbuffer/jitter_buffer.go

+1-3
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
lastSequence uint16
7272
playoutHead uint16
@@ -253,8 +253,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
253253
// PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence
254254
// without removing it from the buffer.
255255
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
256-
jb.mutex.Lock()
257-
defer jb.mutex.Unlock()
258256
packet, err := jb.packets.Find(sq)
259257
if err != nil {
260258
return nil, err

pkg/jitterbuffer/jitter_buffer_test.go

+1
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)