diff --git a/bitrate/BitrateCalculator.go b/bitrate/BitrateCalculator.go index 9f5b86aa..fea3bc1f 100644 --- a/bitrate/BitrateCalculator.go +++ b/bitrate/BitrateCalculator.go @@ -6,36 +6,33 @@ import ( ) type BitrateCalculator struct { - Delay int + Delay int // sec now prev isFirstTime bool - elapsedTime time + elapsedTime time.Time } // The bitrate calculator func (bc *BitrateCalculator) Start() { - if isFirstTime { + if bc.isFirstTime { if Delay == nil { - Delay = 5 * time.Second + bc.Delay = 5 * time.Second } - now = time.Now() - prev = now - isFirstTime = false - elapsedTime = time.Duration(0) + bc.now = time.Now() + bc.prev = now + bc.isFirstTime = false + bc.elapsedTime = time.Duration(0) } - now := time.Now() + bc.now = time.Now() } -func (bc *BitrateCalculator) Stop(noOfKB int, printOption bool) (bitrate int) { +func (bc *BitrateCalculator) Stop(noOfKB int) (bitrate int) { deltaTime := now.Sub(prevTime) - elapsedTime += deltaTime - if elapsedTime > bitrateOutputDelay*time.Second { - bitrate = int64(noOfKB/float64(deltaTime/1e9)) - if printOption { - fmt.Printf("Bitrate: %d kbps\n", bitrate) - } - elapsedTime = time.Duration(0) + bc.elapsedTime += deltaTime + if bc.elapsedTime > bc.Delay*time.Second { + fmt.Printf("Bitrate: %d kbps\n", int64(noOfKB/float64(deltaTime/1e9))) + bc.elapsedTime = time.Duration(0) } - prevTime = now + bc.prev = now }