outputting bitrate and ringbuffer length. everything else seems to be working

This commit is contained in:
Jack Richardson 2018-01-17 15:32:52 +10:30
parent 16c399aabf
commit c9110be8e7
2 changed files with 23 additions and 4 deletions

View File

@ -70,6 +70,7 @@ const (
framesPerSec = 25
packetsPerFrame = 7
h264BufferSize = 500000
bitrateTime = 10
)
const (
@ -258,22 +259,35 @@ func (r *revidInst) input() {
}
func (r *revidInst) output() {
now := time.Now()
prevTime := now
bytes := 0
for r.isRunning {
if clip, err := r.ringBuffer.Read(); err == nil {
switch r.config.Output {
case File:
r.outputFile.Write(clip)
case HttpOut:
for err := sendClipToHTTP(clip, r.config.HttpAddress); err != nil; {
err = sendClipToHTTP(clip, r.config.HttpAddress)
time.Sleep(5*time.Second)
}
bytes += len(clip)
for err := sendClipToHTTP(clip, r.config.HttpAddress); err != nil; {
err = sendClipToHTTP(clip, r.config.HttpAddress)
time.Sleep(5*time.Second)
}
default:
r.Error.Println("No output?")
}
if err := r.ringBuffer.DoneReading(); err != nil {
r.Error.Println(err.Error())
}
fmt.Printf("len(ringBuffer): %v\n", r.ringBuffer.GetNoOfElements())
now = time.Now()
deltaTime := now.Sub(prevTime)
if deltaTime > time.Duration(bitrateTime)*time.Second {
fmt.Printf("Bitrate: %v bytes/s\n", int64(float64(bytes) / float64(deltaTime/1e9)))
prevTime = now
bytes = 0
}
}
}
}

View File

@ -45,6 +45,11 @@ type RingBuffer interface {
DoneReading() error
IsReadable() bool
IsWritable() bool
GetNoOfElements() int
}
func (rb *ringBuffer)GetNoOfElements() int {
return rb.noOfElements
}
// ringBuffer implements the RingBuffer interface