From 9a510f5c31eda897eb467d0578c769c1fe2ea769 Mon Sep 17 00:00:00 2001 From: Matthew Michael Date: Fri, 15 Mar 2019 12:44:13 +1030 Subject: [PATCH 1/6] cmd/revid-cli & revid: adding raspivid exposure and brightness parameters Started working on adding exposure, brightness, saturation and awb flags to revid-cli so that we can control raspivid parameters. Updated revid logic to give these to raspivid and updated config to consider these parameters in config validation. --- cmd/revid-cli/main.go | 12 ++++++++++++ revid/config.go | 9 +++++++++ revid/revid.go | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 625d9356..9c5b0fc8 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -128,6 +128,12 @@ 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") + ) var outputs flagStrings @@ -234,6 +240,7 @@ func handleFlags() revid.Config { log.Log(logger.Error, pkg+"bad packetization argument") } + if *configFilePtr != "" { netsender.ConfigFile = *configFilePtr } @@ -255,6 +262,11 @@ func handleFlags() revid.Config { cfg.RtpAddress = *rtpAddrPtr cfg.SendRetry = *sendRetryPtr + cfg.Brightness = *brightnessPtr + cfg.Saturation = *saturationPtr + cfg.Exposure = *exposurePtr + cfg.AutoWhiteBalance = *autoWhiteBalancePtr + return cfg } diff --git a/revid/config.go b/revid/config.go index 56292a08..b142e8f4 100644 --- a/revid/config.go +++ b/revid/config.go @@ -69,6 +69,11 @@ type Config struct { Logger Logger SendRetry bool BurstPeriod uint + + Brightness uint + Saturation uint + Exposure string + AutoWhiteBalance string } // Enums for config struct @@ -116,6 +121,10 @@ 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 diff --git a/revid/revid.go b/revid/revid.go index f36cbca0..3524c969 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -609,6 +609,17 @@ 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") } if r.config.FlipHorizontal { args = append(args, "--hflip") From 9d5771fcbf1aeda2255df3feb1085d945b902873 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 15 Mar 2019 17:24:29 +1030 Subject: [PATCH 2/6] 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") } From b18502c7bae94add405a12fdfcf297d8c56ee7c9 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 15 Mar 2019 17:32:28 +1030 Subject: [PATCH 3/6] revid: adding defaults for exposure and awb cmd flags --- cmd/revid-cli/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index ce6dc5fa..893f249b 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -130,8 +130,8 @@ func handleFlags() revid.Config { sendRetryPtr = flag.Bool("retry", false, "Specify whether a failed send should be retried.") 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[:], ",")) + exposurePtr = flag.String("Exposure", "auto", "Set exposure mode: "+strings.Join(revid.ExposureModes[:], ",")) + autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode: "+strings.Join(revid.AwbModes[:], ",")) ) var outputs flagStrings From 056f3b75b3275c902a7577114261aceb2b13d037 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 15 Mar 2019 17:58:24 +1030 Subject: [PATCH 4/6] revid: general clean --- cmd/revid-cli/main.go | 8 ++++---- revid/config.go | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 116aa2a7..ea80ef40 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -129,10 +129,10 @@ func handleFlags() revid.Config { quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40") intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") rotationPtr = flag.Uint("Rotatation", 0, "Rotate video output. (0-359 degrees)") - brightnessPtr = flag.Uint("Brightness", 50, "Set Brightness: 0-100 ") - saturationPtr = flag.Int("Saturation", 0, "Set Saturation: -100:100") - exposurePtr = flag.String("Exposure", "auto", "Set exposure mode: "+strings.Join(revid.ExposureModes[:], ",")) - autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode: "+strings.Join(revid.AwbModes[:], ",")) + brightnessPtr = flag.Uint("Brightness", 50, "Set brightness. (0-100) ") + saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") + exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(revid.ExposureModes[:], ",")+")") + autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(revid.AwbModes[:], ",")+")") ) var outputs flagStrings diff --git a/revid/config.go b/revid/config.go index 64183318..216bda42 100644 --- a/revid/config.go +++ b/revid/config.go @@ -73,9 +73,10 @@ type Config struct { Brightness uint Saturation int Exposure string - Awb string + AutoWhiteBalance string } +// Possible modes for raspivid --exposure parameter. var ExposureModes = [...]string{ "auto", "night", @@ -91,7 +92,8 @@ var ExposureModes = [...]string{ "fireworks", } -var AwbModes = [...]string{ +// Possible modes for raspivid --awb parameter. +var AutoWhiteBalanceModes = [...]string{ "off", "auto", "sun", @@ -309,6 +311,7 @@ func (c *Config) Validate(r *Revid) error { return nil } +// stringInSlice returns true if want is in slice. func stringInSlice(want string, slice []string) bool { for _, s := range slice { if s == want { From 39a7b382f628945611edb2599439cd455f630701 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 15 Mar 2019 18:05:15 +1030 Subject: [PATCH 5/6] revid: fixed build errors --- cmd/revid-cli/main.go | 4 ++-- revid/config.go | 2 +- revid/revid.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index ea80ef40..af87b38e 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -132,7 +132,7 @@ func handleFlags() revid.Config { brightnessPtr = flag.Uint("Brightness", 50, "Set brightness. (0-100) ") saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(revid.ExposureModes[:], ",")+")") - autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(revid.AwbModes[:], ",")+")") + autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(revid.AutoWhiteBalanceModes[:], ",")+")") ) var outputs flagStrings @@ -263,7 +263,7 @@ func handleFlags() revid.Config { cfg.Brightness = *brightnessPtr cfg.Saturation = *saturationPtr cfg.Exposure = *exposurePtr - cfg.Awb = *autoWhiteBalancePtr + cfg.AutoWhiteBalance = *autoWhiteBalancePtr return cfg } diff --git a/revid/config.go b/revid/config.go index 216bda42..209e692c 100644 --- a/revid/config.go +++ b/revid/config.go @@ -304,7 +304,7 @@ func (c *Config) Validate(r *Revid) error { return errors.New("bad exposure setting in config") } - if !stringInSlice(c.Awb, AwbModes[:]) { + if !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]) { return errors.New("bad awb setting in config") } diff --git a/revid/revid.go b/revid/revid.go index cb04733d..950bc0fa 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -373,7 +373,7 @@ func (r *Revid) Update(vars map[string]string) error { case "Exposure": r.config.Exposure = value case "Awb": - r.config.Awb = value + r.config.AutoWhiteBalance = value case "Output": outputs := strings.Split(value, ",") r.config.Outputs = make([]uint8, len(outputs)) @@ -613,7 +613,7 @@ func (r *Revid) startRaspivid() error { "--brightness", fmt.Sprint(r.config.Brightness), "--saturation", fmt.Sprint(r.config.Saturation), "--exposure", fmt.Sprint(r.config.Exposure), - "--awb", fmt.Sprint(r.config.Awb), + "--awb", fmt.Sprint(r.config.AutoWhiteBalance), } if r.config.FlipHorizontal { From 01a5759bdeef2a146cdcc2076108a138b18418a6 Mon Sep 17 00:00:00 2001 From: Saxon Date: Sun, 17 Mar 2019 09:51:09 +1030 Subject: [PATCH 6/6] revid: changed remote param label for auto white balance from Awb to AutoWhiteBalance --- revid/revid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revid/revid.go b/revid/revid.go index 950bc0fa..198bc547 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -372,7 +372,7 @@ func (r *Revid) Update(vars map[string]string) error { r.config.Brightness = uint(b) case "Exposure": r.config.Exposure = value - case "Awb": + case "AutoWhiteBalance": r.config.AutoWhiteBalance = value case "Output": outputs := strings.Split(value, ",")