From 91e5e765f5fedf5c6b023641e3341787a5f8d24a Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 13 Nov 2019 11:46:01 +1030 Subject: [PATCH] fix webcam bug and also consider webcam Input var value --- device/device.go | 2 +- device/webcam/webcam.go | 7 +++++++ revid/revid.go | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/device/device.go b/device/device.go index c66c45e3..08739416 100644 --- a/device/device.go +++ b/device/device.go @@ -60,5 +60,5 @@ type AVDevice interface { type MultiError []error func (me MultiError) Error() string { - return fmt.Sprintf("%v", me) + return fmt.Sprintf("%v", []error(me)) } diff --git a/device/webcam/webcam.go b/device/webcam/webcam.go index 4fe92c40..163e6c11 100644 --- a/device/webcam/webcam.go +++ b/device/webcam/webcam.go @@ -54,6 +54,7 @@ var ( errBadBitrate = errors.New("bitrate bad or unset, defaulting") errBadWidth = errors.New("width bad or unset, defaulting") errBadHeight = errors.New("height bad or unset, defaulting") + errBadInputPath = errors.New("input path bad or unset, defaulting") ) // Webcam is an implementation of the AVDevice interface for a Webcam. Webcam @@ -75,6 +76,12 @@ func New(l config.Logger) *Webcam { // added to the multiError and a default value is used. func (w *Webcam) Set(c config.Config) error { var errs device.MultiError + if c.InputPath == "" { + const defaultInputPath = "/dev/video0" + errs = append(errs, errBadInputPath) + c.InputPath = defaultInputPath + } + if c.Width == 0 { errs = append(errs, errBadWidth) c.Width = defaultWidth diff --git a/revid/revid.go b/revid/revid.go index f5212486..dbb03a2d 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -467,7 +467,7 @@ func (r *Revid) Update(vars map[string]string) error { for key, value := range vars { switch key { case "Input": - v, ok := map[string]uint8{"raspivid": config.InputRaspivid, "rtsp": config.InputRTSP}[strings.ToLower(value)] + v, ok := map[string]uint8{"raspivid": config.InputRaspivid, "rtsp": config.InputRTSP, "v4l": config.InputV4L}[strings.ToLower(value)] if !ok { r.cfg.Logger.Log(logger.Warning, pkg+"invalid input var", "value", value) break