Skip to content

Commit

Permalink
Add additional helper methods for the jitter buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsnotright committed Feb 17, 2024
1 parent 5574fda commit f2cea34
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/jitterbuffer/jitter_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,39 @@ func (jb *JitterBuffer) Pop() (*rtp.Packet, error) {
return packet, nil
}

// Pop an RTP packet from the jitter buffer at the specified Sequence
func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) {
jb.mutex.Lock()
defer jb.mutex.Unlock()
if jb.state != Emitting {
return nil, ErrPopWhileBuffering
}
packet, err := jb.packets.PopAt(sq)
if err != nil {
jb.stats.underflowCount++
jb.emit(BufferUnderflow)
return (*rtp.Packet)(nil), err
}
jb.playoutHead = (jb.playoutHead + 1) % math.MaxUint16
jb.updateState()
return packet, nil
}

// Peek an RTP packet from the jitter buffer at the specified Sequence
func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) {
jb.mutex.Lock()
defer jb.mutex.Unlock()
if jb.state != Emitting {
return nil, ErrPopWhileBuffering
}
packet, err := jb.packets.Find(sq)
if err != nil {
return (*rtp.Packet)(nil), err
}
return packet, nil
}


// PopAtTimestamp pops an RTP packet from the jitter buffer with the provided timestamp
// Call this method repeatedly to drain the buffer at the timestamp
func (jb *JitterBuffer) PopAtTimestamp(ts uint32) (*rtp.Packet, error) {
Expand Down

0 comments on commit f2cea34

Please sign in to comment.