diff --git a/revid/Revid.go b/revid/Revid.go index 14021837..43d34ead 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -73,6 +73,7 @@ const ( sendFailedDelay = 5 maxSendFailedErrorCount = 500 clipSizeThreshold = 11 + rtmpConnectionMaxTries = 5 ) // Log Types @@ -503,11 +504,17 @@ func (r *revid) setupOutputForFfmpegRtmp() error { // setupOutputForLibRtmp sets up rtmp output using the wrapper for the c based // librtmp library - makes connection and starts comms etc. -func (r *revid) setupOutputForLibRtmp() (err error) { - r.rtmpInst = rtmp.NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout) - err = r.rtmpInst.StartSession() - // go r.testRtmp(5000) - return +func (r *revid) setupOutputForLibRtmp() error { + for r.rtmpInst = rtmp.NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout), + err = r.rtmpInst.StartSession(), noOfTries := 0; + err != nil && noOfTries < rtmpConnectionMaxTries; noOfTries++ + { + r.Log(Error, err.Error()) + r.Log(Info, "Trying to establish rtmp connection again!") + r.rtmpInst = rtmp.NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout) + err = r.rtmpInst.StartSession() + } + return errors.New("Could not establish rtmp connection, check rtmp url!") } // setupOutputForFile sets up an output file to output data to