Skip to content

Commit 7639fd0

Browse files
committed
Jitter Buffer: Improve performance
Rework the jitterbuffer for SampleBuilder use
1 parent 6ecd702 commit 7639fd0

File tree

7 files changed

+898
-351
lines changed

7 files changed

+898
-351
lines changed

pkg/jitterbuffer/jitter_buffer.go

Lines changed: 5 additions & 5 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,13 +132,15 @@ 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()
139+
138140
return jb.packets.Length()
139141
}
140142

141-
// SetPlayoutHead allows you to manually specify the packet you wish to pop next
143+
// SetPlayoutHead allows you to manually specify the packet you wish to pop next.
142144
// If you have encountered a packet that hasn't resolved you can skip it.
143145
func (jb *JitterBuffer) SetPlayoutHead(playoutHead uint16) {
144146
jb.mutex.Lock()
@@ -177,7 +179,7 @@ func (jb *JitterBuffer) Push(packet *rtp.Packet) {
177179
}
178180

179181
jb.updateStats(packet.SequenceNumber)
180-
jb.packets.Push(packet, packet.SequenceNumber)
182+
jb.packets.Push(packet)
181183
jb.updateState()
182184
}
183185

@@ -259,8 +261,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
259261
// PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence
260262
// without removing it from the buffer.
261263
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
262-
jb.mutex.Lock()
263-
defer jb.mutex.Unlock()
264264
packet, err := jb.packets.Find(sq)
265265
if err != nil {
266266
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))

pkg/jitterbuffer/option.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func Log(log logging.LeveledLogger) ReceiverInterceptorOption {
2222
func WithSkipMissingPackets() ReceiverInterceptorOption {
2323
return func(d *ReceiverInterceptor) error {
2424
d.skipMissingPackets = true
25+
2526
return nil
2627
}
2728
}

0 commit comments

Comments
 (0)