1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
package gcc
import (
"time"
)
type estimator interface {
updateEstimate(measurement time.Duration) time.Duration
}
type estimatorFunc func(time.Duration) time.Duration
func (f estimatorFunc) updateEstimate(d time.Duration) time.Duration {
return f(d)
}
type slopeEstimator struct {
estimator
init bool
group arrivalGroup
delayStatsWriter func(DelayStats)
}
func newSlopeEstimator(e estimator, dsw func(DelayStats)) *slopeEstimator {
return &slopeEstimator{
estimator: e,
delayStatsWriter: dsw,
}
}
func (e *slopeEstimator) onArrivalGroup(ag arrivalGroup) {
if !e.init {
e.group = ag
e.init = true
return
}
measurement := interGroupDelayVariation(e.group, ag)
delta := ag.arrival.Sub(e.group.arrival)
e.group = ag
e.delayStatsWriter(DelayStats{
Measurement: measurement,
Estimate: e.updateEstimate(measurement),
Threshold: 0,
LastReceiveDelta: delta,
Usage: 0,
State: 0,
TargetBitrate: 0,
})
}
func interGroupDelayVariation(a, b arrivalGroup) time.Duration {
return b.arrival.Sub(a.arrival) - b.departure.Sub(a.departure)
}
|