diff --git a/revid/config/config.go b/revid/config/config.go index d13157b2..677421c3 100644 --- a/revid/config/config.go +++ b/revid/config/config.go @@ -27,6 +27,8 @@ package config import ( "errors" + "fmt" + "os/exec" "time" "bitbucket.org/ausocean/av/codec/codecutil" @@ -116,6 +118,9 @@ const ( FilterKNN ) +// OS names +const raspian = "Raspbian GNU/Linux" + // Config provides parameters relevant to a revid instance. A new config must // be passed to the constructor. Default values for these fields are defined // as consts above. @@ -236,6 +241,10 @@ type Config struct { // of the file. Exposure string + // ShowWindows enables or disables the display of windows used for debugging + // motion filters. + ShowWindows bool + // AutoWhiteBalance defines the auto white balance mode used by Raspivid input. // Valid modes are defined in the exported []string AutoWhiteBalanceModes // defined at the start of the file. @@ -304,6 +313,7 @@ var TypeData = map[string]string{ "RTMPURL": "string", "RTPAddress": "string", "Saturation": "int", + "ShowWindows": "bool", "VBRBitrate": "int", "VBRQuality": "enum:standard,fair,good,great,excellent", "VerticalFlip": "bool", @@ -442,9 +452,29 @@ func (c *Config) Validate() error { c.PSITime = defaultPSITime } + if c.ShowWindows { + os, err := osName() + if err != nil { + return err + } + if os == raspian { + c.Logger.Log(logger.Info, "ShowWindows disabled on Raspbian GNU/Linux") + c.ShowWindows = false + } + } + return nil } +func osName() (string, error) { + out, err := exec.Command("grep", "^NAME=", "/etc/os-release").Output() + if err != nil { + return "", fmt.Errorf("could not get OS name: %w", err) + } + + return string(out)[6 : len(out)-2], nil +} + // stringInSlice returns true if want is in slice. func stringInSlice(want string, slice []string) bool { for _, s := range slice { diff --git a/revid/revid.go b/revid/revid.go index cdbc1cc5..cc68e02a 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -77,10 +77,7 @@ const ( ) // Motion filter parameters. -const ( - showWindows = true - minFPS = 1.0 -) +const minFPS = 1.0 // KNN specific parameters. const ( @@ -353,11 +350,11 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterNoOp: r.filter = filter.NewNoOp(r.encoders) case config.FilterMOG: - r.filter = filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, showWindows) + r.filter = filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, r.cfg.ShowWindows) case config.FilterVariableFPS: - r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, showWindows)) + r.filter = filter.NewVariableFPSFilter(r.encoders, minFPS, filter.NewMOGFilter(r.encoders, mogMinArea, mogThreshold, mogHistory, r.cfg.ShowWindows)) case config.FilterKNN: - r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, showWindows) + r.filter = filter.NewKNNFilter(r.encoders, knnMinArea, knnThreshold, knnHistory, knnKernel, r.cfg.ShowWindows) default: panic("Undefined Filter") @@ -776,6 +773,16 @@ func (r *Revid) Update(vars map[string]string) error { break } r.cfg.CameraChan = v + case "ShowWindows": + switch strings.ToLower(value) { + case "true": + r.cfg.ShowWindows = true + case "false": + r.cfg.ShowWindows = false + default: + r.cfg.Logger.Log(logger.Warning, pkg+"invalid ShowWindows var", "value", value) + break + } } } r.cfg.Logger.Log(logger.Info, pkg+"revid config changed", "config", fmt.Sprintf("%+v", r.cfg))