mirror of https://bitbucket.org/ausocean/av.git
started writing BitrateCalculatorStruct
This commit is contained in:
parent
6c0f923480
commit
f8aa535ec7
|
@ -0,0 +1,37 @@
|
|||
package bitrate
|
||||
|
||||
import (
|
||||
"time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type BitrateCalculator struct {
|
||||
Delay int
|
||||
now
|
||||
prev
|
||||
isFirstTime bool
|
||||
elapsedTime time
|
||||
}
|
||||
|
||||
func (bc *BitrateCalculator) Start() {
|
||||
if isFirstTime {
|
||||
if Delay == nil {
|
||||
Delay = 5 * time.Second
|
||||
}
|
||||
now = time.Now()
|
||||
prev = now
|
||||
isFirstTime = false
|
||||
elapsedTime = time.Duration(0)
|
||||
}
|
||||
now := time.Now()
|
||||
}
|
||||
|
||||
func (bc *BitrateCalculator) End(noOfKB int, printOption bool) (bitrate int) {
|
||||
deltaTime := now.Sub(prevTime)
|
||||
elapsedTime += deltaTime
|
||||
if elapsedTime > bitrateOutputDelay*time.Second {
|
||||
fmt.Printf("Bitrate: %d kbps\n", int64(noOfKB/float64(deltaTime/1e9)))
|
||||
elapsedTime = time.Duration(0)
|
||||
}
|
||||
prevTime = now
|
||||
}
|
|
@ -298,25 +298,17 @@ func input(input string, output string) {
|
|||
|
||||
// output handles the writing to specified output
|
||||
func output(output string) {
|
||||
elapsedTime := time.Duration(0)
|
||||
now := time.Now()
|
||||
prevTime := now
|
||||
bitrateCalc := BitrateCalculator{60}
|
||||
for {
|
||||
if clip, err := ringBuffer.Read(); err == nil {
|
||||
now := time.Now()
|
||||
bitrateCalc.Start()
|
||||
err := sendClip(clip, output, conn)
|
||||
for err != nil {
|
||||
outputErrChan <- err
|
||||
err = sendClip(clip, output, conn)
|
||||
}
|
||||
deltaTime := now.Sub(prevTime)
|
||||
elapsedTime += deltaTime
|
||||
if elapsedTime > bitrateOutputDelay*time.Second {
|
||||
noOfBits := float64(len(clip)*8) / 1024.0 // convert bytes to kilobits
|
||||
fmt.Printf("Bitrate: %d kbps\n", int64(noOfBits/float64(deltaTime/1e9)))
|
||||
elapsedTime = time.Duration(0)
|
||||
}
|
||||
prevTime = now
|
||||
noOfKB = float64(len(clip)*8) / 1024.0 // Convert bytes to kilobits
|
||||
bitrateCalc.End(, true)
|
||||
if err := ringBuffer.DoneReading(); err != nil {
|
||||
outputErrChan <- err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue