Think I've finished the actual code, just need to write some testing utilities

This commit is contained in:
Saxon Milton 2017-12-06 08:54:20 +10:30
parent ca48e4a9d4
commit f013a3e1f3
1 changed files with 15 additions and 18 deletions

View File

@ -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
}