From 93ad5ed2479d7e52c60dfc725688978e95668455 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 6 Dec 2017 13:41:32 +1030 Subject: [PATCH] Fixed up comments --- bitrate/BitrateCalculator.go | 37 ++++++++++++++++--------------- bitrate/BitrateCalculator_test.go | 35 +++++++++++++++-------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/bitrate/BitrateCalculator.go b/bitrate/BitrateCalculator.go index 2f6fc528..752905d6 100644 --- a/bitrate/BitrateCalculator.go +++ b/bitrate/BitrateCalculator.go @@ -1,15 +1,16 @@ /* NAME - revid - a testbed for re-muxing and re-directing video streams as MPEG-TS over various protocols. + BitrateCalculator.go - is a simple struct with methods to allow for easy + calculation of bitrate. DESCRIPTION See Readme.md AUTHOR - Alan Noble + Saxon Nelson-Milton LICENSE - revid is Copyright (C) 2017 Alan Noble. + BitrateCalculator.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -34,38 +35,38 @@ import ( // bitrateCalculator implements interface BitrateCalculator type BitrateCalculator struct { - outputDelay int // sec - now time.Time - prev time.Time - startedBefore bool - elapsedTime time.Duration - lastDisplayTime time.Time + outputDelay int // sec + now time.Time + prev time.Time + startedBefore bool + elapsedTime time.Duration + lastDisplayTime time.Time } // Place this at the start of the code segment that you would like to time func (bc *BitrateCalculator) Start(outputDelay int) { - if outputDelay >= 0{ - bc.outputDelay = outputDelay - } else { - bc.outputDelay = 0 - } - bc.prev = time.Now() + if outputDelay >= 0 { + bc.outputDelay = outputDelay + } else { + bc.outputDelay = 0 + } + bc.prev = time.Now() if !bc.startedBefore { bc.startedBefore = true bc.elapsedTime = time.Duration(0) - bc.lastDisplayTime = time.Now() + bc.lastDisplayTime = time.Now() } } // Place this at the end of the code segment that you would like to time func (bc *BitrateCalculator) Stop(noOfKB float64) (bitrate int64) { - bc.now = time.Now() + bc.now = time.Now() deltaTime := bc.now.Sub(bc.prev) if bc.now.Sub(bc.lastDisplayTime) > time.Duration(bc.outputDelay)*time.Second { bitrate = int64(noOfKB / float64(deltaTime/1e9)) fmt.Printf("Bitrate: %d kbps\n", bitrate) bc.elapsedTime = time.Duration(0) - bc.lastDisplayTime = bc.now + bc.lastDisplayTime = bc.now } return } diff --git a/bitrate/BitrateCalculator_test.go b/bitrate/BitrateCalculator_test.go index e65e6eff..f256e1f5 100644 --- a/bitrate/BitrateCalculator_test.go +++ b/bitrate/BitrateCalculator_test.go @@ -1,15 +1,16 @@ /* NAME - revid - a testbed for re-muxing and re-directing video streams as MPEG-TS over various protocols. + BitrateCalculator_test.go - is a file that may be used to test the + BitrateCalculator.go file using the golang testing utilities DESCRIPTION See Readme.md AUTHOR - Alan Noble + Saxon Nelson-Milton LICENSE - revid is Copyright (C) 2017 Alan Noble. + BitrateCalculator_test.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean) It is free software: you can redistribute it and/or modify them under the terms of the GNU General Public License as published by the @@ -46,30 +47,30 @@ var bitrateCalc BitrateCalculator // Simple test to check that the calculator can calc bitrate over a given // duration of time func Test1(t *testing.T) { - bitrateCalc = BitrateCalculator{} + bitrateCalc = BitrateCalculator{} bitrateCalc.Start(bitrateDelay1) time.Sleep(testTime * time.Millisecond) currentBitrate := int64(bitrateCalc.Stop(amountOfData)) - actualBitrate := int64(amountOfData / ((testTime * time.Millisecond)/1e9)) + actualBitrate := int64(amountOfData / ((testTime * time.Millisecond) / 1e9)) if currentBitrate != actualBitrate { t.Errorf("Bitrate is wrong! Calculated: %v Actual %v", currentBitrate, actualBitrate) } } // Now let's check that the output delay feature works -func Test2(t *testing.T){ - bitrateCalc = BitrateCalculator{} +func Test2(t *testing.T) { + bitrateCalc = BitrateCalculator{} var currentBitrate int64 - for i := 0; i < 2; i++ { - bitrateCalc.Start(bitrateDelay2) - time.Sleep(testTime*time.Millisecond) - currentBitrate = int64(bitrateCalc.Stop(amountOfData)) - if i == 0 && currentBitrate != 0 { - t.Errorf("The bitrate calc did not delay outputting!") - } - time.Sleep(6000*time.Millisecond) - } - actualBitrate := int64(amountOfData / ((testTime * time.Millisecond)/1e9)) + for i := 0; i < 2; i++ { + bitrateCalc.Start(bitrateDelay2) + time.Sleep(testTime * time.Millisecond) + currentBitrate = int64(bitrateCalc.Stop(amountOfData)) + if i == 0 && currentBitrate != 0 { + t.Errorf("The bitrate calc did not delay outputting!") + } + time.Sleep(6000 * time.Millisecond) + } + actualBitrate := int64(amountOfData / ((testTime * time.Millisecond) / 1e9)) if currentBitrate != actualBitrate { t.Errorf("Bitrate is wrong! Calculated: %v Actual %v", currentBitrate, actualBitrate) }