From d741e393466afa035d379b5c9593b36c62c12568 Mon Sep 17 00:00:00 2001 From: richardsonjack Date: Mon, 30 Apr 2018 12:08:00 +0930 Subject: [PATCH 1/6] change ReturnLogger() to GetLogger() --- RevidCLI.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RevidCLI.go b/RevidCLI.go index 44e0073d..ff339bb8 100644 --- a/RevidCLI.go +++ b/RevidCLI.go @@ -250,7 +250,7 @@ func main() { func netsenderInit() { //initialize netsender and assign function to check X pins - config.Logger = netsender.ReturnLogger() + config.Logger = netsender.GetLogger() netsender.InitRevidNetsender() netsender.ExternalReader = revidReportActions From 4fdcaa6d0ac2454486a0fb59f2760daa2e2ffb71 Mon Sep 17 00:00:00 2001 From: richardsonjack Date: Mon, 30 Apr 2018 12:44:21 +0930 Subject: [PATCH 2/6] make inputs configurable for revidCLI --- RevidCLI.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RevidCLI.go b/RevidCLI.go index ff339bb8..15b270a5 100644 --- a/RevidCLI.go +++ b/RevidCLI.go @@ -274,7 +274,8 @@ func periodicNetsenderReport(){ } } - inputs := []string{"X20", "X21"} + //inputs := []string{"X20", "X21"} + inputs := netsender.GetConfigParam("inputs") if _, _, err := netsender.Send(netsender.RequestPoll, inputs); err != nil { config.Logger.Log("Error", err.Error()) } From 68035544345bf9bb5ebdfe342002822783766caf Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Tue, 1 May 2018 05:40:41 +0930 Subject: [PATCH 3/6] fixing rtmp handshake error --- revid/Revid.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 From 9b4681e29fb1d92f6f10aeaf2a8b1203a2ecb297 Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Tue, 1 May 2018 06:07:37 +0930 Subject: [PATCH 4/6] implementing rotate --- RevidCLI.go | 5 ++++- revid/Config.go | 10 ++++++++++ revid/Revid.go | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/RevidCLI.go b/RevidCLI.go index 15b270a5..cf6148fd 100644 --- a/RevidCLI.go +++ b/RevidCLI.go @@ -63,13 +63,14 @@ const ( quantizationPtr = 16 timeoutPtr = 17 intraRefreshPeriodPtr = 18 + rotatePtr = 19 ) // Other misc consts const ( sleepTime = 2 * 43200 defaultRunDuration = 2 * 43200 - noOfConfigconfigFlags = 19 + noOfConfigconfigFlags = 20 revidStopTime = 5 prepTime = 20 loggerVerbosity = 3 @@ -118,6 +119,7 @@ func main() { {"Quantization", "Desired quantization value"}, {"Timeout", "Http timeout in seconds"}, {"IntraRefreshPeriod", "The IntraRefreshPeriod i.e. how many keyframes we send"}, + {"Rotate", "Rotate video the specified number of degrees"}, } // Create the configFlags based on the flagNames array @@ -221,6 +223,7 @@ func main() { config.Quantization = *configFlags[quantizationPtr] config.Timeout = *configFlags[timeoutPtr] config.IntraRefreshPeriod = *configFlags[intraRefreshPeriodPtr] + config.Rotate = *configFlags[rotatePtr] // Also give the config a logger object config.Logger = smartLogger.New(loggerVerbosity, smartLogger.White) diff --git a/revid/Config.go b/revid/Config.go index b23a697f..5230b4d4 100644 --- a/revid/Config.go +++ b/revid/Config.go @@ -98,6 +98,7 @@ const ( defaultBitrate = "500000" defaultQuantizationMode = QuantizationOff defaultFramesPerClip = "1" + defaultRotate = "0" ) // Validate checks for any errors in the config fields and defaults settings @@ -273,5 +274,14 @@ func (config *Config) Validate(r *revid) error { return errors.New("Bad quantization defined in config!") } } + + if config.Rotate = "" { + r.Log(Warning, fmt.Sprintf("No rotate defined defaulting to: %v", defaultRotate) ) + r.config.Rotate = defaultRotate + } else { + if integer, err := strconv.Atoi(config.Rotate); integer < 0 || integer > 270 || err != nil { + return errors.New("Bad rotate defined in config!") + } + } return nil } diff --git a/revid/Revid.go b/revid/Revid.go index 43d34ead..9d2ef86b 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -543,6 +543,7 @@ func (r *revid) setupInputForRaspivid() error { "-fps", r.config.FrameRate, "-ih", "-g", r.config.IntraRefreshPeriod, + "-ro", r.config.Rotate, ) case QuantizationOff: r.cmd = exec.Command("raspivid", @@ -556,6 +557,7 @@ func (r *revid) setupInputForRaspivid() error { "-fps", r.config.FrameRate, "-ih", "-g", r.config.IntraRefreshPeriod, + "-ro", r.config.Rotate, ) } From 962a21ebc9f70b7c0f22bceeb0a0a574d739ac48 Mon Sep 17 00:00:00 2001 From: richardsonjack Date: Tue, 1 May 2018 16:28:05 +0930 Subject: [PATCH 5/6] update init call --- RevidCLI.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RevidCLI.go b/RevidCLI.go index 15b270a5..bcf6b1ec 100644 --- a/RevidCLI.go +++ b/RevidCLI.go @@ -251,7 +251,7 @@ func main() { func netsenderInit() { //initialize netsender and assign function to check X pins config.Logger = netsender.GetLogger() - netsender.InitRevidNetsender() + netsender.Init(false) netsender.ExternalReader = revidReportActions //try get initial config From 5e03ed87249cbde1f37a54a034135229d0daa08e Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Wed, 2 May 2018 09:58:00 +0930 Subject: [PATCH 6/6] Trying to fix mem leaks --- revid/Revid.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/revid/Revid.go b/revid/Revid.go index 9d2ef86b..8c26df93 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -279,6 +279,7 @@ func (r *revid) Stop() { if r.cmd != nil && r.cmd.Process != nil { r.cmd.Process.Kill() } + r.rtmpInst.EndSession() } // getFrameNoPacketization gets a frame directly from the revid output chan @@ -509,6 +510,7 @@ func (r *revid) setupOutputForLibRtmp() error { err = r.rtmpInst.StartSession(), noOfTries := 0; err != nil && noOfTries < rtmpConnectionMaxTries; noOfTries++ { + r.rtmpInst.EndSession() r.Log(Error, err.Error()) r.Log(Info, "Trying to establish rtmp connection again!") r.rtmpInst = rtmp.NewRTMPSession(r.config.RtmpUrl, rtmpConnectionTimout)