From 9d5771fcbf1aeda2255df3feb1085d945b902873 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 15 Mar 2019 17:24:29 +1030 Subject: [PATCH] revid: completed addition of exposure, awb, saturation and brightness options --- cmd/revid-cli/main.go | 14 ++++------ revid/config.go | 65 +++++++++++++++++++++++++++++++++++++------ revid/revid.go | 26 +++++++++++------ 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 9c5b0fc8..ce6dc5fa 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -128,12 +128,10 @@ func handleFlags() revid.Config { logPathPtr = flag.String("LogPath", defaultLogPath, "The log path") configFilePtr = flag.String("ConfigFile", "", "NetSender config file") sendRetryPtr = flag.Bool("retry", false, "Specify whether a failed send should be retried.") - - brightnessPtr = flag.Uint("Brightness", -1, "Set Brightness: 0-100 ") - saturationPtr = flag.Uint("Saturation", 0, "Set Saturation: -100:100") - exposurePtr = flag.String("Exposure", "", "Set Exposure Mode: Auto/Night/Spotlight") - autoWhiteBalancePtr = flag.String("AutoWhiteBalance", "", "Set Automatic White Balance mode") - + brightnessPtr = flag.Uint("Brightness", 50, "Set Brightness: 0-100 ") + saturationPtr = flag.Int("Saturation", 0, "Set Saturation: -100:100") + exposurePtr = flag.String("Exposure", "", "Set exposure mode: "+strings.Join(revid.ExposureModes[:], ",")) + autoWhiteBalancePtr = flag.String("Awb", "", "Set automatic white balance mode: "+strings.Join(revid.AwbModes[:], ",")) ) var outputs flagStrings @@ -240,7 +238,6 @@ func handleFlags() revid.Config { log.Log(logger.Error, pkg+"bad packetization argument") } - if *configFilePtr != "" { netsender.ConfigFile = *configFilePtr } @@ -261,11 +258,10 @@ func handleFlags() revid.Config { cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr cfg.RtpAddress = *rtpAddrPtr cfg.SendRetry = *sendRetryPtr - cfg.Brightness = *brightnessPtr cfg.Saturation = *saturationPtr cfg.Exposure = *exposurePtr - cfg.AutoWhiteBalance = *autoWhiteBalancePtr + cfg.Awb = *autoWhiteBalancePtr return cfg } diff --git a/revid/config.go b/revid/config.go index b142e8f4..dab5a565 100644 --- a/revid/config.go +++ b/revid/config.go @@ -69,11 +69,38 @@ type Config struct { Logger Logger SendRetry bool BurstPeriod uint + Brightness uint + Saturation int + Exposure string + Awb string +} - Brightness uint - Saturation uint - Exposure string - AutoWhiteBalance string +var ExposureModes = [...]string{ + "auto", + "night", + "nightpreview", + "backlight", + "spotlight", + "sports", + "snow", + "beach", + "verylong", + "fixedfps", + "antishake", + "fireworks", +} + +var AwbModes = [...]string{ + "off", + "auto", + "sun", + "cloud", + "shade", + "tungsten", + "fluorescent", + "incandescent", + "flash", + "horizon", } // Enums for config struct @@ -121,10 +148,6 @@ const ( defaultVerbosity = No // FIXME(kortschak): This makes no sense whatsoever. No is currently 15. defaultRtpAddr = "localhost:6970" defaultBurstPeriod = 10 // Seconds - - notDefinedBrightness =-1 //outside range (0-100) - notDefinedSaturation =-101 //outside range (-100-(100)) - ) // Validate checks for any errors in the config fields and defaults settings @@ -259,5 +282,31 @@ func (c *Config) Validate(r *Revid) error { if c.RtpAddress == "" { c.RtpAddress = defaultRtpAddr } + + if c.Brightness < 0 || c.Brightness > 100 { + return errors.New("bad brightness setting in config") + } + + if c.Saturation < -100 || c.Saturation > 100 { + return errors.New("bad saturation setting in config") + } + + if !stringInSlice(c.Exposure, ExposureModes[:]) { + return errors.New("bad exposure setting in config") + } + + if !stringInSlice(c.Awb, AwbModes[:]) { + return errors.New("bad awb setting in config") + } + return nil } + +func stringInSlice(want string, slice []string) bool { + for _, s := range slice { + if s == want { + return true + } + } + return false +} diff --git a/revid/revid.go b/revid/revid.go index 3524c969..cee8fc0d 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -386,6 +386,22 @@ func (r *Revid) Update(vars map[string]string) error { //look through the vars and update revid where needed for key, value := range vars { switch key { + case "Saturation": + s, err := strconv.ParseInt(value, 10, 0) + if err != nil { + r.config.Logger.Log(logger.Warning, pkg+"invalid saturation param", "value", value) + } + r.config.Saturation = int(s) + case "Brightness": + b, err := strconv.ParseUint(value, 10, 0) + if err != nil { + r.config.Logger.Log(logger.Warning, pkg+"invalid brightness param", "value", value) + } + r.config.Brightness = uint(b) + case "Exposure": + r.config.Exposure = value + case "Awb": + r.config.Awb = value case "Output": r.config.Outputs = make([]uint8, 1) // FIXME(kortschak): There can be only one! @@ -609,18 +625,12 @@ func (r *Revid) startRaspivid() error { "--height", fmt.Sprint(r.config.Height), "--bitrate", fmt.Sprint(r.config.Bitrate), "--framerate", fmt.Sprint(r.config.FrameRate), - "--brightness", fmt.Sprint(r.config.Brightness), "--saturation", fmt.Sprint(r.config.Saturation), "--exposure", fmt.Sprint(r.config.Exposure), - "--awb", fmt.Sprint(r.config.AutoWhiteBalance), - } - if cfg.Brightness != notDefinedBrightness { - args = append(args, "--brightness") - } - if cfg.Saturation != notDefinedSaturation { - args = append(args, "--saturation") + "--awb", fmt.Sprint(r.config.Awb), } + if r.config.FlipHorizontal { args = append(args, "--hflip") }