Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jitter timestamp increase at least defaultTickInterval on jitter::Get #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pkg/jitter/jitter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package jitter

import (
"github.com/huandu/skiplist"
"github.com/samber/lo"
"math"

"sync"

"github.com/huandu/skiplist"
"github.com/samber/lo"
)

type Factory struct {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (b *Jitter) Get() ([]*Packet, bool) {
}

lastPkt := ret[len(ret)-1]
newTargetTime := lastPkt.Timestamp + lastPkt.SampleCnt
newTargetTime := max(lastPkt.Timestamp+lastPkt.SampleCnt, targetTime+b.defaultTickInterval)
incr := newTargetTime - targetTime

b.currentOffset += incr
Expand All @@ -144,6 +144,13 @@ func (b *Jitter) Get() ([]*Packet, bool) {
return ret, true
}

func max(a int64, b int64) int64 {
if a < b {
return b
}
return a
}

func (b *Jitter) dequeuePackets() []*Packet {
var ret []*Packet

Expand Down