revid: cleaned up key value pairs in config.go

This commit is contained in:
saxon 2018-09-15 12:26:05 +09:30
parent b3a8f2bca3
commit d697b4013d
1 changed files with 45 additions and 24 deletions

View File

@ -99,6 +99,9 @@ const (
defaultFramesPerClip = 1
defaultVerticalFlip = No
defaultHorizontalFlip = No
httpFramesPerClip = 7
defaultInputCodec = H264
defaultVerbosity = No
)
// Validate checks for any errors in the config fields and defaults settings
@ -108,8 +111,9 @@ func (c *Config) Validate(r *Revid) error {
case Yes:
case No:
case NothingDefined:
c.Verbosity = Yes
c.Logger.Log(smartlogger.Warning, "No verbosity mode defined, defaulting to no Verbosity!")
c.Verbosity = defaultVerbosity
c.Logger.Log(smartlogger.Warning, "No verbosity mode defined, defaulting",
"verbosity", defaultVerbosity)
default:
return errors.New("Bad Verbosity defined in config!")
}
@ -118,7 +122,8 @@ func (c *Config) Validate(r *Revid) error {
case QuantizationOn:
case QuantizationOff:
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No quantization mode defined, defaulting to QuantizationOff!")
c.Logger.Log(smartlogger.Warning, "No quantization mode defined, defaulting",
"quantizationMode", QuantizationOff)
c.QuantizationMode = QuantizationOff
default:
return errors.New("Bad QuantizationMode defined in config!")
@ -128,7 +133,8 @@ func (c *Config) Validate(r *Revid) error {
case Raspivid:
case File:
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No input type defined, defaulting to raspivid!")
c.Logger.Log(smartlogger.Warning, "No input type defined, defaulting", "input",
defaultInput)
c.Input = defaultInput
default:
return errors.New("Bad input type defined in config!")
@ -160,9 +166,11 @@ func (c *Config) Validate(r *Revid) error {
}
}
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No input codec defined, defaulting to h264!")
c.InputCodec = H264
c.Logger.Log(smartlogger.Warning, "Defaulting bitrate to 0 and quantization to 35!")
c.Logger.Log(smartlogger.Warning, "No input codec defined, defaulting",
"inputCodec", defaultInputCodec)
c.InputCodec = defaultInputCodec
c.Logger.Log(smartlogger.Warning, "Defaulting quantization", "quantization",
defaultQuantization)
c.Quantization = defaultQuantization
default:
return errors.New("Bad input codec defined in config!")
@ -176,15 +184,18 @@ func (c *Config) Validate(r *Revid) error {
c.Output = Http
break
}
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip to 1 for rtmp output!")
c.FramesPerClip = 1
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip for rtmp out",
"framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No output defined, defaulting to httpOut!")
c.Logger.Log(smartlogger.Warning, "No output defined, defaulting", "output",
defaultOutput)
c.Output = defaultOutput
fallthrough
case Http:
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip to 7 for http output!")
c.FramesPerClip = 7
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip for http out",
"framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip
default:
return errors.New("Bad output type defined in config!")
}
@ -194,8 +205,9 @@ func (c *Config) Validate(r *Revid) error {
case Mpegts:
case Flv:
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No packetization option defined, defaulting to none!")
c.Packetization = Flv
c.Logger.Log(smartlogger.Warning, "No packetization option defined, defaulting",
"packetization", defaultPacketization)
c.Packetization = defaultPacketization
default:
return errors.New("Bad packetization option defined in config!")
}
@ -204,7 +216,8 @@ func (c *Config) Validate(r *Revid) error {
case Yes:
case No:
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No horizontal flip option defined, defaulting to not flipped!")
c.Logger.Log(smartlogger.Warning, "No horizontal flip option defined, defaulting",
"horizontalFlip", defaultHorizontalFlip)
c.HorizontalFlip = defaultHorizontalFlip
default:
return errors.New("Bad horizontal flip option defined in config!")
@ -214,19 +227,22 @@ func (c *Config) Validate(r *Revid) error {
case Yes:
case No:
case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No vertical flip option defined, defaulting to not flipped!")
c.Logger.Log(smartlogger.Warning, "No vertical flip option defined, defaulting",
"verticalFlip", defaultVerticalFlip)
c.VerticalFlip = defaultVerticalFlip
default:
return errors.New("Bad vertical flip option defined in config!")
}
if c.FramesPerClip < 1 {
c.Logger.Log(smartlogger.Warning, "No FramesPerClip defined defined, defaulting to 1!")
c.Logger.Log(smartlogger.Warning, "No FramesPerClip defined, defaulting",
"framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip
}
if c.Width == "" {
c.Logger.Log(smartlogger.Warning, "No width defined, defaulting to 1280!")
c.Logger.Log(smartlogger.Warning, "No width defined, defaulting", "width",
defaultWidth)
c.Width = defaultWidth
} else {
if integer, err := strconv.Atoi(c.Width); integer < 0 || err != nil {
@ -235,7 +251,8 @@ func (c *Config) Validate(r *Revid) error {
}
if c.Height == "" {
c.Logger.Log(smartlogger.Warning, "No height defined, defaulting to 720!")
c.Logger.Log(smartlogger.Warning, "No height defined, defaulting", "height",
defaultHeight)
c.Height = defaultHeight
} else {
if integer, err := strconv.Atoi(c.Height); integer < 0 || err != nil {
@ -244,7 +261,8 @@ func (c *Config) Validate(r *Revid) error {
}
if c.FrameRate == "" {
c.Logger.Log(smartlogger.Warning, "No frame rate defined, defaulting to 25!")
c.Logger.Log(smartlogger.Warning, "No frame rate defined, defaulting", "fps",
defaultFrameRate)
c.FrameRate = defaultFrameRate
} else {
if integer, err := strconv.Atoi(c.FrameRate); integer < 0 || err != nil {
@ -253,7 +271,8 @@ func (c *Config) Validate(r *Revid) error {
}
if c.Bitrate == "" {
c.Logger.Log(smartlogger.Warning, "No bitrate defined, defaulting!")
c.Logger.Log(smartlogger.Warning, "No bitrate defined, defaulting", "bitrate",
defaultBitrate)
c.Bitrate = defaultBitrate
} else {
if integer, err := strconv.Atoi(c.Bitrate); integer < 0 || err != nil {
@ -262,7 +281,7 @@ func (c *Config) Validate(r *Revid) error {
}
if c.Timeout == "" {
c.Logger.Log(smartlogger.Warning, "No timeout defined, defaulting to 0!")
c.Logger.Log(smartlogger.Warning, "No timeout defined, defaulting", "timeout", defaultTimeout)
c.Timeout = defaultTimeout
} else {
if integer, err := strconv.Atoi(c.Timeout); integer < 0 || err != nil {
@ -271,7 +290,8 @@ func (c *Config) Validate(r *Revid) error {
}
if c.IntraRefreshPeriod == "" {
c.Logger.Log(smartlogger.Warning, "No intra refresh defined, defaulting to 100!")
c.Logger.Log(smartlogger.Warning, "No intra refresh defined, defaulting", "intraRefresh",
defaultIntraRefreshPeriod)
c.IntraRefreshPeriod = defaultIntraRefreshPeriod
} else {
if integer, err := strconv.Atoi(c.IntraRefreshPeriod); integer < 0 || err != nil {
@ -280,7 +300,8 @@ func (c *Config) Validate(r *Revid) error {
}
if c.Quantization == "" {
c.Logger.Log(smartlogger.Warning, "No quantization defined")
c.Logger.Log(smartlogger.Warning, "No quantization defined, defaulting", "quantization",
defaultQuantization)
c.Quantization = defaultQuantization
} else {
if integer, err := strconv.Atoi(c.Quantization); integer < 0 || integer > 51 || err != nil {