2018-02-27 18:10:38 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
Config.go
|
|
|
|
|
|
|
|
AUTHORS
|
2018-06-07 14:50:57 +03:00
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
2019-05-08 13:01:25 +03:00
|
|
|
Trek Hopton <trek@ausocean.org>
|
2018-02-27 18:10:38 +03:00
|
|
|
|
|
|
|
LICENSE
|
2018-06-08 03:02:13 +03:00
|
|
|
Config.go is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
2018-02-27 18:10:38 +03:00
|
|
|
|
|
|
|
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
|
2018-06-07 14:50:57 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-02-27 18:10:38 +03:00
|
|
|
*/
|
|
|
|
|
2018-02-10 10:08:14 +03:00
|
|
|
package revid
|
|
|
|
|
2018-02-12 10:58:29 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
2019-08-25 10:44:06 +03:00
|
|
|
"time"
|
2018-02-12 10:58:29 +03:00
|
|
|
|
2019-06-05 19:39:55 +03:00
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
2019-01-02 08:09:47 +03:00
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
2018-02-12 10:58:29 +03:00
|
|
|
)
|
|
|
|
|
2019-03-15 10:28:24 +03:00
|
|
|
// Possible modes for raspivid --exposure parameter.
|
2019-03-15 09:54:29 +03:00
|
|
|
var ExposureModes = [...]string{
|
|
|
|
"auto",
|
|
|
|
"night",
|
|
|
|
"nightpreview",
|
|
|
|
"backlight",
|
|
|
|
"spotlight",
|
|
|
|
"sports",
|
|
|
|
"snow",
|
|
|
|
"beach",
|
|
|
|
"verylong",
|
|
|
|
"fixedfps",
|
|
|
|
"antishake",
|
|
|
|
"fireworks",
|
|
|
|
}
|
2019-03-15 05:14:13 +03:00
|
|
|
|
2019-03-15 10:28:24 +03:00
|
|
|
// Possible modes for raspivid --awb parameter.
|
|
|
|
var AutoWhiteBalanceModes = [...]string{
|
2019-03-15 09:54:29 +03:00
|
|
|
"off",
|
|
|
|
"auto",
|
|
|
|
"sun",
|
|
|
|
"cloud",
|
|
|
|
"shade",
|
|
|
|
"tungsten",
|
|
|
|
"fluorescent",
|
|
|
|
"incandescent",
|
|
|
|
"flash",
|
|
|
|
"horizon",
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-05-13 09:12:16 +03:00
|
|
|
// Enums to define inputs, outputs and codecs.
|
2018-02-10 10:08:14 +03:00
|
|
|
const (
|
2019-05-13 09:12:16 +03:00
|
|
|
// Indicates no option has been set.
|
2018-06-07 14:50:57 +03:00
|
|
|
NothingDefined = iota
|
2019-05-13 09:12:16 +03:00
|
|
|
|
|
|
|
// Input/Output.
|
|
|
|
File
|
|
|
|
|
|
|
|
// Inputs.
|
2018-06-07 14:50:57 +03:00
|
|
|
Raspivid
|
2019-01-17 08:34:04 +03:00
|
|
|
V4L
|
2019-05-21 05:48:52 +03:00
|
|
|
RTSP
|
2019-06-13 17:45:04 +03:00
|
|
|
Audio
|
2019-05-13 09:12:16 +03:00
|
|
|
|
|
|
|
// Outputs.
|
2019-05-13 09:48:41 +03:00
|
|
|
RTMP
|
|
|
|
RTP
|
|
|
|
HTTP
|
|
|
|
MPEGTS
|
2019-05-13 09:12:16 +03:00
|
|
|
|
|
|
|
// Codecs.
|
2018-06-07 14:50:57 +03:00
|
|
|
H264
|
2019-05-27 08:45:26 +03:00
|
|
|
H265
|
2019-05-13 09:48:41 +03:00
|
|
|
MJPEG
|
2018-02-10 10:08:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Default config settings
|
|
|
|
const (
|
2019-08-08 06:50:02 +03:00
|
|
|
// General revid defaults.
|
|
|
|
defaultInput = Raspivid
|
|
|
|
defaultOutput = HTTP
|
|
|
|
defaultFrameRate = 25
|
|
|
|
defaultWriteRate = 25
|
|
|
|
defaultTimeout = 0
|
|
|
|
defaultInputCodec = codecutil.H264
|
|
|
|
defaultVerbosity = logger.Error
|
|
|
|
defaultRtpAddr = "localhost:6970"
|
|
|
|
defaultBurstPeriod = 10 // Seconds
|
|
|
|
|
|
|
|
// Raspivid video defaults.
|
2019-08-25 10:44:06 +03:00
|
|
|
defaultBrightness = 50
|
|
|
|
defaultExposure = "auto"
|
|
|
|
defaultAutoWhiteBalance = "auto"
|
|
|
|
defaultRotation = 0 // Degrees
|
|
|
|
defaultWidth = 1280
|
|
|
|
defaultHeight = 720
|
2019-08-26 07:13:45 +03:00
|
|
|
defaultMinFrames = 100
|
2019-08-25 10:44:06 +03:00
|
|
|
defaultClipDuration = 0
|
|
|
|
defaultQuantization = 30
|
|
|
|
defaultBitrate = 400000
|
2019-04-24 07:28:56 +03:00
|
|
|
|
2019-08-08 06:50:02 +03:00
|
|
|
// Audio defaults.
|
2019-06-05 19:39:55 +03:00
|
|
|
defaultAudioInputCodec = codecutil.ADPCM
|
2019-05-09 05:41:02 +03:00
|
|
|
defaultSampleRate = 48000
|
|
|
|
defaultBitDepth = 16
|
|
|
|
defaultChannels = 1
|
2019-05-22 08:26:58 +03:00
|
|
|
defaultRecPeriod = 1.0
|
2019-08-08 06:50:02 +03:00
|
|
|
|
|
|
|
// Ringbuffer defaults.
|
|
|
|
defaultMTSRBSize = 1000
|
|
|
|
defaultMTSRBElementSize = 100000
|
|
|
|
defaultRTMPRBSize = 500
|
|
|
|
defaultRTMPRBElementSize = 200000
|
2018-02-10 10:08:14 +03:00
|
|
|
)
|
|
|
|
|
2019-05-13 09:12:16 +03:00
|
|
|
// Config provides parameters relevant to a revid instance. A new config must
|
|
|
|
// be passed to the constructor. Default values for these fields are defined
|
2019-05-13 09:42:08 +03:00
|
|
|
// as consts above.
|
2019-05-13 09:12:16 +03:00
|
|
|
type Config struct {
|
2019-05-13 09:42:08 +03:00
|
|
|
// LogLevel is the revid logging verbosity level.
|
|
|
|
// Valid values are defined by enums from the logger package: logger.Debug,
|
|
|
|
// logger.Info, logger.Warning logger.Error, logger.Fatal.
|
2019-05-13 09:12:16 +03:00
|
|
|
LogLevel int8
|
|
|
|
|
2019-05-13 09:42:08 +03:00
|
|
|
// Input defines the input data source.
|
|
|
|
//
|
|
|
|
// Valid values are defined by enums:
|
|
|
|
// Raspivid:
|
|
|
|
// Read data from a Raspberry Pi Camera.
|
|
|
|
// V4l:
|
|
|
|
// Read from webcam.
|
|
|
|
// File:
|
|
|
|
// Location must be specified in InputPath field.
|
2019-05-27 08:45:26 +03:00
|
|
|
// RTSP:
|
|
|
|
// RTSPURL must also be defined.
|
2019-05-13 09:42:08 +03:00
|
|
|
Input uint8
|
|
|
|
|
2019-05-28 06:07:50 +03:00
|
|
|
// InputCodec defines the input codec we wish to use, and therefore defines the
|
|
|
|
// lexer for use in the pipeline. This defaults to H264, but H265 is also a
|
|
|
|
// valid option if we expect this from the input.
|
2019-05-13 09:42:08 +03:00
|
|
|
InputCodec uint8
|
|
|
|
|
|
|
|
// Outputs define the outputs we wish to output data too.
|
|
|
|
//
|
|
|
|
// Valid outputs are defined by enums:
|
|
|
|
// File:
|
|
|
|
// Location must be defined by the OutputPath field. MPEG-TS packetization
|
|
|
|
// is used.
|
2019-05-13 09:53:38 +03:00
|
|
|
// HTTP:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Destination is defined by the sh field located in /etc/netsender.conf.
|
|
|
|
// MPEGT-TS packetization is used.
|
2019-05-13 09:53:38 +03:00
|
|
|
// RTMP:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Destination URL must be defined in the RtmpUrl field. FLV packetization
|
|
|
|
// is used.
|
2019-05-13 09:53:38 +03:00
|
|
|
// RTP:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Destination is defined by RtpAddr field, otherwise it will default to
|
|
|
|
// localhost:6970. MPEGT-TS packetization is used.
|
|
|
|
Outputs []uint8
|
|
|
|
|
2019-05-13 10:25:20 +03:00
|
|
|
// RTMPURL specifies the Rtmp output destination URL. This must be defined if
|
2019-05-13 09:42:08 +03:00
|
|
|
// RTMP is to be used as an output.
|
2019-05-13 10:25:20 +03:00
|
|
|
RTMPURL string
|
|
|
|
|
2019-05-27 08:45:26 +03:00
|
|
|
// RTSPURL specifies the RTSP server URL for RTSP input. This must be defined
|
|
|
|
// when Input is RTSP.
|
|
|
|
RTSPURL string
|
|
|
|
|
2019-05-13 10:25:20 +03:00
|
|
|
// OutputPath defines the output destination for File output. This must be
|
|
|
|
// defined if File output is to be used.
|
|
|
|
OutputPath string
|
|
|
|
|
|
|
|
// InputPath defines the input file location for File Input. This must be
|
|
|
|
// defined if File input is to be used.
|
|
|
|
InputPath string
|
|
|
|
|
|
|
|
// FrameRate defines the input frame rate if configurable by the chosen input.
|
|
|
|
// Raspivid input supports custom framerate.
|
|
|
|
FrameRate uint
|
|
|
|
|
2019-06-13 17:45:04 +03:00
|
|
|
// WriteRate is how many times a second revid encoders will be written to.
|
|
|
|
WriteRate float64
|
|
|
|
|
2019-05-13 10:25:20 +03:00
|
|
|
// HTTPAddress defines a custom HTTP destination if we do not wish to use that
|
|
|
|
// defined in /etc/netsender.conf.
|
|
|
|
HTTPAddress string
|
|
|
|
|
|
|
|
// Quantization defines the quantization level, which may be a value between
|
|
|
|
// 0-40. This will only take effect if the Quantize field is true and if we
|
|
|
|
// are using Raspivid input.
|
|
|
|
Quantization uint
|
|
|
|
|
2019-08-26 07:13:45 +03:00
|
|
|
// MinFrames defines the frequency of key NAL units SPS, PPS and IDR in
|
2019-08-25 10:44:06 +03:00
|
|
|
// number of NAL units. This will also determine the frequency of PSI if the
|
2019-08-26 07:13:45 +03:00
|
|
|
// output container is MPEG-TS. If ClipDuration is less than MinFrames,
|
|
|
|
// ClipDuration will default to MinFrames.
|
|
|
|
MinFrames uint
|
2019-08-25 10:44:06 +03:00
|
|
|
|
|
|
|
// ClipDuration is the duration of MTS data that is sent using HTTP or RTP
|
2019-08-26 07:13:45 +03:00
|
|
|
// output. This defaults to 0, therefore MinFrames will determine the length of
|
2019-08-25 10:44:06 +03:00
|
|
|
// clips by default.
|
|
|
|
ClipDuration time.Duration
|
2019-05-13 10:25:20 +03:00
|
|
|
|
|
|
|
// Logger holds an implementation of the Logger interface as defined in revid.go.
|
|
|
|
// This must be set for revid to work correctly.
|
|
|
|
Logger Logger
|
|
|
|
|
|
|
|
// Brightness and saturation define the brightness and saturation levels for
|
|
|
|
// Raspivid input.
|
|
|
|
Brightness uint
|
|
|
|
Saturation int
|
|
|
|
|
|
|
|
// Exposure defines the exposure mode used by the Raspivid input. Valid modes
|
|
|
|
// are defined in the exported []string ExposureModes defined at the start
|
|
|
|
// of the file.
|
|
|
|
Exposure string
|
|
|
|
|
|
|
|
// AutoWhiteBalance defines the auto white balance mode used by Raspivid input.
|
|
|
|
// Valid modes are defined in the exported []string AutoWhiteBalanceModes
|
|
|
|
// defined at the start of the file.
|
|
|
|
AutoWhiteBalance string
|
|
|
|
|
2019-06-13 17:45:04 +03:00
|
|
|
// Audio
|
|
|
|
SampleRate int // Samples a second (Hz).
|
|
|
|
RecPeriod float64 // How many seconds to record at a time.
|
|
|
|
Channels int // Number of audio channels, 1 for mono, 2 for stereo.
|
|
|
|
BitDepth int // Sample bit depth.
|
2019-06-18 10:54:32 +03:00
|
|
|
ChunkSize int // ChunkSize is the size of the chunks in the audio.Device's ringbuffer.
|
2019-06-13 17:45:04 +03:00
|
|
|
|
2019-05-13 10:25:20 +03:00
|
|
|
RTPAddress string // RTPAddress defines the RTP output destination.
|
|
|
|
BurstPeriod uint // BurstPeriod defines the revid burst period in seconds.
|
|
|
|
Rotation uint // Rotation defines the video rotation angle in degrees Raspivid input.
|
|
|
|
Height uint // Height defines the input video height Raspivid input.
|
2019-08-08 06:50:02 +03:00
|
|
|
Width uint // Width defines the input video width Raspivid input.
|
2019-05-13 10:25:20 +03:00
|
|
|
Bitrate uint // Bitrate specifies the input bitrate for Raspivid input.
|
|
|
|
FlipHorizontal bool // FlipHorizontal flips video horizontally for Raspivid input.
|
|
|
|
FlipVertical bool // FlipVertial flips video vertically for Raspivid input.
|
2019-08-08 06:50:02 +03:00
|
|
|
|
|
|
|
// Ring buffer sizes.
|
|
|
|
RTMPRBSize int // The number of elements in the RTMP sender ringbuffer.
|
|
|
|
RTMPRBElementSize int // The element size in bytes of the RTMP sender RingBuffer.
|
|
|
|
MTSRBSize int // The number of elements in the MTS sender ringbuffer.
|
|
|
|
MTSRBElementSize int // The element size in bytes of the MTS sender RingBuffer.
|
2019-05-13 09:12:16 +03:00
|
|
|
}
|
|
|
|
|
2019-08-24 07:32:24 +03:00
|
|
|
// Validation errors.
|
|
|
|
var (
|
|
|
|
errInvalidQuantization = errors.New("invalid quantization")
|
|
|
|
)
|
|
|
|
|
2018-03-17 16:29:42 +03:00
|
|
|
// Validate checks for any errors in the config fields and defaults settings
|
2018-02-10 10:08:14 +03:00
|
|
|
// if particular parameters have not been defined.
|
2019-08-24 07:32:24 +03:00
|
|
|
func (c *Config) Validate() error {
|
2018-09-22 08:16:54 +03:00
|
|
|
switch c.LogLevel {
|
2019-05-05 13:09:56 +03:00
|
|
|
case logger.Debug:
|
|
|
|
case logger.Info:
|
|
|
|
case logger.Warning:
|
|
|
|
case logger.Error:
|
|
|
|
case logger.Fatal:
|
2018-03-17 16:29:42 +03:00
|
|
|
default:
|
2018-09-22 08:16:54 +03:00
|
|
|
c.LogLevel = defaultVerbosity
|
2019-05-06 09:29:41 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"bad LogLevel mode defined, defaulting", "LogLevel", defaultVerbosity)
|
2018-03-17 16:29:42 +03:00
|
|
|
}
|
|
|
|
|
2018-06-09 05:01:21 +03:00
|
|
|
switch c.Input {
|
2019-06-03 11:20:48 +03:00
|
|
|
case Raspivid, V4L, File, Audio, RTSP:
|
2018-02-10 10:08:14 +03:00
|
|
|
case NothingDefined:
|
2019-05-06 09:29:41 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no input type defined, defaulting", "input", defaultInput)
|
2018-06-09 05:01:21 +03:00
|
|
|
c.Input = defaultInput
|
2018-02-10 10:08:14 +03:00
|
|
|
default:
|
2018-09-20 05:04:17 +03:00
|
|
|
return errors.New("bad input type defined in config")
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2018-06-09 05:01:21 +03:00
|
|
|
switch c.InputCodec {
|
2019-09-24 01:12:26 +03:00
|
|
|
case codecutil.H264, codecutil.MJPEG, codecutil.PCM, codecutil.ADPCM:
|
2019-06-05 19:39:55 +03:00
|
|
|
default:
|
2019-05-09 05:41:02 +03:00
|
|
|
switch c.Input {
|
|
|
|
case Audio:
|
|
|
|
c.Logger.Log(logger.Info, pkg+"input is audio but no codec defined, defaulting", "inputCodec", defaultAudioInputCodec)
|
|
|
|
c.InputCodec = defaultAudioInputCodec
|
|
|
|
default:
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec)
|
|
|
|
c.InputCodec = defaultInputCodec
|
|
|
|
c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization)
|
|
|
|
c.Quantization = defaultQuantization
|
|
|
|
}
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-05-05 16:20:59 +03:00
|
|
|
if c.Outputs == nil {
|
2019-05-06 09:29:41 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no output defined, defaulting", "output", defaultOutput)
|
2019-05-05 16:20:59 +03:00
|
|
|
c.Outputs = append(c.Outputs, defaultOutput)
|
2019-08-24 07:32:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var haveRTMPOut bool
|
|
|
|
for i, o := range c.Outputs {
|
|
|
|
switch o {
|
|
|
|
case File:
|
|
|
|
case RTMP:
|
|
|
|
haveRTMPOut = true
|
|
|
|
if c.Bitrate == 0 {
|
|
|
|
c.Bitrate = defaultBitrate
|
|
|
|
}
|
|
|
|
c.Quantization = 0
|
|
|
|
if c.RTMPURL == "" {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP")
|
|
|
|
c.Outputs[i] = HTTP
|
2019-08-24 08:23:49 +03:00
|
|
|
haveRTMPOut = false
|
2019-08-24 07:32:24 +03:00
|
|
|
}
|
2019-08-24 08:23:49 +03:00
|
|
|
fallthrough
|
2019-08-24 07:32:24 +03:00
|
|
|
case HTTP, RTP:
|
|
|
|
if !haveRTMPOut {
|
|
|
|
c.Bitrate = 0
|
|
|
|
if c.Quantization == 0 {
|
|
|
|
c.Quantization = defaultQuantization
|
2019-05-05 16:20:59 +03:00
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
}
|
2019-08-24 07:32:24 +03:00
|
|
|
default:
|
|
|
|
return errors.New("bad output type defined in config")
|
2018-06-08 03:02:13 +03:00
|
|
|
}
|
2018-11-25 15:40:38 +03:00
|
|
|
}
|
|
|
|
|
2019-02-03 16:13:51 +03:00
|
|
|
if c.BurstPeriod == 0 {
|
2019-03-04 05:17:57 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no burst period defined, defaulting", "burstPeriod", defaultBurstPeriod)
|
2019-02-03 16:13:51 +03:00
|
|
|
c.BurstPeriod = defaultBurstPeriod
|
|
|
|
}
|
|
|
|
|
2019-03-04 04:41:34 +03:00
|
|
|
if c.Rotation > 359 {
|
|
|
|
c.Logger.Log(logger.Warning, pkg+"bad rotate angle, defaulting", "angle", defaultRotation)
|
|
|
|
c.Rotation = defaultRotation
|
2019-03-04 04:37:28 +03:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:09:20 +03:00
|
|
|
if c.Width == 0 {
|
2019-03-04 05:17:57 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no width defined, defaulting", "width", defaultWidth)
|
2018-06-09 05:01:21 +03:00
|
|
|
c.Width = defaultWidth
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:09:20 +03:00
|
|
|
if c.Height == 0 {
|
2019-03-04 05:17:57 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no height defined, defaulting", "height", defaultHeight)
|
2018-06-09 05:01:21 +03:00
|
|
|
c.Height = defaultHeight
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:09:20 +03:00
|
|
|
if c.FrameRate == 0 {
|
2019-03-04 05:17:57 +03:00
|
|
|
c.Logger.Log(logger.Info, pkg+"no frame rate defined, defaulting", "fps", defaultFrameRate)
|
2018-06-09 05:01:21 +03:00
|
|
|
c.FrameRate = defaultFrameRate
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-04-23 08:21:17 +03:00
|
|
|
if c.SampleRate == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no sample rate defined, defaulting", "sampleRate", defaultSampleRate)
|
|
|
|
c.SampleRate = defaultSampleRate
|
|
|
|
}
|
|
|
|
|
2019-05-09 05:41:02 +03:00
|
|
|
if c.Channels == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no number of channels defined, defaulting", "Channels", defaultChannels)
|
|
|
|
c.Channels = defaultChannels
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.BitDepth == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no bit depth defined, defaulting", "BitDepth", defaultBitDepth)
|
|
|
|
c.BitDepth = defaultBitDepth
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RecPeriod == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no record period defined, defaulting", "recPeriod", defaultRecPeriod)
|
|
|
|
c.RecPeriod = defaultRecPeriod
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.WriteRate == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no write rate defined, defaulting", "writeRate", defaultWriteRate)
|
|
|
|
c.WriteRate = defaultWriteRate
|
|
|
|
}
|
|
|
|
|
2019-08-24 07:32:24 +03:00
|
|
|
if c.Bitrate < 0 {
|
|
|
|
return errors.New("invalid bitrate")
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-08-26 07:13:45 +03:00
|
|
|
if c.MinFrames == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no min period defined, defaulting", "MinFrames", defaultMinFrames)
|
|
|
|
c.MinFrames = defaultMinFrames
|
|
|
|
} else if c.MinFrames < 0 {
|
2019-08-25 10:44:06 +03:00
|
|
|
return errors.New("refresh period is less than 0")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ClipDuration == 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"no clip duration defined, defaulting", "ClipDuration", defaultClipDuration)
|
|
|
|
c.ClipDuration = defaultClipDuration
|
|
|
|
} else if c.ClipDuration < 0 {
|
|
|
|
return errors.New("clip duration is less than 0")
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-08-24 07:32:24 +03:00
|
|
|
if c.Quantization != 0 && (c.Quantization < 10 || c.Quantization > 40) {
|
|
|
|
return errInvalidQuantization
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
2018-11-20 17:37:38 +03:00
|
|
|
|
2019-05-13 09:53:38 +03:00
|
|
|
if c.RTPAddress == "" {
|
|
|
|
c.RTPAddress = defaultRtpAddr
|
2018-11-20 17:37:38 +03:00
|
|
|
}
|
2019-03-15 09:54:29 +03:00
|
|
|
|
2019-03-18 03:32:11 +03:00
|
|
|
switch {
|
|
|
|
case c.Brightness == 0:
|
|
|
|
c.Logger.Log(logger.Info, pkg+"brightness undefined, defaulting", "brightness", defaultBrightness)
|
|
|
|
c.Brightness = defaultBrightness
|
|
|
|
case c.Brightness < 0 || c.Brightness > 100:
|
|
|
|
return errors.New(pkg + "bad brightness defined in config")
|
2019-03-15 09:54:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.Saturation < -100 || c.Saturation > 100 {
|
2019-03-18 03:32:11 +03:00
|
|
|
return errors.New(pkg + "bad saturation setting in config")
|
2019-03-15 09:54:29 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 03:32:11 +03:00
|
|
|
switch {
|
|
|
|
case c.Exposure == "":
|
|
|
|
c.Logger.Log(logger.Info, pkg+"exposure undefined, defaulting", "exposure", defaultExposure)
|
|
|
|
c.Exposure = defaultExposure
|
|
|
|
case !stringInSlice(c.Exposure, ExposureModes[:]):
|
|
|
|
return errors.New(pkg + "bad exposure setting in config")
|
2019-03-15 09:54:29 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 03:32:11 +03:00
|
|
|
switch {
|
|
|
|
case c.AutoWhiteBalance == "":
|
|
|
|
c.Logger.Log(logger.Info, pkg+"auto white balance undefined, defaulting", "autoWhiteBalance", defaultAutoWhiteBalance)
|
|
|
|
c.AutoWhiteBalance = defaultAutoWhiteBalance
|
|
|
|
case !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]):
|
|
|
|
return errors.New(pkg + "bad auto white balance setting in config")
|
2019-03-15 09:54:29 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 06:50:02 +03:00
|
|
|
if c.RTMPRBSize <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"RTMPRBSize bad or unset, defaulting", "RTMPRBSize", defaultRTMPRBSize)
|
|
|
|
c.RTMPRBSize = defaultRTMPRBSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RTMPRBElementSize <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"RTMPRBElementSize bad or unset, defaulting", "RTMPRBElementSize", defaultRTMPRBElementSize)
|
|
|
|
c.RTMPRBElementSize = defaultRTMPRBElementSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.MTSRBSize <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"MTSRBSize bad or unset, defaulting", "MTSRBSize", defaultMTSRBSize)
|
|
|
|
c.MTSRBSize = defaultMTSRBSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.MTSRBElementSize <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, pkg+"MTSRBElementSize bad or unset, defaulting", "MTSRBElementSize", defaultMTSRBElementSize)
|
|
|
|
c.MTSRBElementSize = defaultMTSRBElementSize
|
|
|
|
}
|
|
|
|
|
2018-02-12 10:58:29 +03:00
|
|
|
return nil
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
2019-03-15 09:54:29 +03:00
|
|
|
|
2019-03-15 10:28:24 +03:00
|
|
|
// stringInSlice returns true if want is in slice.
|
2019-03-15 09:54:29 +03:00
|
|
|
func stringInSlice(want string, slice []string) bool {
|
|
|
|
for _, s := range slice {
|
|
|
|
if s == want {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|