From f013a3e1f33bd9eb82cbebdd4868b5d7739c6fbe Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Wed, 6 Dec 2017 08:54:20 +1030 Subject: [PATCH] Think I've finished the actual code, just need to write some testing utilities --- bitrate/BitrateCalculator.go | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) 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 }