fix webcam bug and also consider webcam Input var value

This commit is contained in:
Saxon 2019-11-13 11:46:01 +10:30
parent 1a65dc9da4
commit 91e5e765f5
3 changed files with 9 additions and 2 deletions

View File

@ -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))
}

View File

@ -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

View File

@ -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