Commit b5f8ea0e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix rounding in estimator.

The test was buggy.
parent 474c58cc
...@@ -40,9 +40,8 @@ func (e *Estimator) swap(now uint64) { ...@@ -40,9 +40,8 @@ func (e *Estimator) swap(now uint64) {
var rate, packetRate uint32 var rate, packetRate uint32
if jiffies >= rtptime.JiffiesPerSec/1000 { if jiffies >= rtptime.JiffiesPerSec/1000 {
rate = uint32(uint64(bytes) * rtptime.JiffiesPerSec / jiffies) rate = uint32((uint64(bytes)*rtptime.JiffiesPerSec + jiffies/2) / jiffies)
packetRate = packetRate = uint32((uint64(packets)*rtptime.JiffiesPerSec + jiffies/2) / jiffies)
uint32(uint64(packets) * rtptime.JiffiesPerSec / jiffies)
} }
atomic.StoreUint32(&e.rate, rate) atomic.StoreUint32(&e.rate, rate)
atomic.StoreUint32(&e.packetRate, packetRate) atomic.StoreUint32(&e.packetRate, packetRate)
......
...@@ -2,13 +2,14 @@ package estimator ...@@ -2,13 +2,14 @@ package estimator
import ( import (
"testing" "testing"
"time"
"github.com/jech/galene/rtptime" "github.com/jech/galene/rtptime"
) )
func TestEstimator(t *testing.T) { func TestEstimator(t *testing.T) {
now := rtptime.Jiffies() now := rtptime.Jiffies()
e := New(rtptime.JiffiesPerSec) e := New(time.Second)
e.estimate(now) e.estimate(now)
e.Accumulate(42) e.Accumulate(42)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment