2019-11-02 03:24:50 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
geovision.go
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2017-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
|
|
|
|
|
2019-11-04 08:17:18 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2019-11-02 03:24:50 +03:00
|
|
|
|
2019-11-04 08:17:18 +03:00
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
|
|
|
"bitbucket.org/ausocean/av/input/gvctrl"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
gvDefaultCameraIP = "192.168.1.50"
|
|
|
|
gvDefaultCodec = codecutil.H264
|
|
|
|
gvDefaultHeight = 720
|
|
|
|
gvDefaultFrameRate = 25
|
|
|
|
gvDefaultBitrate = 400
|
|
|
|
gvDefaultVBRBitrate = 400
|
|
|
|
gvDefaultMinFrames = 100
|
|
|
|
gvDefaultVBRQuality = "standard"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
errGVBadCameraIP = errors.New("camera IP bad or unset, defaulting")
|
|
|
|
errGVBadCodec = errors.New("codec bad or unset, defaulting")
|
|
|
|
errGVBadFrameRate = errors.New("frame rate bad or unset, defaulting")
|
|
|
|
errGVBadBitrate = errors.New("bitrate bad or unset, defaulting")
|
|
|
|
errGVBadVBRQuality = errors.New("VBR quality bad or unset, defaulting")
|
|
|
|
errGVBadHeight = errors.New("height bad or unset, defaulting")
|
|
|
|
errGVBadMinFrames = errors.New("min frames bad or unset, defaulting")
|
|
|
|
)
|
|
|
|
|
|
|
|
type GeoVision struct {
|
|
|
|
cfg Config
|
|
|
|
}
|
2019-11-02 03:24:50 +03:00
|
|
|
|
|
|
|
func (g *GeoVision) Set(c Config) error {
|
2019-11-04 08:17:18 +03:00
|
|
|
var errs multiError
|
|
|
|
if c.CameraIP == "" {
|
|
|
|
errs = append(errs, errGVBadCameraIP)
|
|
|
|
c.CameraIP = gvDefaultCameraIP
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c.InputCodec {
|
|
|
|
case codecutil.H264, codecutil.H265, codecutil.MJPEG:
|
|
|
|
default:
|
|
|
|
errs = append(errs, errGVBadCodec)
|
|
|
|
c.InputCodec = gvDefaultCodec
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Height <= 0 {
|
|
|
|
errs = append(errs, errGVBadHeight)
|
|
|
|
c.Height = gvDefaultHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.FrameRate <= 0 {
|
|
|
|
errs = append(errs, errGVBadFrameRate)
|
|
|
|
c.FrameRate = gvDefaultFrameRate
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bitrate <= 0 {
|
|
|
|
errs = append(errs, errGVBadBitrate)
|
|
|
|
c.Bitrate = gvDefaultBitrate
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.MinFrames <= 0 {
|
|
|
|
errs = append(errs, errGVBadMinFrames)
|
|
|
|
c.MinFrames = gvDefaultMinFrames
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c.VBRQuality {
|
|
|
|
case qualityStandard, qualityFair, qualityGood, qualityGreat, qualityExcellent:
|
|
|
|
default:
|
|
|
|
errs = append(errs, errGVBadVBRQuality)
|
|
|
|
c.VBRQuality = defaultVBRQuality
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VBRBitrate <= 0 {
|
|
|
|
errs = append(errs, errGVBadVBRQuality)
|
|
|
|
c.VBRBitrate = defaultVBRBitrate
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.CameraChan != 1 && c.CameraChan != 2 {
|
|
|
|
errs = append(errs, errGVBadVBRQuality)
|
|
|
|
c.CameraChan = defaultCameraChan
|
|
|
|
}
|
|
|
|
|
|
|
|
g.cfg = c
|
|
|
|
|
|
|
|
err := gvctrl.Set(
|
|
|
|
g.cfg.CameraIP,
|
|
|
|
gvctrl.Channel(g.cfg.CameraChan),
|
2019-11-02 03:24:50 +03:00
|
|
|
gvctrl.CodecOut(
|
|
|
|
map[uint8]gvctrl.Codec{
|
|
|
|
codecutil.H264: gvctrl.CodecH264,
|
|
|
|
codecutil.H265: gvctrl.CodecH265,
|
|
|
|
codecutil.MJPEG: gvctrl.CodecMJPEG,
|
2019-11-04 08:17:18 +03:00
|
|
|
}[g.cfg.InputCodec],
|
2019-11-02 03:24:50 +03:00
|
|
|
),
|
2019-11-04 08:17:18 +03:00
|
|
|
gvctrl.Height(int(g.cfg.Height)),
|
|
|
|
gvctrl.FrameRate(int(g.cfg.FrameRate)),
|
|
|
|
gvctrl.VariableBitrate(g.cfg.VBR),
|
2019-11-02 03:24:50 +03:00
|
|
|
gvctrl.VBRQuality(
|
|
|
|
map[quality]gvctrl.Quality{
|
|
|
|
qualityStandard: gvctrl.QualityStandard,
|
|
|
|
qualityFair: gvctrl.QualityFair,
|
|
|
|
qualityGood: gvctrl.QualityGood,
|
|
|
|
qualityGreat: gvctrl.QualityGreat,
|
|
|
|
qualityExcellent: gvctrl.QualityExcellent,
|
2019-11-04 08:17:18 +03:00
|
|
|
}[g.cfg.VBRQuality],
|
2019-11-02 03:24:50 +03:00
|
|
|
),
|
2019-11-04 08:17:18 +03:00
|
|
|
gvctrl.VBRBitrate(g.cfg.VBRBitrate),
|
|
|
|
gvctrl.CBRBitrate(int(g.cfg.Bitrate)),
|
|
|
|
gvctrl.Refresh(float64(g.cfg.MinFrames)/float64(g.cfg.FrameRate)),
|
2019-11-02 03:24:50 +03:00
|
|
|
)
|
|
|
|
if err != nil {
|
2019-11-04 08:17:18 +03:00
|
|
|
return fmt.Errorf("could not set IPCamera settings: %w", err)
|
2019-11-02 03:24:50 +03:00
|
|
|
}
|
2019-11-04 08:17:18 +03:00
|
|
|
return multiError(errs)
|
2019-11-02 03:24:50 +03:00
|
|
|
}
|