Skip to content

Commit

Permalink
Jitter Buffer: Enable setting a minimum length before playout
Browse files Browse the repository at this point in the history
  • Loading branch information
thatsnotright committed Feb 23, 2024
1 parent f2cea34 commit 9be703e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/jitterbuffer/jitter_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type (
// provided timestamp
type JitterBuffer struct {
packets *PriorityQueue

Check failure on line 68 in pkg/jitterbuffer/jitter_buffer.go

View workflow job for this annotation

GitHub Actions / lint / Go

File is not `gci`-ed with --skip-generated -s standard,default (gci)
minStartCount uint16
lastSequence uint16
playoutHead uint16
playoutReady bool
Expand All @@ -90,13 +91,21 @@ type Stats struct {

// New will initialize a jitter buffer and its associated statistics
func New(opts ...Option) *JitterBuffer {
jb := &JitterBuffer{state: Buffering, stats: Stats{0, 0, 0}, packets: NewQueue(), listeners: make(map[Event][]EventListener)}
jb := &JitterBuffer{state: Buffering, stats: Stats{0, 0, 0}, minStartCount: 50, packets: NewQueue(), listeners: make(map[Event][]EventListener)}

Check failure on line 94 in pkg/jitterbuffer/jitter_buffer.go

View workflow job for this annotation

GitHub Actions / lint / Go

File is not `gci`-ed with --skip-generated -s standard,default (gci)
for _, o := range opts {
o(jb)
}
return jb
}

// WithMinimumPacketCount will set the required number of packets to be received before

Check failure on line 101 in pkg/jitterbuffer/jitter_buffer.go

View workflow job for this annotation

GitHub Actions / lint / Go

File is not `gci`-ed with --skip-generated -s standard,default (gci)
// any attempt to pop a packet can succeed
func WithMinimumPacketCount(count uint16) Option {
return func (jb *JitterBuffer) {
jb.minStartCount = count
}

Check warning on line 106 in pkg/jitterbuffer/jitter_buffer.go

View check run for this annotation

Codecov / codecov/patch

pkg/jitterbuffer/jitter_buffer.go#L103-L106

Added lines #L103 - L106 were not covered by tests
}

// Listen will register an event listener
// The jitter buffer may emit events correspnding, interested listerns should
// look at Event for available events
Expand Down Expand Up @@ -142,7 +151,7 @@ func (jb *JitterBuffer) emit(event Event) {

func (jb *JitterBuffer) updateState() {
// For now, we only look at the number of packets captured in the play buffer
if jb.packets.Length() >= 50 && jb.state == Buffering {
if jb.packets.Length() >= jb.minStartCount && jb.state == Buffering {
jb.state = Emitting
jb.playoutReady = true
jb.emit(BeginPlayback)
Expand Down

0 comments on commit 9be703e

Please sign in to comment.