Skip to content

Commit

Permalink
jitterbuffer: Improve performance
Browse files Browse the repository at this point in the history
Rework the jittebuffer for SampleBuilder use
  • Loading branch information
thatsnotright committed Feb 26, 2025
1 parent dfa6291 commit ab615fe
Show file tree
Hide file tree
Showing 5 changed files with 905 additions and 320 deletions.
4 changes: 1 addition & 3 deletions pkg/jitterbuffer/jitter_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type (
// order, and allows removing in either sequence number order or via a
// provided timestamp.
type JitterBuffer struct {
packets *PriorityQueue
packets *RBTree
minStartCount uint16
lastSequence uint16
playoutHead uint16
Expand Down Expand Up @@ -253,8 +253,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
// PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence
// without removing it from the buffer.
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
jb.mutex.Lock()
defer jb.mutex.Unlock()
packet, err := jb.packets.Find(sq)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/jitterbuffer/jitter_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func TestJitterBuffer(t *testing.T) {
assert.Equal(jb.packets.Length(), uint16(100))
assert.Equal(jb.state, Emitting)
head, err := jb.PopAtTimestamp(uint32(513))
assert.NotNil(head)
assert.Equal(head.SequenceNumber, uint16(math.MaxUint16-32+1))
assert.Equal(err, nil)
head, err = jb.PopAtTimestamp(uint32(513))
Expand Down
Loading

0 comments on commit ab615fe

Please sign in to comment.