From 098cc19c600b29eaf80499942c770405d946fdd3 Mon Sep 17 00:00:00 2001 From: Alan Noble Date: Mon, 7 May 2018 12:11:43 +0930 Subject: [PATCH] More checks for isRunning. --- revid/Revid.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/revid/Revid.go b/revid/Revid.go index fc3e8695..5feb2f31 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -349,8 +349,8 @@ func (r *revid) packClips() { for r.isRunning { select { - // TODO: This is temporary, need to work out how to make this work - // for cases when there is not packetisation. + // TODO: This is temporary, need to work out how to make this work + // for cases when there is not packetisation. case frame := <-(r.generator.GetOutputChan()): lenOfFrame := len(frame) if lenOfFrame > ringBufferElementSize { @@ -377,10 +377,10 @@ func (r *revid) packClips() { goto finishedWithClip } default: - time.Sleep(time.Duration(5)*time.Millisecond) + time.Sleep(time.Duration(5) * time.Millisecond) } } - finishedWithClip: + finishedWithClip: } } @@ -400,7 +400,6 @@ func (r *revid) outputClips() { case delay > 0: delay-- } - // If the ringbuffer has something we can read and send off if clip, err := r.ringBuffer.Read(); err == nil && r.isRunning { bytes += len(clip) @@ -408,15 +407,15 @@ func (r *revid) outputClips() { err2 := r.sendClip(clip) r.Log(Debug, "Finished send") - if err2 != nil && len(clip) > 11 { + if r.isRunning && err2 != nil && len(clip) > 11 { r.Log(Debug, "Send failed! Trying again") // Try and send again err2 = r.sendClip(clip) - // if there's still an error we try and reconnect - for err2 != nil { + // if there's still an error we try and reconnect, unless we're stopping + for r.isRunning && err2 != nil { r.Log(Debug, "Send failed a again! Trying to reconnect...") - time.Sleep(time.Duration(5)*time.Millisecond) + time.Sleep(time.Duration(5) * time.Millisecond) r.Log(Error, err2.Error()) if r.config.Output == NativeRtmp { @@ -439,6 +438,10 @@ func (r *revid) outputClips() { } } + if !r.isRunning { + break + } + r.Log(Debug, "Done reading that clip from ringbuffer...") // let the ringbuffer know that we're done with the memory we grabbed when // we call ringBuffer.Get() @@ -455,8 +458,6 @@ func (r *revid) outputClips() { prevTime = now bytes = 0 } - } else { - //r.Log(Error, err.Error()) } } r.Log(Info, "Not outputting clips anymore!")