Skip to content

Commit

Permalink
rename to highestAdded
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaffrey committed Dec 16, 2024
1 parent 4fd7c35 commit 2c5317f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/rtpbuffer/rtpbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (

// RTPBuffer stores RTP packets and allows custom logic around the lifetime of them via the PacketFactory
type RTPBuffer struct {
packets []*RetainablePacket
size uint16
lastAdded uint16
started bool
packets []*RetainablePacket
size uint16
highestAdded uint16
started bool
}

// NewRTPBuffer constructs a new RTPBuffer
Expand Down Expand Up @@ -50,24 +50,24 @@ func (r *RTPBuffer) Add(packet *RetainablePacket) {
seq := packet.sequenceNumber
if !r.started {
r.packets[seq%r.size] = packet
r.lastAdded = seq
r.highestAdded = seq
r.started = true
return
}

diff := seq - r.lastAdded
diff := seq - r.highestAdded
if diff == 0 {
return
} else if diff < Uint16SizeHalf {
for i := r.lastAdded + 1; i != seq; i++ {
for i := r.highestAdded + 1; i != seq; i++ {
idx := i % r.size
prevPacket := r.packets[idx]
if prevPacket != nil {
prevPacket.Release()
}
r.packets[idx] = nil
}
r.lastAdded = seq
r.highestAdded = seq
}

idx := seq % r.size
Expand All @@ -80,7 +80,7 @@ func (r *RTPBuffer) Add(packet *RetainablePacket) {

// Get returns the RetainablePacket for the requested sequence number
func (r *RTPBuffer) Get(seq uint16) *RetainablePacket {
diff := r.lastAdded - seq
diff := r.highestAdded - seq
if diff >= Uint16SizeHalf {
return nil
}
Expand Down

0 comments on commit 2c5317f

Please sign in to comment.