diff --git a/revid/Revid.go b/revid/Revid.go index 08a24094..8db224a2 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -324,20 +324,20 @@ func (r *revid) flushData() { func (r *revid) packClips() { clipSize := 0 packetCount := 0 - for { + for r.isRunning { // Get some memory from the ring buffer for out clip var clip []byte var err error if clip, err = r.ringBuffer.Get(); err != nil { r.Log(Error, err.Error()) r.Log(Warning, "Clearing output chan!") - for clip, err = r.ringBuffer.Get(); err != nil; { + for clip, err = r.ringBuffer.Get(); err != nil && r.isRunning; { time.Sleep(time.Duration(10) * time.Millisecond) clip, err = r.ringBuffer.Get() } r.Log(Debug, "Finally got mem from ringbuffer!") } - for { + for r.isRunning { frame := r.getFrame() lenOfFrame := len(frame) if lenOfFrame > ringBufferElementSize { @@ -385,7 +385,7 @@ func (r *revid) outputClips() { } // If the ringbuffer has something we can read and send off - if clip, err := r.ringBuffer.Read(); err == nil { + if clip, err := r.ringBuffer.Read(); err == nil && r.isRunning { bytes += len(clip) errorCount := 0 r.Log(Debug,"About to send!")