2020-05-19 09:02:02 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
variables.go contains a list of structs that provide a variable Name, type in
|
|
|
|
a string format, a function for updating the variable in the Config struct
|
|
|
|
from a string, and finally, a validation function to check the validity of the
|
|
|
|
corresponding field value in the Config.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2020 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
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
2022-05-27 09:12:52 +03:00
|
|
|
"bitbucket.org/ausocean/utils/logging"
|
2020-05-19 09:02:02 +03:00
|
|
|
)
|
|
|
|
|
2021-01-20 04:19:01 +03:00
|
|
|
// Config map Keys.
|
2021-01-04 06:22:57 +03:00
|
|
|
const (
|
2021-05-17 04:48:44 +03:00
|
|
|
KeyAutoWhiteBalance = "AutoWhiteBalance"
|
|
|
|
KeyAWBGains = "AWBGains"
|
|
|
|
KeyBitDepth = "BitDepth"
|
|
|
|
KeyBitrate = "Bitrate"
|
|
|
|
KeyBrightness = "Brightness"
|
|
|
|
KeyBurstPeriod = "BurstPeriod"
|
|
|
|
KeyCameraChan = "CameraChan"
|
|
|
|
KeyCameraIP = "CameraIP"
|
|
|
|
KeyCBR = "CBR"
|
|
|
|
KeyClipDuration = "ClipDuration"
|
|
|
|
KeyChannels = "Channels"
|
|
|
|
KeyContrast = "Contrast"
|
|
|
|
KeyExposure = "Exposure"
|
|
|
|
KeyEV = "EV"
|
|
|
|
KeyFileFPS = "FileFPS"
|
|
|
|
KeyFilters = "Filters"
|
|
|
|
KeyFrameRate = "FrameRate"
|
|
|
|
KeyHeight = "Height"
|
|
|
|
KeyHorizontalFlip = "HorizontalFlip"
|
|
|
|
KeyHTTPAddress = "HTTPAddress"
|
|
|
|
KeyInput = "Input"
|
|
|
|
KeyInputCodec = "InputCodec"
|
|
|
|
KeyInputPath = "InputPath"
|
|
|
|
KeyISO = "ISO"
|
|
|
|
KeyLogging = "logging"
|
|
|
|
KeyLoop = "Loop"
|
|
|
|
KeyMinFPS = "MinFPS"
|
|
|
|
KeyMinFrames = "MinFrames"
|
|
|
|
KeyMode = "mode"
|
|
|
|
KeyMotionDownscaling = "MotionDownscaling"
|
|
|
|
KeyMotionHistory = "MotionHistory"
|
|
|
|
KeyMotionInterval = "MotionInterval"
|
|
|
|
KeyMotionKernel = "MotionKernel"
|
|
|
|
KeyMotionMinArea = "MotionMinArea"
|
|
|
|
KeyMotionPadding = "MotionPadding"
|
|
|
|
KeyMotionPixels = "MotionPixels"
|
|
|
|
KeyMotionThreshold = "MotionThreshold"
|
|
|
|
KeyOutput = "Output"
|
|
|
|
KeyOutputPath = "OutputPath"
|
|
|
|
KeyOutputs = "Outputs"
|
|
|
|
KeyPSITime = "PSITime"
|
|
|
|
KeyQuantization = "Quantization"
|
|
|
|
KeyPoolCapacity = "PoolCapacity"
|
|
|
|
KeyPoolStartElementSize = "PoolStartElementSize"
|
|
|
|
KeyPoolWriteTimeout = "PoolWriteTimeout"
|
|
|
|
KeyRecPeriod = "RecPeriod"
|
|
|
|
KeyRotation = "Rotation"
|
|
|
|
KeyRTMPURL = "RTMPURL"
|
|
|
|
KeyRTPAddress = "RTPAddress"
|
|
|
|
KeySampleRate = "SampleRate"
|
|
|
|
KeySaturation = "Saturation"
|
|
|
|
KeySharpness = "Sharpness"
|
|
|
|
KeyJPEGQuality = "JPEGQuality"
|
|
|
|
KeySuppress = "Suppress"
|
|
|
|
KeyTimelapseDuration = "TimelapseDuration"
|
|
|
|
KeyTimelapseInterval = "TimelapseInterval"
|
|
|
|
KeyVBRBitrate = "VBRBitrate"
|
|
|
|
KeyVBRQuality = "VBRQuality"
|
|
|
|
KeyVerticalFlip = "VerticalFlip"
|
|
|
|
KeyWidth = "Width"
|
2022-04-11 02:53:40 +03:00
|
|
|
KeyTransformMatrix = "TransformMatrix"
|
2021-01-04 06:22:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config map parameter types.
|
|
|
|
const (
|
|
|
|
typeString = "string"
|
2021-01-20 04:19:01 +03:00
|
|
|
typeInt = "int"
|
2021-01-04 06:22:57 +03:00
|
|
|
typeUint = "uint"
|
|
|
|
typeBool = "bool"
|
|
|
|
typeFloat = "float"
|
|
|
|
)
|
|
|
|
|
2020-05-19 09:02:02 +03:00
|
|
|
// Default variable values.
|
|
|
|
const (
|
|
|
|
// General revid defaults.
|
2020-08-11 05:13:17 +03:00
|
|
|
defaultInput = InputRaspivid
|
|
|
|
defaultOutput = OutputHTTP
|
|
|
|
defaultInputCodec = codecutil.H264
|
2022-05-27 09:12:52 +03:00
|
|
|
defaultVerbosity = logging.Error
|
2020-08-11 05:13:17 +03:00
|
|
|
defaultRTPAddr = "localhost:6970"
|
|
|
|
defaultCameraIP = "192.168.1.50"
|
|
|
|
defaultBurstPeriod = 10 // Seconds
|
|
|
|
defaultMinFrames = 100
|
|
|
|
defaultFrameRate = 25
|
|
|
|
defaultClipDuration = 0
|
|
|
|
defaultPSITime = 2
|
|
|
|
defaultFileFPS = 0
|
2020-05-19 09:02:02 +03:00
|
|
|
|
|
|
|
// Ring buffer defaults.
|
2021-05-17 04:48:44 +03:00
|
|
|
defaultPoolCapacity = 50000000 // => 50MB
|
|
|
|
defaultPoolStartElementSize = 1000 // bytes
|
|
|
|
defaultPoolWriteTimeout = 5 // Seconds.
|
2020-05-19 09:02:02 +03:00
|
|
|
|
|
|
|
// Motion filter parameter defaults.
|
|
|
|
defaultMinFPS = 1.0
|
|
|
|
)
|
|
|
|
|
2021-07-22 06:33:01 +03:00
|
|
|
// Variables describes the variables that can be used for revid control.
|
|
|
|
// These structs provide the name and type of variable, a function for updating
|
|
|
|
// this variable in a Config, and a function for validating the value of the variable.
|
2020-05-19 09:02:02 +03:00
|
|
|
var Variables = []struct {
|
|
|
|
Name string
|
2022-04-11 02:53:40 +03:00
|
|
|
Type string
|
2020-05-19 09:02:02 +03:00
|
|
|
Update func(*Config, string)
|
|
|
|
Validate func(*Config)
|
|
|
|
}{
|
2022-04-11 02:53:40 +03:00
|
|
|
{
|
|
|
|
Name: KeyTransformMatrix,
|
|
|
|
Type: typeString,
|
|
|
|
Update: func(c *Config, v string) {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Debug("updating transform matrix", "string", v)
|
2022-04-11 06:45:07 +03:00
|
|
|
v = strings.Replace(v, " ", "", -1)
|
|
|
|
vals := make([]float64, 0)
|
|
|
|
if v == "" {
|
|
|
|
c.TransformMatrix = vals
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-11 02:53:40 +03:00
|
|
|
elements := strings.Split(v, ",")
|
2022-04-11 06:45:07 +03:00
|
|
|
for _, e := range elements {
|
|
|
|
vFloat, err := strconv.ParseFloat(e, 64)
|
2022-04-11 02:53:40 +03:00
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid TransformMatrix param", "value", e)
|
2022-04-11 02:53:40 +03:00
|
|
|
}
|
|
|
|
vals = append(vals, vFloat)
|
|
|
|
}
|
|
|
|
c.TransformMatrix = vals
|
|
|
|
},
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyAutoWhiteBalance,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.AutoWhiteBalance = v },
|
|
|
|
},
|
2021-03-30 06:36:00 +03:00
|
|
|
{
|
|
|
|
Name: KeyAWBGains,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2021-03-30 06:36:00 +03:00
|
|
|
Update: func(c *Config, v string) { c.AWBGains = v },
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyBitDepth,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.BitDepth = parseUint(KeyBitDepth, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyBitrate,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Bitrate = parseUint(KeyBitrate, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyBrightness,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Brightness = parseUint(KeyBrightness, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyBurstPeriod,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.BurstPeriod = parseUint(KeyBurstPeriod, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.BurstPeriod <= 0 {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyBurstPeriod, defaultBurstPeriod)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.BurstPeriod = defaultBurstPeriod
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyCameraChan,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.CameraChan = uint8(parseUint(KeyCameraChan, v, c)) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyCameraIP,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.CameraIP = v },
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.CameraIP == "" {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyCameraIP, defaultCameraIP)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.CameraIP = defaultCameraIP
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyCBR,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeBool,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.CBR = parseBool(KeyCBR, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyClipDuration,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeUint,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
_v, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid ClipDuration param", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
c.ClipDuration = time.Duration(_v) * time.Second
|
|
|
|
},
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.ClipDuration <= 0 {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyClipDuration, defaultClipDuration)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.ClipDuration = defaultClipDuration
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-08-11 05:13:17 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyChannels,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Channels = parseUint(KeyChannels, v, c) },
|
2020-08-11 05:13:17 +03:00
|
|
|
},
|
2021-03-30 06:36:00 +03:00
|
|
|
{
|
2021-04-02 00:49:26 +03:00
|
|
|
Name: KeyContrast,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeInt,
|
2021-04-02 00:49:26 +03:00
|
|
|
Update: func(c *Config, v string) { c.Contrast = parseInt(KeyContrast, v, c) },
|
2021-03-30 06:36:00 +03:00
|
|
|
},
|
|
|
|
{
|
2021-04-02 00:49:26 +03:00
|
|
|
Name: KeyEV,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeInt,
|
2021-04-02 00:49:26 +03:00
|
|
|
Update: func(c *Config, v string) { c.EV = parseInt(KeyEV, v, c) },
|
2021-03-30 06:36:00 +03:00
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyExposure,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: "enum:auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.Exposure = v },
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyFileFPS,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.FileFPS = parseUint(KeyFileFPS, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.FileFPS <= 0 || (c.FileFPS > 0 && c.Input != InputFile) {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyFileFPS, defaultFileFPS)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.FileFPS = defaultFileFPS
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyFilters,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: "enums:NoOp,MOG,VariableFPS,KNN,Difference,Basic",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
filters := strings.Split(v, ",")
|
|
|
|
m := map[string]uint{"NoOp": FilterNoOp, "MOG": FilterMOG, "VariableFPS": FilterVariableFPS, "KNN": FilterKNN, "Difference": FilterDiff, "Basic": FilterBasic}
|
|
|
|
c.Filters = make([]uint, len(filters))
|
|
|
|
for i, filter := range filters {
|
|
|
|
v, ok := m[filter]
|
|
|
|
if !ok {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid Filters param", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
c.Filters[i] = uint(v)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyFrameRate,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.FrameRate = parseUint(KeyFrameRate, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.FrameRate <= 0 || c.FrameRate > 60 {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyFrameRate, defaultFrameRate)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.FrameRate = defaultFrameRate
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyHeight,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Height = parseUint(KeyHeight, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyHorizontalFlip,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeBool,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.HorizontalFlip = parseBool(KeyHorizontalFlip, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyHTTPAddress,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.HTTPAddress = v },
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyInput,
|
2022-09-09 04:54:29 +03:00
|
|
|
Type: "enum:raspivid,raspistill,rtsp,v4l,file,audio,manual",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
c.Input = parseEnum(
|
2021-01-18 08:18:43 +03:00
|
|
|
KeyInput,
|
2020-05-19 09:02:02 +03:00
|
|
|
v,
|
|
|
|
map[string]uint8{
|
2021-01-20 04:19:01 +03:00
|
|
|
"raspivid": InputRaspivid,
|
|
|
|
"raspistill": InputRaspistill,
|
|
|
|
"rtsp": InputRTSP,
|
|
|
|
"v4l": InputV4L,
|
|
|
|
"file": InputFile,
|
|
|
|
"audio": InputAudio,
|
2022-09-20 09:24:59 +03:00
|
|
|
"manual": InputManual,
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
c,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
switch c.Input {
|
2022-09-14 10:44:35 +03:00
|
|
|
case InputRaspivid, InputRaspistill, InputV4L, InputFile, InputAudio, InputRTSP, InputManual:
|
2020-05-19 09:02:02 +03:00
|
|
|
default:
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyInput, defaultInput)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.Input = defaultInput
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyInputCodec,
|
2022-09-09 04:54:29 +03:00
|
|
|
Type: "enum:h264,h264_au,h265,mjpeg,jpeg,pcm,adpcm",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
2021-02-22 07:45:30 +03:00
|
|
|
c.InputCodec = v
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
Validate: func(c *Config) {
|
2021-02-22 07:45:30 +03:00
|
|
|
if !codecutil.IsValid(c.InputCodec) {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyInputCodec, defaultInputCodec)
|
2020-08-11 05:13:17 +03:00
|
|
|
c.InputCodec = defaultInputCodec
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyInputPath,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.InputPath = v },
|
|
|
|
},
|
2021-03-30 06:36:00 +03:00
|
|
|
{
|
|
|
|
Name: KeyISO,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-03-30 06:36:00 +03:00
|
|
|
Update: func(c *Config, v string) { c.ISO = parseUint(KeyISO, v, c) },
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyLogging,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: "enum:Debug,Info,Warning,Error,Fatal",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
switch v {
|
|
|
|
case "Debug":
|
2022-05-27 09:12:52 +03:00
|
|
|
c.LogLevel = logging.Debug
|
2020-05-19 09:02:02 +03:00
|
|
|
case "Info":
|
2022-05-27 09:12:52 +03:00
|
|
|
c.LogLevel = logging.Info
|
2020-05-19 09:02:02 +03:00
|
|
|
case "Warning":
|
2022-05-27 09:12:52 +03:00
|
|
|
c.LogLevel = logging.Warning
|
2020-05-19 09:02:02 +03:00
|
|
|
case "Error":
|
2022-05-27 09:12:52 +03:00
|
|
|
c.LogLevel = logging.Error
|
2020-05-19 09:02:02 +03:00
|
|
|
case "Fatal":
|
2022-05-27 09:12:52 +03:00
|
|
|
c.LogLevel = logging.Fatal
|
2020-05-19 09:02:02 +03:00
|
|
|
default:
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid Logging param", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
switch c.LogLevel {
|
2022-05-27 09:12:52 +03:00
|
|
|
case logging.Debug, logging.Info, logging.Warning, logging.Error, logging.Fatal:
|
2020-05-19 09:02:02 +03:00
|
|
|
default:
|
|
|
|
c.LogInvalidField("LogLevel", defaultVerbosity)
|
|
|
|
c.LogLevel = defaultVerbosity
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyLoop,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeBool,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Loop = parseBool(KeyLoop, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMinFPS,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MinFPS = parseUint(KeyMinFPS, v, c) },
|
|
|
|
Validate: func(c *Config) { c.MinFPS = lessThanOrEqual(KeyMinFPS, c.MinFPS, 0, c, defaultMinFPS) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMinFrames,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MinFrames = parseUint(KeyMinFrames, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
Validate: func(c *Config) {
|
|
|
|
const maxMinFrames = 1000
|
|
|
|
if c.MinFrames <= 0 || c.MinFrames > maxMinFrames {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyMinFrames, defaultMinFrames)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.MinFrames = defaultMinFrames
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-09-20 09:24:59 +03:00
|
|
|
Name: KeyMode,
|
|
|
|
Type: "enum:Normal,Paused,Burst",
|
2022-08-31 10:28:40 +03:00
|
|
|
Update: func(c *Config, v string) {},
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionDownscaling,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionDownscaling = parseUint(KeyMotionDownscaling, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionHistory,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionHistory = parseUint(KeyMotionHistory, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionInterval,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionInterval = parseUint(KeyMotionInterval, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionKernel,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionKernel = parseUint(KeyMotionKernel, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyMotionMinArea,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeFloat,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
f, err := strconv.ParseFloat(v, 64)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid MotionMinArea var", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
c.MotionMinArea = f
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionPadding,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionPadding = parseUint(KeyMotionPadding, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyMotionPixels,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.MotionPixels = parseUint(KeyMotionPixels, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyMotionThreshold,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeFloat,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
f, err := strconv.ParseFloat(v, 64)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid MotionThreshold var", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
c.MotionThreshold = f
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyOutput,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: "enum:File,HTTP,RTMP,RTP",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
c.Outputs = make([]uint8, 1)
|
|
|
|
switch strings.ToLower(v) {
|
|
|
|
case "file":
|
|
|
|
c.Outputs[0] = OutputFile
|
2021-01-20 04:19:01 +03:00
|
|
|
case "files":
|
|
|
|
c.Outputs[0] = OutputFiles
|
2020-05-19 09:02:02 +03:00
|
|
|
case "http":
|
|
|
|
c.Outputs[0] = OutputHTTP
|
|
|
|
case "rtmp":
|
|
|
|
c.Outputs[0] = OutputRTMP
|
|
|
|
case "rtp":
|
|
|
|
c.Outputs[0] = OutputRTP
|
|
|
|
default:
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid output param", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyOutputPath,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.OutputPath = v },
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyOutputs,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: "enums:File,HTTP,RTMP,RTP",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
outputs := strings.Split(v, ",")
|
|
|
|
c.Outputs = make([]uint8, len(outputs))
|
|
|
|
for i, output := range outputs {
|
|
|
|
switch strings.ToLower(output) {
|
|
|
|
case "file":
|
|
|
|
c.Outputs[i] = OutputFile
|
2021-01-20 04:19:01 +03:00
|
|
|
case "files":
|
|
|
|
c.Outputs[i] = OutputFiles
|
2020-05-19 09:02:02 +03:00
|
|
|
case "http":
|
|
|
|
c.Outputs[i] = OutputHTTP
|
|
|
|
case "rtmp":
|
|
|
|
c.Outputs[i] = OutputRTMP
|
|
|
|
case "rtp":
|
|
|
|
c.Outputs[i] = OutputRTP
|
|
|
|
default:
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid outputs param", "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.Outputs == nil {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyOutputs, defaultOutput)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.Outputs = append(c.Outputs, defaultOutput)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyPSITime,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.PSITime = parseUint(KeyPSITime, v, c) },
|
|
|
|
Validate: func(c *Config) { c.PSITime = lessThanOrEqual(KeyPSITime, c.PSITime, 0, c, defaultPSITime) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyQuantization,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Quantization = parseUint(KeyQuantization, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-05-17 04:48:44 +03:00
|
|
|
Name: KeyPoolCapacity,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-05-17 04:48:44 +03:00
|
|
|
Update: func(c *Config, v string) { c.PoolCapacity = parseUint(KeyPoolCapacity, v, c) },
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
c.PoolCapacity = lessThanOrEqual(KeyPoolCapacity, c.PoolCapacity, 0, c, defaultPoolCapacity)
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
2021-01-20 04:19:01 +03:00
|
|
|
{
|
2021-05-17 04:48:44 +03:00
|
|
|
Name: KeyPoolStartElementSize,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-05-17 04:48:44 +03:00
|
|
|
Update: func(c *Config, v string) { c.PoolStartElementSize = parseUint("PoolStartElementSize", v, c) },
|
2021-01-20 04:19:01 +03:00
|
|
|
Validate: func(c *Config) {
|
2021-05-17 04:48:44 +03:00
|
|
|
c.PoolStartElementSize = lessThanOrEqual("PoolStartElementSize", c.PoolStartElementSize, 0, c, defaultPoolStartElementSize)
|
2021-01-20 04:19:01 +03:00
|
|
|
},
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-05-17 04:48:44 +03:00
|
|
|
Name: KeyPoolWriteTimeout,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-05-17 04:48:44 +03:00
|
|
|
Update: func(c *Config, v string) { c.PoolWriteTimeout = parseUint(KeyPoolWriteTimeout, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
Validate: func(c *Config) {
|
2021-05-17 04:48:44 +03:00
|
|
|
c.PoolWriteTimeout = lessThanOrEqual(KeyPoolWriteTimeout, c.PoolWriteTimeout, 0, c, defaultPoolWriteTimeout)
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
},
|
2020-08-11 05:13:17 +03:00
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyRecPeriod,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeFloat,
|
2020-08-11 05:13:17 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
_v, err := strconv.ParseFloat(v, 64)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning(fmt.Sprintf("invalid %s param", KeyRecPeriod), "value", v)
|
2020-08-11 05:13:17 +03:00
|
|
|
}
|
2020-08-11 07:19:41 +03:00
|
|
|
c.RecPeriod = _v
|
2020-08-11 05:13:17 +03:00
|
|
|
},
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyRotation,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Rotation = parseUint(KeyRotation, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2023-03-05 00:55:14 +03:00
|
|
|
Name: KeyRTMPURL,
|
|
|
|
Type: typeString,
|
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
v = strings.ReplaceAll(v, " ", "")
|
|
|
|
split := strings.Split(v, ",")
|
|
|
|
for _, s := range split {
|
|
|
|
c.RTMPURL = append(c.RTMPURL, s)
|
|
|
|
}
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyRTPAddress,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeString,
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) { c.RTPAddress = v },
|
|
|
|
Validate: func(c *Config) {
|
|
|
|
if c.RTPAddress == "" {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.LogInvalidField(KeyRTPAddress, defaultRTPAddr)
|
2020-05-19 09:02:02 +03:00
|
|
|
c.RTPAddress = defaultRTPAddr
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-08-11 05:13:17 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeySampleRate,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.SampleRate = parseUint(KeySampleRate, v, c) },
|
2020-08-11 05:13:17 +03:00
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-04-02 00:49:26 +03:00
|
|
|
Name: KeySaturation,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeInt,
|
2021-04-02 00:49:26 +03:00
|
|
|
Update: func(c *Config, v string) { c.Saturation = parseInt(KeySaturation, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
2021-03-30 06:36:00 +03:00
|
|
|
{
|
2021-04-02 00:49:26 +03:00
|
|
|
Name: KeySharpness,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeInt,
|
2021-04-02 00:49:26 +03:00
|
|
|
Update: func(c *Config, v string) { c.Sharpness = parseInt(KeySharpness, v, c) },
|
2021-03-30 06:36:00 +03:00
|
|
|
},
|
2021-01-20 04:19:01 +03:00
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyJPEGQuality,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeUint,
|
2021-01-20 04:19:01 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
_v, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid JPEGQuality param", "value", v)
|
2021-01-20 04:19:01 +03:00
|
|
|
}
|
2021-01-27 06:11:29 +03:00
|
|
|
c.JPEGQuality = _v
|
2021-01-20 04:19:01 +03:00
|
|
|
},
|
|
|
|
},
|
2020-05-19 17:41:14 +03:00
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeySuppress,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeBool,
|
2020-05-19 17:41:14 +03:00
|
|
|
Update: func(c *Config, v string) {
|
2021-01-18 08:18:43 +03:00
|
|
|
c.Suppress = parseBool(KeySuppress, v, c)
|
2022-05-27 09:12:52 +03:00
|
|
|
c.Logger.(*logging.JSONLogger).SetSuppress(c.Suppress)
|
2020-05-19 17:41:14 +03:00
|
|
|
},
|
|
|
|
},
|
2021-01-20 04:19:01 +03:00
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyTimelapseInterval,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeUint,
|
2021-01-20 04:19:01 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
_v, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid TimelapseInterval param", "value", v)
|
2021-01-20 04:19:01 +03:00
|
|
|
}
|
|
|
|
c.TimelapseInterval = time.Duration(_v) * time.Second
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyTimelapseDuration,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: typeUint,
|
2021-01-20 04:19:01 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
_v, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning("invalid TimelapseDuration param", "value", v)
|
2021-01-20 04:19:01 +03:00
|
|
|
}
|
|
|
|
c.TimelapseDuration = time.Duration(_v) * time.Second
|
|
|
|
},
|
|
|
|
},
|
2020-05-19 09:02:02 +03:00
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyVBRBitrate,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.VBRBitrate = parseUint(KeyVBRBitrate, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 02:53:40 +03:00
|
|
|
Name: KeyVBRQuality,
|
2021-07-22 06:33:01 +03:00
|
|
|
Type: "enum:standard,fair,good,great,excellent",
|
2020-05-19 09:02:02 +03:00
|
|
|
Update: func(c *Config, v string) {
|
|
|
|
c.VBRQuality = Quality(parseEnum(
|
2021-01-18 08:18:43 +03:00
|
|
|
KeyVBRQuality,
|
2020-05-19 09:02:02 +03:00
|
|
|
v,
|
|
|
|
map[string]uint8{
|
|
|
|
"standard": uint8(QualityStandard),
|
|
|
|
"fair": uint8(QualityFair),
|
|
|
|
"good": uint8(QualityGood),
|
|
|
|
"great": uint8(QualityGreat),
|
|
|
|
"excellent": uint8(QualityExcellent),
|
|
|
|
},
|
|
|
|
c,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyVerticalFlip,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeBool,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.VerticalFlip = parseBool(KeyVerticalFlip, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 08:18:43 +03:00
|
|
|
Name: KeyWidth,
|
2022-04-11 02:53:40 +03:00
|
|
|
Type: typeUint,
|
2021-01-18 08:18:43 +03:00
|
|
|
Update: func(c *Config, v string) { c.Width = parseUint(KeyWidth, v, c) },
|
2020-05-19 09:02:02 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseUint(n, v string, c *Config) uint {
|
2021-04-02 00:49:26 +03:00
|
|
|
_v, err := strconv.ParseUint(v, 10, 64)
|
2020-05-19 09:02:02 +03:00
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning(fmt.Sprintf("expected unsigned int for param %s", n), "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
return uint(_v)
|
|
|
|
}
|
|
|
|
|
2021-04-02 00:49:26 +03:00
|
|
|
func parseInt(n, v string, c *Config) int {
|
|
|
|
_v, err := strconv.Atoi(v)
|
|
|
|
if err != nil {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning(fmt.Sprintf("expected integer for param %s", n), "value", v)
|
2021-04-02 00:49:26 +03:00
|
|
|
}
|
|
|
|
return _v
|
|
|
|
}
|
|
|
|
|
2020-05-19 09:02:02 +03:00
|
|
|
func parseBool(n, v string, c *Config) (b bool) {
|
|
|
|
switch strings.ToLower(v) {
|
|
|
|
case "true":
|
|
|
|
b = true
|
|
|
|
case "false":
|
|
|
|
b = false
|
|
|
|
default:
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning(fmt.Sprintf("expect bool for param %s", n), "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseEnum(n, v string, enums map[string]uint8, c *Config) uint8 {
|
|
|
|
_v, ok := enums[strings.ToLower(v)]
|
|
|
|
if !ok {
|
2022-09-20 09:24:59 +03:00
|
|
|
c.Logger.Warning(fmt.Sprintf("invalid value for %s param", n), "value", v)
|
2020-05-19 09:02:02 +03:00
|
|
|
}
|
|
|
|
return _v
|
|
|
|
}
|
|
|
|
|
|
|
|
func lessThanOrEqual(n string, v, cmp uint, c *Config, def uint) uint {
|
|
|
|
if v <= cmp {
|
|
|
|
c.LogInvalidField(n, def)
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|