mirror of https://bitbucket.org/ausocean/av.git
revid/webcam.go: started writing implementation of AVDevice for webcams
This commit is contained in:
parent
5afad9c5aa
commit
8302e959d9
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
DESCRIPTION
|
||||
webcam.go provides an implementation of AVDevice for webcams.
|
||||
|
||||
AUTHORS
|
||||
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
||||
|
||||
It is free software: you can redistribute it and/or modify them
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package revid
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultWebcamInputPath = "/dev/video0"
|
||||
defaultWebcamFrameRate = 25
|
||||
defaultWebcamBitrate = 400
|
||||
defaultWebcamWidth = 1280
|
||||
defaultWebcamHeight = 720
|
||||
)
|
||||
|
||||
var (
|
||||
errWebcamBadFrameRate = errors.New("frame rate bad or unset, defaulting")
|
||||
errWebcamBadBitrate = errors.New("bitrate bad or unset, defaulting")
|
||||
errWebcamWidth = errors.New("width bad or unset, defaulting")
|
||||
errWebcamHeight = errors.New("height bad or unset, defaulting")
|
||||
)
|
||||
|
||||
type Webcam struct {
|
||||
out io.ReadCloser
|
||||
log Logger
|
||||
cfg Config
|
||||
}
|
||||
|
||||
func NewWebcam(l Logger) *Webcam {
|
||||
return &Webcam{log: l}
|
||||
}
|
||||
|
||||
func (w *Webcam) Set(c Config) error {
|
||||
var errs []error
|
||||
if c.Width == 0 {
|
||||
errs = append(errs, errBadWidth)
|
||||
c.Width = raspividDefaultWidth
|
||||
}
|
||||
|
||||
if c.Height == 0 {
|
||||
errs = append(errs, errBadHeight)
|
||||
c.Height = raspividDefaultHeight
|
||||
}
|
||||
|
||||
if c.FrameRate == 0 {
|
||||
errs = append(errs, errBadFrameRate)
|
||||
c.FrameRate = raspividDefaultFramerate
|
||||
}
|
||||
|
||||
if c.Bitrate <= 0 {
|
||||
errs = append(errs, errBadBitrate)
|
||||
c.Bitrate = raspividDefaultBitrate
|
||||
}
|
||||
w.cfg = c
|
||||
return multiError(errs)
|
||||
}
|
Loading…
Reference in New Issue