diff --git a/revid/config.go b/revid/config.go index 209e692c..6f5a0c8a 100644 --- a/revid/config.go +++ b/revid/config.go @@ -152,6 +152,9 @@ const ( defaultRtpAddr = "localhost:6970" defaultBurstPeriod = 10 // Seconds defaultRotation = 0 // Degrees + defaultBrightness = 50 + defaultExposure = "auto" + defaultAutoWhiteBalance = "auto" ) // Validate checks for any errors in the config fields and defaults settings @@ -292,20 +295,32 @@ func (c *Config) Validate(r *Revid) error { c.RtpAddress = defaultRtpAddr } - if c.Brightness < 0 || c.Brightness > 100 { - return errors.New("bad brightness setting in config") + switch { + case c.Brightness == 0: + c.Logger.Log(logger.Info, pkg+"brightness undefined, defaulting", "brightness", defaultBrightness) + c.Brightness = defaultBrightness + case c.Brightness < 0 || c.Brightness > 100: + return errors.New(pkg + "bad brightness defined in config") } if c.Saturation < -100 || c.Saturation > 100 { - return errors.New("bad saturation setting in config") + return errors.New(pkg + "bad saturation setting in config") } - if !stringInSlice(c.Exposure, ExposureModes[:]) { - return errors.New("bad exposure setting in config") + switch { + case c.Exposure == "": + c.Logger.Log(logger.Info, pkg+"exposure undefined, defaulting", "exposure", defaultExposure) + c.Exposure = defaultExposure + case !stringInSlice(c.Exposure, ExposureModes[:]): + return errors.New(pkg + "bad exposure setting in config") } - if !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]) { - return errors.New("bad awb setting in config") + switch { + case c.AutoWhiteBalance == "": + c.Logger.Log(logger.Info, pkg+"auto white balance undefined, defaulting", "autoWhiteBalance", defaultAutoWhiteBalance) + c.AutoWhiteBalance = defaultAutoWhiteBalance + case !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]): + return errors.New(pkg + "bad auto white balance setting in config") } return nil