From 772c381293ea39b1d1815c69203e5681259a0c66 Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 8 Nov 2019 17:29:01 +1030 Subject: [PATCH 1/2] device/geovision: renamed gvctrl package to config --- .../gvctrl-cli => config/config-cli}/main.go | 34 +++++------ .../{gvctrl/gvctrl.go => config/config.go} | 6 +- .../gvctrl_test.go => config/config_test.go} | 4 +- .../geovision/{gvctrl => config}/request.go | 2 +- device/geovision/{gvctrl => config}/utils.go | 2 +- device/geovision/geovision.go | 60 +++++++++---------- revid/inputs.go | 44 +++++++------- 7 files changed, 75 insertions(+), 77 deletions(-) rename device/geovision/{gvctrl/gvctrl-cli => config/config-cli}/main.go (69%) rename device/geovision/{gvctrl/gvctrl.go => config/config.go} (98%) rename device/geovision/{gvctrl/gvctrl_test.go => config/config_test.go} (99%) rename device/geovision/{gvctrl => config}/request.go (99%) rename device/geovision/{gvctrl => config}/utils.go (99%) diff --git a/device/geovision/gvctrl/gvctrl-cli/main.go b/device/geovision/config/config-cli/main.go similarity index 69% rename from device/geovision/gvctrl/gvctrl-cli/main.go rename to device/geovision/config/config-cli/main.go index 8e5eb942..9956d264 100644 --- a/device/geovision/gvctrl/gvctrl-cli/main.go +++ b/device/geovision/config/config-cli/main.go @@ -22,8 +22,6 @@ LICENSE in gpl.txt. If not, see http://www.gnu.org/licenses. */ -// Package gvctrl-cli provides a command line interface for controlling GeoVision -// camera settings using the gvctrl package. package main import ( @@ -31,7 +29,7 @@ import ( "fmt" "strconv" - "bitbucket.org/ausocean/av/device/geovision/gvctrl" + "bitbucket.org/ausocean/av/device/geovision/config" ) func main() { @@ -48,51 +46,51 @@ func main() { ) flag.Parse() - var options []gvctrl.Option + var options []config.Option if *codecPtr != "" { - var c gvctrl.Codec + var c config.Codec switch *codecPtr { case "h264": - c = gvctrl.CodecH264 + c = config.CodecH264 case "h265": - c = gvctrl.CodecH265 + c = config.CodecH265 case "mjpeg": - c = gvctrl.CodecMJPEG + c = config.CodecMJPEG default: panic(fmt.Sprintf("invalid codec: %s", *codecPtr)) } - options = append(options, gvctrl.CodecOut(c)) + options = append(options, config.CodecOut(c)) } if *heightPtr != 0 { - options = append(options, gvctrl.Height(*heightPtr)) + options = append(options, config.Height(*heightPtr)) } if *fpsPtr != 0 { - options = append(options, gvctrl.FrameRate(*fpsPtr)) + options = append(options, config.FrameRate(*fpsPtr)) } - options = append(options, gvctrl.VariableBitrate(*vbrPtr)) + options = append(options, config.VariableBitrate(*vbrPtr)) if *vbrQualityPtr != -1 { - options = append(options, gvctrl.VBRQuality(gvctrl.Quality(strconv.Itoa(*vbrQualityPtr)))) + options = append(options, config.VBRQuality(config.Quality(strconv.Itoa(*vbrQualityPtr)))) } if *vbrRatePtr != 0 { - options = append(options, gvctrl.VBRBitrate(*vbrRatePtr)) + options = append(options, config.VBRBitrate(*vbrRatePtr)) } if *cbrRatePtr != 0 { - options = append(options, gvctrl.CBRBitrate(*cbrRatePtr)) + options = append(options, config.CBRBitrate(*cbrRatePtr)) } if *refreshPtr != 0 { - options = append(options, gvctrl.Refresh(*refreshPtr)) + options = append(options, config.Refresh(*refreshPtr)) } - err := gvctrl.Set(*hostPtr, options...) + err := config.Set(*hostPtr, options...) if err != nil { - panic(fmt.Sprintf("error from gvctrl.Set: %v", err)) + panic(fmt.Sprintf("error from config.Set: %v", err)) } } diff --git a/device/geovision/gvctrl/gvctrl.go b/device/geovision/config/config.go similarity index 98% rename from device/geovision/gvctrl/gvctrl.go rename to device/geovision/config/config.go index 4017891f..0993dcec 100644 --- a/device/geovision/gvctrl/gvctrl.go +++ b/device/geovision/config/config.go @@ -1,6 +1,6 @@ /* DESCRIPTION - gvctrl.go provides exported functionality of a basic API to allow programmatic + config.go provides exported functionality of a basic API to allow programmatic control over the GeoVision camera (namely the GV-BX4700) through the HTTP server used for settings control. See package documentation for further information on the API. @@ -25,14 +25,14 @@ LICENSE in gpl.txt. If not, see http://www.gnu.org/licenses. */ -// Package gvctrl provides a basic API for programmatic control of the +// Package config provides a basic API for programmatic control of the // web based interface provided by GeoVision cameras. This API has been // developed and tested only with the GV-BX4700, and therefore may not work // with other models without further evolution. // // Settings on a GeoVision camera are updated using the Set function. One or // more option functions may be provided to control camera function. -package gvctrl +package config import ( "errors" diff --git a/device/geovision/gvctrl/gvctrl_test.go b/device/geovision/config/config_test.go similarity index 99% rename from device/geovision/gvctrl/gvctrl_test.go rename to device/geovision/config/config_test.go index 7acbc6a3..99592b5d 100644 --- a/device/geovision/gvctrl/gvctrl_test.go +++ b/device/geovision/config/config_test.go @@ -1,6 +1,6 @@ /* DESCRIPTION - gvctrl_test.go provides tests of functionality in the gvctrl package. + config_test.go provides tests of functionality in the config package. AUTHORS Saxon A. Nelson-Milton @@ -22,7 +22,7 @@ LICENSE in gpl.txt. If not, see http://www.gnu.org/licenses. */ -package gvctrl +package config import ( "errors" diff --git a/device/geovision/gvctrl/request.go b/device/geovision/config/request.go similarity index 99% rename from device/geovision/gvctrl/request.go rename to device/geovision/config/request.go index df33dd3c..6ee07788 100644 --- a/device/geovision/gvctrl/request.go +++ b/device/geovision/config/request.go @@ -23,7 +23,7 @@ LICENSE in gpl.txt. If not, see http://www.gnu.org/licenses. */ -package gvctrl +package config import ( "bytes" diff --git a/device/geovision/gvctrl/utils.go b/device/geovision/config/utils.go similarity index 99% rename from device/geovision/gvctrl/utils.go rename to device/geovision/config/utils.go index a92cd2f8..88f52183 100644 --- a/device/geovision/gvctrl/utils.go +++ b/device/geovision/config/utils.go @@ -23,7 +23,7 @@ LICENSE in gpl.txt. If not, see http://www.gnu.org/licenses. */ -package gvctrl +package config import ( "crypto/md5" diff --git a/device/geovision/geovision.go b/device/geovision/geovision.go index 6eaf6949..c51afb59 100644 --- a/device/geovision/geovision.go +++ b/device/geovision/geovision.go @@ -35,11 +35,11 @@ import ( "bitbucket.org/ausocean/av/codec/codecutil" "bitbucket.org/ausocean/av/device" - "bitbucket.org/ausocean/av/device/geovision/gvctrl" + gvconfig "bitbucket.org/ausocean/av/device/geovision/config" "bitbucket.org/ausocean/av/protocol/rtcp" "bitbucket.org/ausocean/av/protocol/rtp" "bitbucket.org/ausocean/av/protocol/rtsp" - "bitbucket.org/ausocean/av/revid/config" + avconfig "bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/utils/logger" ) @@ -53,7 +53,7 @@ const ( defaultServerRTCPPort = 17301 ) -// TODO: remove this when gvctrl has configurable user and pass. +// TODO: remove this when config has configurable user and pass. const ( ipCamUser = "admin" ipCamPass = "admin" @@ -68,7 +68,7 @@ const ( defaultBitrate = 400 defaultVBRBitrate = 400 defaultMinFrames = 100 - defaultVBRQuality = config.QualityStandard + defaultVBRQuality = avconfig.QualityStandard defaultCameraChan = 2 ) @@ -87,21 +87,21 @@ var ( // IP camera. This has been designed to implement the GV-BX4700-8F in particular. // Any other models are untested. type GeoVision struct { - cfg config.Config - log config.Logger + cfg avconfig.Config + log avconfig.Logger rtpClt *rtp.Client rtspClt *rtsp.Client rtcpClt *rtcp.Client } // NewGeoVision returns a new GeoVision. -func NewGeoVision(l config.Logger) *GeoVision { return &GeoVision{log: l} } +func NewGeoVision(l avconfig.Logger) *GeoVision { return &GeoVision{log: l} } // Set will take a Config struct, check the validity of the relevant fields -// and then performs any configuration necessary using gvctrl to control the +// and then performs any configuration necessary using config to control the // GeoVision web interface. If fields are not valid, an error is added to the // multiError and a default value is used for that particular field. -func (g *GeoVision) Set(c config.Config) error { +func (g *GeoVision) Set(c avconfig.Config) error { var errs device.MultiError if c.CameraIP == "" { errs = append(errs, errGVBadCameraIP) @@ -136,7 +136,7 @@ func (g *GeoVision) Set(c config.Config) error { } switch c.VBRQuality { - case config.QualityStandard, config.QualityFair, config.QualityGood, config.QualityGreat, config.QualityExcellent: + case avconfig.QualityStandard, avconfig.QualityFair, avconfig.QualityGood, avconfig.QualityGreat, avconfig.QualityExcellent: default: errs = append(errs, errGVBadVBRQuality) c.VBRQuality = defaultVBRQuality @@ -154,31 +154,31 @@ func (g *GeoVision) Set(c config.Config) error { g.cfg = c - err := gvctrl.Set( + err := gvconfig.Set( g.cfg.CameraIP, - gvctrl.Channel(g.cfg.CameraChan), - gvctrl.CodecOut( - map[uint8]gvctrl.Codec{ - codecutil.H264: gvctrl.CodecH264, - codecutil.H265: gvctrl.CodecH265, - codecutil.MJPEG: gvctrl.CodecMJPEG, + gvconfig.Channel(g.cfg.CameraChan), + gvconfig.CodecOut( + map[uint8]gvconfig.Codec{ + codecutil.H264: gvconfig.CodecH264, + codecutil.H265: gvconfig.CodecH265, + codecutil.MJPEG: gvconfig.CodecMJPEG, }[g.cfg.InputCodec], ), - gvctrl.Height(int(g.cfg.Height)), - gvctrl.FrameRate(int(g.cfg.FrameRate)), - gvctrl.VariableBitrate(g.cfg.VBR), - gvctrl.VBRQuality( - map[config.Quality]gvctrl.Quality{ - config.QualityStandard: gvctrl.QualityStandard, - config.QualityFair: gvctrl.QualityFair, - config.QualityGood: gvctrl.QualityGood, - config.QualityGreat: gvctrl.QualityGreat, - config.QualityExcellent: gvctrl.QualityExcellent, + gvconfig.Height(int(g.cfg.Height)), + gvconfig.FrameRate(int(g.cfg.FrameRate)), + gvconfig.VariableBitrate(g.cfg.VBR), + gvconfig.VBRQuality( + map[avconfig.Quality]gvconfig.Quality{ + avconfig.QualityStandard: gvconfig.QualityStandard, + avconfig.QualityFair: gvconfig.QualityFair, + avconfig.QualityGood: gvconfig.QualityGood, + avconfig.QualityGreat: gvconfig.QualityGreat, + avconfig.QualityExcellent: gvconfig.QualityExcellent, }[g.cfg.VBRQuality], ), - gvctrl.VBRBitrate(g.cfg.VBRBitrate), - gvctrl.CBRBitrate(int(g.cfg.Bitrate)), - gvctrl.Refresh(float64(g.cfg.MinFrames)/float64(g.cfg.FrameRate)), + gvconfig.VBRBitrate(g.cfg.VBRBitrate), + gvconfig.CBRBitrate(int(g.cfg.Bitrate)), + gvconfig.Refresh(float64(g.cfg.MinFrames)/float64(g.cfg.FrameRate)), ) if err != nil { return fmt.Errorf("could not set IPCamera settings: %w", err) diff --git a/revid/inputs.go b/revid/inputs.go index a31e0201..cb5b9c3c 100644 --- a/revid/inputs.go +++ b/revid/inputs.go @@ -40,7 +40,7 @@ import ( "time" "bitbucket.org/ausocean/av/codec/codecutil" - "bitbucket.org/ausocean/av/device/geovision/gvctrl" + gvconfig "bitbucket.org/ausocean/av/device/geovision/config" "bitbucket.org/ausocean/av/protocol/rtcp" "bitbucket.org/ausocean/av/protocol/rtp" "bitbucket.org/ausocean/av/protocol/rtsp" @@ -48,7 +48,7 @@ import ( "bitbucket.org/ausocean/utils/logger" ) -// TODO: remove this when gvctrl has configurable user and pass. +// TODO: remove this when config has configurable user and pass. const ( ipCamUser = "admin" ipCamPass = "admin" @@ -194,31 +194,31 @@ func (r *Revid) setupInputForFile() (func() error, error) { func (r *Revid) startRTSPCamera() (func() error, error) { r.cfg.Logger.Log(logger.Info, pkg+"starting geovision...") - err := gvctrl.Set( + err := gvconfig.Set( r.cfg.CameraIP, - gvctrl.Channel(r.cfg.CameraChan), - gvctrl.CodecOut( - map[uint8]gvctrl.Codec{ - codecutil.H264: gvctrl.CodecH264, - codecutil.H265: gvctrl.CodecH265, - codecutil.MJPEG: gvctrl.CodecMJPEG, + gvconfig.Channel(r.cfg.CameraChan), + gvconfig.CodecOut( + map[uint8]gvconfig.Codec{ + codecutil.H264: gvconfig.CodecH264, + codecutil.H265: gvconfig.CodecH265, + codecutil.MJPEG: gvconfig.CodecMJPEG, }[r.cfg.InputCodec], ), - gvctrl.Height(int(r.cfg.Height)), - gvctrl.FrameRate(int(r.cfg.FrameRate)), - gvctrl.VariableBitrate(r.cfg.VBR), - gvctrl.VBRQuality( - map[config.Quality]gvctrl.Quality{ - config.QualityStandard: gvctrl.QualityStandard, - config.QualityFair: gvctrl.QualityFair, - config.QualityGood: gvctrl.QualityGood, - config.QualityGreat: gvctrl.QualityGreat, - config.QualityExcellent: gvctrl.QualityExcellent, + gvconfig.Height(int(r.cfg.Height)), + gvconfig.FrameRate(int(r.cfg.FrameRate)), + gvconfig.VariableBitrate(r.cfg.VBR), + gvconfig.VBRQuality( + map[config.Quality]gvconfig.Quality{ + config.QualityStandard: gvconfig.QualityStandard, + config.QualityFair: gvconfig.QualityFair, + config.QualityGood: gvconfig.QualityGood, + config.QualityGreat: gvconfig.QualityGreat, + config.QualityExcellent: gvconfig.QualityExcellent, }[r.cfg.VBRQuality], ), - gvctrl.VBRBitrate(r.cfg.VBRBitrate), - gvctrl.CBRBitrate(int(r.cfg.Bitrate)), - gvctrl.Refresh(float64(r.cfg.MinFrames)/float64(r.cfg.FrameRate)), + gvconfig.VBRBitrate(r.cfg.VBRBitrate), + gvconfig.CBRBitrate(int(r.cfg.Bitrate)), + gvconfig.Refresh(float64(r.cfg.MinFrames)/float64(r.cfg.FrameRate)), ) if err != nil { return nil, fmt.Errorf("could not set IPCamera settings: %w", err) From ff54b40bd2c690aec9cd1d46025a60c50bfd4dde Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 8 Nov 2019 17:35:44 +1030 Subject: [PATCH 2/2] revid/inputs.go: using alias avconfig for revid/config package --- revid/inputs.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/revid/inputs.go b/revid/inputs.go index cb5b9c3c..124d800b 100644 --- a/revid/inputs.go +++ b/revid/inputs.go @@ -44,7 +44,7 @@ import ( "bitbucket.org/ausocean/av/protocol/rtcp" "bitbucket.org/ausocean/av/protocol/rtp" "bitbucket.org/ausocean/av/protocol/rtsp" - "bitbucket.org/ausocean/av/revid/config" + avconfig "bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/utils/logger" ) @@ -208,12 +208,12 @@ func (r *Revid) startRTSPCamera() (func() error, error) { gvconfig.FrameRate(int(r.cfg.FrameRate)), gvconfig.VariableBitrate(r.cfg.VBR), gvconfig.VBRQuality( - map[config.Quality]gvconfig.Quality{ - config.QualityStandard: gvconfig.QualityStandard, - config.QualityFair: gvconfig.QualityFair, - config.QualityGood: gvconfig.QualityGood, - config.QualityGreat: gvconfig.QualityGreat, - config.QualityExcellent: gvconfig.QualityExcellent, + map[avconfig.Quality]gvconfig.Quality{ + avconfig.QualityStandard: gvconfig.QualityStandard, + avconfig.QualityFair: gvconfig.QualityFair, + avconfig.QualityGood: gvconfig.QualityGood, + avconfig.QualityGreat: gvconfig.QualityGreat, + avconfig.QualityExcellent: gvconfig.QualityExcellent, }[r.cfg.VBRQuality], ), gvconfig.VBRBitrate(r.cfg.VBRBitrate),