Merge branch 'RevidCLI' of https://bitbucket.org/ausocean/av into RevidCLI

This commit is contained in:
Alan Noble 2018-05-02 10:00:11 +09:30
commit 9afe4b1334
3 changed files with 32 additions and 7 deletions

View File

@ -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)
@ -274,7 +277,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())
}

View File

@ -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
}

View File

@ -73,6 +73,7 @@ const (
sendFailedDelay = 5
maxSendFailedErrorCount = 500
clipSizeThreshold = 11
rtmpConnectionMaxTries = 5
)
// Log Types
@ -278,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
@ -503,11 +505,18 @@ 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.rtmpInst.EndSession()
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
@ -536,6 +545,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",
@ -549,6 +559,7 @@ func (r *revid) setupInputForRaspivid() error {
"-fps", r.config.FrameRate,
"-ih",
"-g", r.config.IntraRefreshPeriod,
"-ro", r.config.Rotate,
)
}