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 defaultFramesPerClip = 1
defaultVerticalFlip = No defaultVerticalFlip = No
defaultHorizontalFlip = No defaultHorizontalFlip = No
httpFramesPerClip = 7
defaultInputCodec = H264
defaultVerbosity = No
) )
// Validate checks for any errors in the config fields and defaults settings // 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 Yes:
case No: case No:
case NothingDefined: case NothingDefined:
c.Verbosity = Yes c.Verbosity = defaultVerbosity
c.Logger.Log(smartlogger.Warning, "No verbosity mode defined, defaulting to no Verbosity!") c.Logger.Log(smartlogger.Warning, "No verbosity mode defined, defaulting",
"verbosity", defaultVerbosity)
default: default:
return errors.New("Bad Verbosity defined in config!") return errors.New("Bad Verbosity defined in config!")
} }
@ -118,7 +122,8 @@ func (c *Config) Validate(r *Revid) error {
case QuantizationOn: case QuantizationOn:
case QuantizationOff: case QuantizationOff:
case NothingDefined: 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 c.QuantizationMode = QuantizationOff
default: default:
return errors.New("Bad QuantizationMode defined in config!") return errors.New("Bad QuantizationMode defined in config!")
@ -128,7 +133,8 @@ func (c *Config) Validate(r *Revid) error {
case Raspivid: case Raspivid:
case File: case File:
case NothingDefined: 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 c.Input = defaultInput
default: default:
return errors.New("Bad input type defined in config!") return errors.New("Bad input type defined in config!")
@ -160,9 +166,11 @@ func (c *Config) Validate(r *Revid) error {
} }
} }
case NothingDefined: case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No input codec defined, defaulting to h264!") c.Logger.Log(smartlogger.Warning, "No input codec defined, defaulting",
c.InputCodec = H264 "inputCodec", defaultInputCodec)
c.Logger.Log(smartlogger.Warning, "Defaulting bitrate to 0 and quantization to 35!") c.InputCodec = defaultInputCodec
c.Logger.Log(smartlogger.Warning, "Defaulting quantization", "quantization",
defaultQuantization)
c.Quantization = defaultQuantization c.Quantization = defaultQuantization
default: default:
return errors.New("Bad input codec defined in config!") return errors.New("Bad input codec defined in config!")
@ -176,15 +184,18 @@ func (c *Config) Validate(r *Revid) error {
c.Output = Http c.Output = Http
break break
} }
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip to 1 for rtmp output!") c.Logger.Log(smartlogger.Info, "Defaulting frames per clip for rtmp out",
c.FramesPerClip = 1 "framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip
case NothingDefined: 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 c.Output = defaultOutput
fallthrough fallthrough
case Http: case Http:
c.Logger.Log(smartlogger.Info, "Defaulting frames per clip to 7 for http output!") c.Logger.Log(smartlogger.Info, "Defaulting frames per clip for http out",
c.FramesPerClip = 7 "framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip
default: default:
return errors.New("Bad output type defined in config!") return errors.New("Bad output type defined in config!")
} }
@ -194,8 +205,9 @@ func (c *Config) Validate(r *Revid) error {
case Mpegts: case Mpegts:
case Flv: case Flv:
case NothingDefined: case NothingDefined:
c.Logger.Log(smartlogger.Warning, "No packetization option defined, defaulting to none!") c.Logger.Log(smartlogger.Warning, "No packetization option defined, defaulting",
c.Packetization = Flv "packetization", defaultPacketization)
c.Packetization = defaultPacketization
default: default:
return errors.New("Bad packetization option defined in config!") return errors.New("Bad packetization option defined in config!")
} }
@ -204,7 +216,8 @@ func (c *Config) Validate(r *Revid) error {
case Yes: case Yes:
case No: case No:
case NothingDefined: 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 c.HorizontalFlip = defaultHorizontalFlip
default: default:
return errors.New("Bad horizontal flip option defined in config!") return errors.New("Bad horizontal flip option defined in config!")
@ -214,19 +227,22 @@ func (c *Config) Validate(r *Revid) error {
case Yes: case Yes:
case No: case No:
case NothingDefined: 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 c.VerticalFlip = defaultVerticalFlip
default: default:
return errors.New("Bad vertical flip option defined in config!") return errors.New("Bad vertical flip option defined in config!")
} }
if c.FramesPerClip < 1 { 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 c.FramesPerClip = defaultFramesPerClip
} }
if c.Width == "" { 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 c.Width = defaultWidth
} else { } else {
if integer, err := strconv.Atoi(c.Width); integer < 0 || err != nil { 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 == "" { 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 c.Height = defaultHeight
} else { } else {
if integer, err := strconv.Atoi(c.Height); integer < 0 || err != nil { 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 == "" { 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 c.FrameRate = defaultFrameRate
} else { } else {
if integer, err := strconv.Atoi(c.FrameRate); integer < 0 || err != nil { 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 == "" { 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 c.Bitrate = defaultBitrate
} else { } else {
if integer, err := strconv.Atoi(c.Bitrate); integer < 0 || err != nil { 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 == "" { 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 c.Timeout = defaultTimeout
} else { } else {
if integer, err := strconv.Atoi(c.Timeout); integer < 0 || err != nil { 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 == "" { 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 c.IntraRefreshPeriod = defaultIntraRefreshPeriod
} else { } else {
if integer, err := strconv.Atoi(c.IntraRefreshPeriod); integer < 0 || err != nil { 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 == "" { 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 c.Quantization = defaultQuantization
} else { } else {
if integer, err := strconv.Atoi(c.Quantization); integer < 0 || integer > 51 || err != nil { if integer, err := strconv.Atoi(c.Quantization); integer < 0 || integer > 51 || err != nil {