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
|
|
|
*/
|
|
|
|
|
2020-02-26 06:58:12 +03:00
|
|
|
// Package config contains the configuration settings for revid.
|
2019-11-06 09:57:10 +03:00
|
|
|
package config
|
2018-02-10 10:08:14 +03:00
|
|
|
|
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-11-06 09:57:10 +03:00
|
|
|
type Logger interface {
|
|
|
|
SetLevel(int8)
|
|
|
|
Log(level int8, message string, params ...interface{})
|
|
|
|
}
|
|
|
|
|
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.
|
2019-11-01 14:15:46 +03:00
|
|
|
InputFile
|
|
|
|
InputRaspivid
|
|
|
|
InputV4L
|
|
|
|
InputRTSP
|
|
|
|
InputAudio
|
2019-05-13 09:12:16 +03:00
|
|
|
|
|
|
|
// Outputs.
|
2019-11-01 14:15:46 +03:00
|
|
|
OutputAudio
|
|
|
|
OutputRTMP
|
|
|
|
OutputRTP
|
|
|
|
OutputHTTP
|
|
|
|
OutputMPEGTS
|
|
|
|
OutputFile
|
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.
|
2019-11-12 08:46:45 +03:00
|
|
|
defaultInput = InputRaspivid
|
|
|
|
defaultOutput = OutputHTTP
|
|
|
|
defaultTimeout = 0
|
|
|
|
defaultInputCodec = codecutil.H264
|
|
|
|
defaultVerbosity = logger.Error
|
|
|
|
defaultRtpAddr = "localhost:6970"
|
|
|
|
defaultCameraIP = "192.168.1.50"
|
|
|
|
defaultBurstPeriod = 10 // Seconds
|
|
|
|
defaultMinFrames = 100
|
2019-11-13 06:08:33 +03:00
|
|
|
defaultFrameRate = 25
|
2019-11-13 06:28:53 +03:00
|
|
|
defaultWriteRate = 25
|
2019-11-12 08:46:45 +03:00
|
|
|
defaultClipDuration = 0
|
2019-06-05 19:39:55 +03:00
|
|
|
defaultAudioInputCodec = codecutil.ADPCM
|
2019-12-19 03:45:47 +03:00
|
|
|
defaultPSITime = 2
|
2020-01-25 02:09:42 +03:00
|
|
|
defaultFileFPS = 0
|
2019-08-08 06:50:02 +03:00
|
|
|
|
2020-04-27 06:49:23 +03:00
|
|
|
// Ring buffer defaults.
|
|
|
|
defaultRBCapacity = 50000000 // => 50MB
|
|
|
|
defaultRBWriteTimeout = 5 // Seconds.
|
2020-01-08 03:12:34 +03:00
|
|
|
|
|
|
|
// Motion filter parameter defaults.
|
2020-02-06 02:12:12 +03:00
|
|
|
defaultMinFPS = 1.0
|
2018-02-10 10:08:14 +03:00
|
|
|
)
|
|
|
|
|
2020-01-08 03:12:34 +03:00
|
|
|
// Quality represents video quality.
|
2019-11-12 08:46:45 +03:00
|
|
|
type Quality int
|
|
|
|
|
|
|
|
// The different video qualities that can be used for variable bitrate when
|
|
|
|
// using the GeoVision camera.
|
|
|
|
const (
|
|
|
|
QualityStandard Quality = iota
|
|
|
|
QualityFair
|
|
|
|
QualityGood
|
|
|
|
QualityGreat
|
|
|
|
QualityExcellent
|
|
|
|
)
|
|
|
|
|
2019-12-23 04:29:17 +03:00
|
|
|
// The different media filters.
|
2019-12-20 03:12:51 +03:00
|
|
|
const (
|
|
|
|
FilterNoOp = iota
|
|
|
|
FilterMOG
|
2019-12-24 06:38:42 +03:00
|
|
|
FilterVariableFPS
|
2019-12-23 07:28:35 +03:00
|
|
|
FilterKNN
|
2020-02-10 07:57:43 +03:00
|
|
|
FilterDiff
|
2020-01-24 09:31:28 +03:00
|
|
|
FilterBasic
|
2019-12-20 03:12:51 +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:
|
2019-11-06 13:56:39 +03:00
|
|
|
// InputRaspivid:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Read data from a Raspberry Pi Camera.
|
2019-11-06 13:56:39 +03:00
|
|
|
// InputV4l:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Read from webcam.
|
2019-11-06 13:56:39 +03:00
|
|
|
// InputFile:
|
2020-05-02 12:15:38 +03:00
|
|
|
// Read h.264 bytestream from a file.
|
2019-05-13 09:42:08 +03:00
|
|
|
// Location must be specified in InputPath field.
|
2019-11-06 13:56:39 +03:00
|
|
|
// InputRTSP:
|
2020-05-02 12:15:38 +03:00
|
|
|
// Read from a camera supporting RTSP communication.
|
2019-10-22 07:24:38 +03:00
|
|
|
// CameraIP should also be defined.
|
2020-05-02 12:15:38 +03:00
|
|
|
// InputAudio:
|
|
|
|
// Read from a ALSA audio source.
|
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:
|
2019-11-06 13:56:39 +03:00
|
|
|
// OutputFile:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Location must be defined by the OutputPath field. MPEG-TS packetization
|
|
|
|
// is used.
|
2019-11-06 13:56:39 +03:00
|
|
|
// OutputHTTP:
|
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-11-06 13:56:39 +03:00
|
|
|
// OutputRTMP:
|
2019-05-13 09:42:08 +03:00
|
|
|
// Destination URL must be defined in the RtmpUrl field. FLV packetization
|
|
|
|
// is used.
|
2019-11-06 13:56:39 +03:00
|
|
|
// OutputRTP:
|
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-10-22 07:24:38 +03:00
|
|
|
// CameraIP is the IP address of the camera in the case of the input camera
|
|
|
|
// being an IP camera.
|
|
|
|
CameraIP string
|
2019-05-27 08:45:26 +03:00
|
|
|
|
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
|
|
|
|
|
2019-11-22 06:08:57 +03:00
|
|
|
// CBR indicates whether we wish to use constant or variable bitrate. If CBR
|
|
|
|
// is true then we will use constant bitrate, and variable bitrate otherwise.
|
2019-10-22 07:24:38 +03:00
|
|
|
// In the case of the Pi camera, variable bitrate quality is controlled by
|
|
|
|
// the Quantization parameter below. In the case of the GeoVision camera,
|
|
|
|
// variable bitrate quality is controlled by firstly the VBRQuality parameter
|
|
|
|
// and second the VBRBitrate parameter.
|
2019-11-22 06:08:57 +03:00
|
|
|
CBR bool
|
2019-10-22 07:24:38 +03:00
|
|
|
|
|
|
|
// Quantization defines the quantization level, which will determine variable
|
|
|
|
// bitrate quality in the case of input from the Pi Camera.
|
2019-05-13 10:25:20 +03:00
|
|
|
Quantization uint
|
|
|
|
|
2019-10-22 07:24:38 +03:00
|
|
|
// VBRQuality describes the general quality of video from the GeoVision camera
|
|
|
|
// under variable bitrate. VBRQuality can be one 5 consts defined:
|
|
|
|
// qualityStandard, qualityFair, qualityGood, qualityGreat and qualityExcellent.
|
2019-11-06 09:57:10 +03:00
|
|
|
VBRQuality Quality
|
2019-10-22 07:24:38 +03:00
|
|
|
|
|
|
|
// VBRBitrate describes maximal bitrate for the GeoVision camera when under
|
|
|
|
// variable bitrate.
|
2020-05-02 06:55:13 +03:00
|
|
|
VBRBitrate uint
|
2019-10-22 07:24:38 +03:00
|
|
|
|
2019-10-25 04:42:30 +03:00
|
|
|
// This is the channel we're using for the GeoVision camera.
|
2020-05-02 06:55:13 +03:00
|
|
|
CameraChan uint8
|
2019-10-25 04:42:30 +03:00
|
|
|
|
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
|
2020-05-02 06:55:13 +03:00
|
|
|
SampleRate uint // Samples a second (Hz).
|
2019-06-13 17:45:04 +03:00
|
|
|
RecPeriod float64 // How many seconds to record at a time.
|
2020-05-02 06:55:13 +03:00
|
|
|
Channels uint // Number of audio channels, 1 for mono, 2 for stereo.
|
|
|
|
BitDepth uint // Sample bit depth.
|
2019-06-13 17:45:04 +03:00
|
|
|
|
2019-12-17 02:51:56 +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.
|
|
|
|
Width uint // Width defines the input video width Raspivid input.
|
|
|
|
Bitrate uint // Bitrate specifies the bitrate for constant bitrate in kbps.
|
|
|
|
|
2020-05-02 06:55:13 +03:00
|
|
|
HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input.
|
|
|
|
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
|
|
|
Filters []uint8 // Defines the methods of filtering to be used in between lexing and encoding.
|
|
|
|
PSITime uint // Sets the time between a packet being sent.
|
2019-08-08 06:50:02 +03:00
|
|
|
|
2020-04-27 06:49:23 +03:00
|
|
|
// Ring buffer parameters.
|
|
|
|
RBCapacity uint // The number of bytes the ring buffer will occupy.
|
|
|
|
RBWriteTimeout uint // The ringbuffer write timeout in seconds.
|
2020-01-08 03:12:34 +03:00
|
|
|
|
|
|
|
// Motion filter parameters.
|
2020-02-06 02:12:12 +03:00
|
|
|
// Some parameters can be used with any filter, while others can only be used by a few.
|
2020-01-31 02:51:23 +03:00
|
|
|
MinFPS float64 // The reduced framerate of the video when there is no motion.
|
2020-05-02 06:55:13 +03:00
|
|
|
MotionInterval uint // Sets the number of frames that are held before the filter is used (on the nth frame).
|
|
|
|
MotionDownscaling uint // Downscaling factor of frames used for motion detection.
|
2020-01-08 03:12:34 +03:00
|
|
|
|
2020-02-06 02:12:12 +03:00
|
|
|
MotionMinArea float64 // Used to ignore small areas of motion detection (KNN & MOG only).
|
|
|
|
MotionThreshold float64 // Intensity value that is considered motion.
|
|
|
|
MotionHistory uint // Length of filter's history (KNN & MOG only).
|
|
|
|
MotionKernel uint // Size of kernel used for filling holes and removing noise (KNN only).
|
2020-05-02 06:55:13 +03:00
|
|
|
MotionPixels uint // Number of pixels with motion that is needed for a whole frame to be considered as moving (Basic only).
|
2020-02-12 05:40:24 +03:00
|
|
|
MotionPadding uint // Number of frames to keep before and after motion detected.
|
2020-01-31 07:53:18 +03:00
|
|
|
|
2020-01-24 11:51:18 +03:00
|
|
|
// If true will restart reading of input after an io.EOF.
|
|
|
|
Loop bool
|
2020-01-24 12:35:43 +03:00
|
|
|
|
2020-01-25 02:09:42 +03:00
|
|
|
// Defines the rate at which frames from a file source are processed.
|
2020-05-02 06:55:13 +03:00
|
|
|
FileFPS uint
|
2019-05-13 09:12:16 +03:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:39:28 +03:00
|
|
|
// TypeData contains information about all of the variables that
|
|
|
|
// can be set over the web. It is a psuedo const.
|
|
|
|
var TypeData = map[string]string{
|
2020-01-31 02:51:23 +03:00
|
|
|
"AutoWhiteBalance": "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
|
|
|
|
"BitDepth": "int",
|
2020-03-27 17:40:28 +03:00
|
|
|
"Bitrate": "uint",
|
2020-01-31 02:51:23 +03:00
|
|
|
"Brightness": "uint",
|
|
|
|
"BurstPeriod": "uint",
|
|
|
|
"CameraChan": "int",
|
|
|
|
"CameraIP": "string",
|
|
|
|
"CBR": "bool",
|
|
|
|
"ClipDuration": "uint",
|
|
|
|
"Exposure": "enum:auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks",
|
|
|
|
"FileFPS": "int",
|
|
|
|
"Filters": "enums:NoOp,MOG,VariableFPS,KNN,Difference,Basic",
|
|
|
|
"FrameRate": "uint",
|
|
|
|
"Height": "uint",
|
|
|
|
"HorizontalFlip": "bool",
|
|
|
|
"HTTPAddress": "string",
|
2020-05-02 12:17:52 +03:00
|
|
|
"Input": "enum:raspivid,rtsp,v4l,file,audio",
|
|
|
|
"InputCodec": "enum:H264,MJPEG,PCM,ADPCM",
|
2020-01-31 02:51:23 +03:00
|
|
|
"InputPath": "string",
|
|
|
|
"logging": "enum:Debug,Info,Warning,Error,Fatal",
|
|
|
|
"Loop": "bool",
|
|
|
|
"MinFPS": "float",
|
|
|
|
"MinFrames": "uint",
|
|
|
|
"mode": "enum:Normal,Paused,Burst,Loop",
|
|
|
|
"MotionDownscaling": "uint",
|
2020-02-06 02:12:12 +03:00
|
|
|
"MotionHistory": "uint",
|
2020-01-31 02:51:23 +03:00
|
|
|
"MotionInterval": "int",
|
2020-02-06 02:12:12 +03:00
|
|
|
"MotionKernel": "uint",
|
|
|
|
"MotionMinArea": "float",
|
2020-02-12 05:40:24 +03:00
|
|
|
"MotionPadding": "uint",
|
2020-02-06 02:12:12 +03:00
|
|
|
"MotionPixels": "int",
|
|
|
|
"MotionThreshold": "float",
|
2020-01-31 02:51:23 +03:00
|
|
|
"Output": "enum:File,Http,Rtmp,Rtp",
|
|
|
|
"OutputPath": "string",
|
|
|
|
"Outputs": "enums:File,Http,Rtmp,Rtp",
|
|
|
|
"Quantization": "uint",
|
|
|
|
"RBCapacity": "uint",
|
|
|
|
"RBWriteTimeout": "uint",
|
|
|
|
"Rotation": "uint",
|
|
|
|
"RTMPURL": "string",
|
|
|
|
"RTPAddress": "string",
|
|
|
|
"Saturation": "int",
|
|
|
|
"VBRBitrate": "int",
|
|
|
|
"VBRQuality": "enum:standard,fair,good,great,excellent",
|
|
|
|
"VerticalFlip": "bool",
|
|
|
|
"Width": "uint",
|
2019-12-05 09:39:28 +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-12-05 02:00:51 +03:00
|
|
|
case logger.Debug, logger.Info, logger.Warning, logger.Error, logger.Fatal:
|
2018-03-17 16:29:42 +03:00
|
|
|
default:
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("LogLevel", defaultVerbosity)
|
2018-09-22 08:16:54 +03:00
|
|
|
c.LogLevel = defaultVerbosity
|
2018-03-17 16:29:42 +03:00
|
|
|
}
|
|
|
|
|
2019-10-22 15:34:33 +03:00
|
|
|
if c.CameraIP == "" {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("CameraIP", defaultCameraIP)
|
2019-10-22 15:34:33 +03:00
|
|
|
c.CameraIP = defaultCameraIP
|
|
|
|
}
|
|
|
|
|
2018-06-09 05:01:21 +03:00
|
|
|
switch c.Input {
|
2019-11-01 14:15:46 +03:00
|
|
|
case InputRaspivid, InputV4L, InputFile, InputAudio, InputRTSP:
|
2018-02-10 10:08:14 +03:00
|
|
|
case NothingDefined:
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("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 {
|
2019-11-01 14:15:46 +03:00
|
|
|
case OutputAudio:
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("InputCodec", defaultAudioInputCodec)
|
2019-05-09 05:41:02 +03:00
|
|
|
c.InputCodec = defaultAudioInputCodec
|
|
|
|
default:
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("InputCodec", defaultInputCodec)
|
2019-05-09 05:41:02 +03:00
|
|
|
c.InputCodec = defaultInputCodec
|
|
|
|
}
|
2018-02-10 10:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-05-05 16:20:59 +03:00
|
|
|
if c.Outputs == nil {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("Outputs", defaultOutput)
|
2019-05-05 16:20:59 +03:00
|
|
|
c.Outputs = append(c.Outputs, defaultOutput)
|
2019-08-24 07:32:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, o := range c.Outputs {
|
|
|
|
switch o {
|
2019-11-12 08:46:45 +03:00
|
|
|
case OutputFile, OutputHTTP, OutputRTP:
|
2019-11-01 14:15:46 +03:00
|
|
|
case OutputRTMP:
|
2019-08-24 07:32:24 +03:00
|
|
|
if c.RTMPURL == "" {
|
2020-03-27 17:34:02 +03:00
|
|
|
c.Logger.Log(logger.Info, "no RTMP URL: falling back to HTTP")
|
2019-11-01 14:15:46 +03:00
|
|
|
c.Outputs[i] = OutputHTTP
|
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 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("BurstPeriod", defaultBurstPeriod)
|
2019-02-03 16:13:51 +03:00
|
|
|
c.BurstPeriod = defaultBurstPeriod
|
|
|
|
}
|
|
|
|
|
2019-12-03 08:00:58 +03:00
|
|
|
const maxMinFrames = 1000
|
|
|
|
switch {
|
|
|
|
case c.MinFrames == 0:
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("MinFrames", defaultMinFrames)
|
2019-08-26 07:13:45 +03:00
|
|
|
c.MinFrames = defaultMinFrames
|
2019-12-03 08:00:58 +03:00
|
|
|
case c.MinFrames < 0:
|
2019-08-25 10:44:06 +03:00
|
|
|
return errors.New("refresh period is less than 0")
|
2019-12-03 08:00:58 +03:00
|
|
|
case c.MinFrames > maxMinFrames:
|
|
|
|
return errors.New("refresh period is greater than 1000")
|
2019-08-25 10:44:06 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 06:28:53 +03:00
|
|
|
if c.FrameRate <= 0 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("FrameRate", defaultFrameRate)
|
2019-11-13 06:08:33 +03:00
|
|
|
c.FrameRate = defaultFrameRate
|
2019-11-13 06:28:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.WriteRate <= 0 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("writeRate", defaultWriteRate)
|
2019-11-13 06:28:53 +03:00
|
|
|
c.WriteRate = defaultWriteRate
|
2019-11-13 06:08:33 +03:00
|
|
|
}
|
|
|
|
|
2019-08-25 10:44:06 +03:00
|
|
|
if c.ClipDuration == 0 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("ClipDuration", defaultClipDuration)
|
2019-08-25 10:44:06 +03:00
|
|
|
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-05-13 09:53:38 +03:00
|
|
|
if c.RTPAddress == "" {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("RTPAddress", defaultRtpAddr)
|
2019-05-13 09:53:38 +03:00
|
|
|
c.RTPAddress = defaultRtpAddr
|
2018-11-20 17:37:38 +03:00
|
|
|
}
|
2019-03-15 09:54:29 +03:00
|
|
|
|
2020-04-27 06:49:23 +03:00
|
|
|
if c.RBWriteTimeout <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, "RBWriteTimeout bad or unset, defaulting", "RBWriteTimeout", defaultRBWriteTimeout)
|
|
|
|
c.RBWriteTimeout = defaultRBWriteTimeout
|
2019-08-08 06:50:02 +03:00
|
|
|
}
|
|
|
|
|
2020-04-27 06:49:23 +03:00
|
|
|
if c.RBCapacity <= 0 {
|
|
|
|
c.Logger.Log(logger.Info, "RBCapacity bad or unset, defaulting", "RBCapacity", defaultRBCapacity)
|
|
|
|
c.RBCapacity = defaultRBCapacity
|
2019-10-12 13:40:48 +03:00
|
|
|
}
|
|
|
|
|
2019-12-19 03:45:47 +03:00
|
|
|
if c.PSITime <= 0 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("PSITime", defaultPSITime)
|
2019-12-19 03:45:47 +03:00
|
|
|
c.PSITime = defaultPSITime
|
2019-12-17 02:51:56 +03:00
|
|
|
}
|
2020-01-08 03:12:34 +03:00
|
|
|
if c.MinFPS <= 0 {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("MinFPS", defaultMinFPS)
|
2020-01-08 03:12:34 +03:00
|
|
|
c.MinFPS = defaultMinFPS
|
|
|
|
}
|
|
|
|
|
2020-01-25 02:09:42 +03:00
|
|
|
if c.FileFPS <= 0 || (c.FileFPS > 0 && c.Input != InputFile) {
|
2020-02-06 02:12:12 +03:00
|
|
|
c.LogInvalidField("FileFPS", defaultFileFPS)
|
2020-01-25 02:09:42 +03:00
|
|
|
c.FileFPS = defaultFileFPS
|
2020-01-24 12:35:43 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-02-06 02:12:12 +03:00
|
|
|
func (c *Config) LogInvalidField(name string, def interface{}) {
|
2020-03-27 17:34:02 +03:00
|
|
|
c.Logger.Log(logger.Info, name+" bad or unset, defaulting", name, def)
|
2020-01-28 08:38:26 +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
|
|
|
|
}
|