From c9110be8e768cc6b2a4eba191f913a2995995e35 Mon Sep 17 00:00:00 2001 From: Jack Richardson Date: Wed, 17 Jan 2018 15:32:52 +1030 Subject: [PATCH] outputting bitrate and ringbuffer length. everything else seems to be working --- revid/RevidInstance.go | 22 ++++++++++++++++++---- ringbuffer/RingBuffer.go | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/revid/RevidInstance.go b/revid/RevidInstance.go index df919c99..a626ecbe 100644 --- a/revid/RevidInstance.go +++ b/revid/RevidInstance.go @@ -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 + } } } } diff --git a/ringbuffer/RingBuffer.go b/ringbuffer/RingBuffer.go index 2e385e74..21f1b07a 100644 --- a/ringbuffer/RingBuffer.go +++ b/ringbuffer/RingBuffer.go @@ -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