revid/config/variables.go: exported config map key constants

This commit is contained in:
Saxon Nelson-Milton 2021-01-18 15:48:43 +10:30
parent 13ea99b63b
commit 80bf76f703
1 changed files with 151 additions and 151 deletions
revid/config

View File

@ -39,57 +39,57 @@ import (
// Config map keys.
const (
keyAutoWhiteBalance = "AutoWhiteBalance"
keyBitDepth = "BitDepth"
keyBitrate = "Bitrate"
keyBrightness = "Brightness"
keyBurstPeriod = "BurstPeriod"
keyCameraChan = "CameraChan"
keyCameraIP = "CameraIP"
keyCBR = "CBR"
keyClipDuration = "ClipDuration"
keyChannels = "Channels"
keyExposure = "Exposure"
keyFileFPS = "FileFPS"
keyFilters = "Filters"
keyFrameRate = "FrameRate"
keyHeight = "Height"
keyHorizontalFlip = "HorizontalFlip"
keyHTTPAddress = "HTTPAddress"
keyInput = "Input"
keyInputCodec = "InputCodec"
keyInputPath = "InputPath"
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"
keyRBCapacity = "RBCapacity"
keyRBWriteTimeout = "RBWriteTimeout"
keyRecPeriod = "RecPeriod"
keyRotation = "Rotation"
keyRTMPURL = "RTMPURL"
keyRTPAddress = "RTPAddress"
keySampleRate = "SampleRate"
keySaturation = "Saturation"
keySuppress = "Suppress"
keyVBRBitrate = "VBRBitrate"
keyVBRQuality = "VBRQuality"
keyVerticalFlip = "VerticalFlip"
keyWidth = "Width"
KeyAutoWhiteBalance = "AutoWhiteBalance"
KeyBitDepth = "BitDepth"
KeyBitrate = "Bitrate"
KeyBrightness = "Brightness"
KeyBurstPeriod = "BurstPeriod"
KeyCameraChan = "CameraChan"
KeyCameraIP = "CameraIP"
KeyCBR = "CBR"
KeyClipDuration = "ClipDuration"
KeyChannels = "Channels"
KeyExposure = "Exposure"
KeyFileFPS = "FileFPS"
KeyFilters = "Filters"
KeyFrameRate = "FrameRate"
KeyHeight = "Height"
KeyHorizontalFlip = "HorizontalFlip"
KeyHTTPAddress = "HTTPAddress"
KeyInput = "Input"
KeyInputCodec = "InputCodec"
KeyInputPath = "InputPath"
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"
KeyRBCapacity = "RBCapacity"
KeyRBWriteTimeout = "RBWriteTimeout"
KeyRecPeriod = "RecPeriod"
KeyRotation = "Rotation"
KeyRTMPURL = "RTMPURL"
KeyRTPAddress = "RTPAddress"
KeySampleRate = "SampleRate"
KeySaturation = "Saturation"
KeySuppress = "Suppress"
KeyVBRBitrate = "VBRBitrate"
KeyVBRQuality = "VBRQuality"
KeyVerticalFlip = "VerticalFlip"
KeyWidth = "Width"
)
// Config map parameter types.
@ -131,59 +131,59 @@ var Variables = []struct {
Validate func(*Config)
}{
{
Name: keyAutoWhiteBalance,
Name: KeyAutoWhiteBalance,
Type_: "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
Update: func(c *Config, v string) { c.AutoWhiteBalance = v },
},
{
Name: keyBitDepth,
Name: KeyBitDepth,
Type_: typeUint,
Update: func(c *Config, v string) { c.BitDepth = parseUint(keyBitDepth, v, c) },
Update: func(c *Config, v string) { c.BitDepth = parseUint(KeyBitDepth, v, c) },
},
{
Name: keyBitrate,
Name: KeyBitrate,
Type_: typeUint,
Update: func(c *Config, v string) { c.Bitrate = parseUint(keyBitrate, v, c) },
Update: func(c *Config, v string) { c.Bitrate = parseUint(KeyBitrate, v, c) },
},
{
Name: keyBrightness,
Name: KeyBrightness,
Type_: typeUint,
Update: func(c *Config, v string) { c.Brightness = parseUint(keyBrightness, v, c) },
Update: func(c *Config, v string) { c.Brightness = parseUint(KeyBrightness, v, c) },
},
{
Name: keyBurstPeriod,
Name: KeyBurstPeriod,
Type_: typeUint,
Update: func(c *Config, v string) { c.BurstPeriod = parseUint(keyBurstPeriod, v, c) },
Update: func(c *Config, v string) { c.BurstPeriod = parseUint(KeyBurstPeriod, v, c) },
Validate: func(c *Config) {
if c.BurstPeriod <= 0 {
c.LogInvalidField(keyBurstPeriod, defaultBurstPeriod)
c.LogInvalidField(KeyBurstPeriod, defaultBurstPeriod)
c.BurstPeriod = defaultBurstPeriod
}
},
},
{
Name: keyCameraChan,
Name: KeyCameraChan,
Type_: typeUint,
Update: func(c *Config, v string) { c.CameraChan = uint8(parseUint(keyCameraChan, v, c)) },
Update: func(c *Config, v string) { c.CameraChan = uint8(parseUint(KeyCameraChan, v, c)) },
},
{
Name: keyCameraIP,
Name: KeyCameraIP,
Type_: typeString,
Update: func(c *Config, v string) { c.CameraIP = v },
Validate: func(c *Config) {
if c.CameraIP == "" {
c.LogInvalidField(keyCameraIP, defaultCameraIP)
c.LogInvalidField(KeyCameraIP, defaultCameraIP)
c.CameraIP = defaultCameraIP
}
},
},
{
Name: keyCBR,
Name: KeyCBR,
Type_: typeBool,
Update: func(c *Config, v string) { c.CBR = parseBool(keyCBR, v, c) },
Update: func(c *Config, v string) { c.CBR = parseBool(KeyCBR, v, c) },
},
{
Name: keyClipDuration,
Name: KeyClipDuration,
Type_: typeUint,
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
@ -194,34 +194,34 @@ var Variables = []struct {
},
Validate: func(c *Config) {
if c.ClipDuration <= 0 {
c.LogInvalidField(keyClipDuration, defaultClipDuration)
c.LogInvalidField(KeyClipDuration, defaultClipDuration)
c.ClipDuration = defaultClipDuration
}
},
},
{
Name: keyChannels,
Name: KeyChannels,
Type_: typeUint,
Update: func(c *Config, v string) { c.Channels = parseUint(keyChannels, v, c) },
Update: func(c *Config, v string) { c.Channels = parseUint(KeyChannels, v, c) },
},
{
Name: keyExposure,
Name: KeyExposure,
Type_: "enum:auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks",
Update: func(c *Config, v string) { c.Exposure = v },
},
{
Name: keyFileFPS,
Name: KeyFileFPS,
Type_: typeUint,
Update: func(c *Config, v string) { c.FileFPS = parseUint(keyFileFPS, v, c) },
Update: func(c *Config, v string) { c.FileFPS = parseUint(KeyFileFPS, v, c) },
Validate: func(c *Config) {
if c.FileFPS <= 0 || (c.FileFPS > 0 && c.Input != InputFile) {
c.LogInvalidField(keyFileFPS, defaultFileFPS)
c.LogInvalidField(KeyFileFPS, defaultFileFPS)
c.FileFPS = defaultFileFPS
}
},
},
{
Name: keyFilters,
Name: KeyFilters,
Type_: "enums:NoOp,MOG,VariableFPS,KNN,Difference,Basic",
Update: func(c *Config, v string) {
filters := strings.Split(v, ",")
@ -237,37 +237,37 @@ var Variables = []struct {
},
},
{
Name: keyFrameRate,
Name: KeyFrameRate,
Type_: typeUint,
Update: func(c *Config, v string) { c.FrameRate = parseUint(keyFrameRate, v, c) },
Update: func(c *Config, v string) { c.FrameRate = parseUint(KeyFrameRate, v, c) },
Validate: func(c *Config) {
if c.FrameRate <= 0 || c.FrameRate > 60 {
c.LogInvalidField(keyFrameRate, defaultFrameRate)
c.LogInvalidField(KeyFrameRate, defaultFrameRate)
c.FrameRate = defaultFrameRate
}
},
},
{
Name: keyHeight,
Name: KeyHeight,
Type_: typeUint,
Update: func(c *Config, v string) { c.Height = parseUint(keyHeight, v, c) },
Update: func(c *Config, v string) { c.Height = parseUint(KeyHeight, v, c) },
},
{
Name: keyHorizontalFlip,
Name: KeyHorizontalFlip,
Type_: typeBool,
Update: func(c *Config, v string) { c.HorizontalFlip = parseBool(keyHorizontalFlip, v, c) },
Update: func(c *Config, v string) { c.HorizontalFlip = parseBool(KeyHorizontalFlip, v, c) },
},
{
Name: keyHTTPAddress,
Name: KeyHTTPAddress,
Type_: typeString,
Update: func(c *Config, v string) { c.HTTPAddress = v },
},
{
Name: keyInput,
Name: KeyInput,
Type_: "enum:raspivid,rtsp,v4l,file,audio",
Update: func(c *Config, v string) {
c.Input = parseEnum(
keyInput,
KeyInput,
v,
map[string]uint8{
"raspivid": InputRaspivid,
@ -283,17 +283,17 @@ var Variables = []struct {
switch c.Input {
case InputRaspivid, InputV4L, InputFile, InputAudio, InputRTSP:
default:
c.LogInvalidField(keyInput, defaultInput)
c.LogInvalidField(KeyInput, defaultInput)
c.Input = defaultInput
}
},
},
{
Name: keyInputCodec,
Name: KeyInputCodec,
Type_: "enum:H264,H265,MJPEG,PCM,ADPCM",
Update: func(c *Config, v string) {
c.InputCodec = parseEnum(
keyInputCodec,
KeyInputCodec,
v,
map[string]uint8{
"h264": codecutil.H264,
@ -309,18 +309,18 @@ var Variables = []struct {
switch c.InputCodec {
case codecutil.H264, codecutil.MJPEG, codecutil.PCM, codecutil.ADPCM:
default:
c.LogInvalidField(keyInputCodec, defaultInputCodec)
c.LogInvalidField(KeyInputCodec, defaultInputCodec)
c.InputCodec = defaultInputCodec
}
},
},
{
Name: keyInputPath,
Name: KeyInputPath,
Type_: typeString,
Update: func(c *Config, v string) { c.InputPath = v },
},
{
Name: keyLogging,
Name: KeyLogging,
Type_: "enum:Debug,Info,Warning,Error,Fatal",
Update: func(c *Config, v string) {
switch v {
@ -348,60 +348,60 @@ var Variables = []struct {
},
},
{
Name: keyLoop,
Name: KeyLoop,
Type_: typeBool,
Update: func(c *Config, v string) { c.Loop = parseBool(keyLoop, v, c) },
Update: func(c *Config, v string) { c.Loop = parseBool(KeyLoop, v, c) },
},
{
Name: keyMinFPS,
Name: KeyMinFPS,
Type_: typeUint,
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) },
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) },
},
{
Name: keyMinFrames,
Name: KeyMinFrames,
Type_: typeUint,
Update: func(c *Config, v string) { c.MinFrames = parseUint(keyMinFrames, v, c) },
Update: func(c *Config, v string) { c.MinFrames = parseUint(KeyMinFrames, v, c) },
Validate: func(c *Config) {
const maxMinFrames = 1000
if c.MinFrames <= 0 || c.MinFrames > maxMinFrames {
c.LogInvalidField(keyMinFrames, defaultMinFrames)
c.LogInvalidField(KeyMinFrames, defaultMinFrames)
c.MinFrames = defaultMinFrames
}
},
},
{
Name: keyMode,
Name: KeyMode,
Type_: "enum:Normal,Paused,Burst,Loop",
Update: func(c *Config, v string) {
c.Loop = false
if v == keyLoop {
if v == KeyLoop {
c.Loop = true
}
},
},
{
Name: keyMotionDownscaling,
Name: KeyMotionDownscaling,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionDownscaling = parseUint(keyMotionDownscaling, v, c) },
Update: func(c *Config, v string) { c.MotionDownscaling = parseUint(KeyMotionDownscaling, v, c) },
},
{
Name: keyMotionHistory,
Name: KeyMotionHistory,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionHistory = parseUint(keyMotionHistory, v, c) },
Update: func(c *Config, v string) { c.MotionHistory = parseUint(KeyMotionHistory, v, c) },
},
{
Name: keyMotionInterval,
Name: KeyMotionInterval,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionInterval = parseUint(keyMotionInterval, v, c) },
Update: func(c *Config, v string) { c.MotionInterval = parseUint(KeyMotionInterval, v, c) },
},
{
Name: keyMotionKernel,
Name: KeyMotionKernel,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionKernel = parseUint(keyMotionKernel, v, c) },
Update: func(c *Config, v string) { c.MotionKernel = parseUint(KeyMotionKernel, v, c) },
},
{
Name: keyMotionMinArea,
Name: KeyMotionMinArea,
Type_: typeFloat,
Update: func(c *Config, v string) {
f, err := strconv.ParseFloat(v, 64)
@ -412,17 +412,17 @@ var Variables = []struct {
},
},
{
Name: keyMotionPadding,
Name: KeyMotionPadding,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionPadding = parseUint(keyMotionPadding, v, c) },
Update: func(c *Config, v string) { c.MotionPadding = parseUint(KeyMotionPadding, v, c) },
},
{
Name: keyMotionPixels,
Name: KeyMotionPixels,
Type_: typeUint,
Update: func(c *Config, v string) { c.MotionPixels = parseUint(keyMotionPixels, v, c) },
Update: func(c *Config, v string) { c.MotionPixels = parseUint(KeyMotionPixels, v, c) },
},
{
Name: keyMotionThreshold,
Name: KeyMotionThreshold,
Type_: typeFloat,
Update: func(c *Config, v string) {
f, err := strconv.ParseFloat(v, 64)
@ -433,7 +433,7 @@ var Variables = []struct {
},
},
{
Name: keyOutput,
Name: KeyOutput,
Type_: "enum:File,HTTP,RTMP,RTP",
Update: func(c *Config, v string) {
c.Outputs = make([]uint8, 1)
@ -452,12 +452,12 @@ var Variables = []struct {
},
},
{
Name: keyOutputPath,
Name: KeyOutputPath,
Type_: typeString,
Update: func(c *Config, v string) { c.OutputPath = v },
},
{
Name: keyOutputs,
Name: KeyOutputs,
Type_: "enums:File,HTTP,RTMP,RTP",
Update: func(c *Config, v string) {
outputs := strings.Split(v, ",")
@ -479,75 +479,75 @@ var Variables = []struct {
},
Validate: func(c *Config) {
if c.Outputs == nil {
c.LogInvalidField(keyOutputs, defaultOutput)
c.LogInvalidField(KeyOutputs, defaultOutput)
c.Outputs = append(c.Outputs, defaultOutput)
}
},
},
{
Name: keyPSITime,
Name: KeyPSITime,
Type_: typeUint,
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) },
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) },
},
{
Name: keyQuantization,
Name: KeyQuantization,
Type_: typeUint,
Update: func(c *Config, v string) { c.Quantization = parseUint(keyQuantization, v, c) },
Update: func(c *Config, v string) { c.Quantization = parseUint(KeyQuantization, v, c) },
},
{
Name: keyRBCapacity,
Name: KeyRBCapacity,
Type_: typeUint,
Update: func(c *Config, v string) { c.RBCapacity = parseUint(keyRBCapacity, v, c) },
Validate: func(c *Config) { c.RBCapacity = lessThanOrEqual(keyRBCapacity, c.RBCapacity, 0, c, defaultRBCapacity) },
Update: func(c *Config, v string) { c.RBCapacity = parseUint(KeyRBCapacity, v, c) },
Validate: func(c *Config) { c.RBCapacity = lessThanOrEqual(KeyRBCapacity, c.RBCapacity, 0, c, defaultRBCapacity) },
},
{
Name: keyRBWriteTimeout,
Name: KeyRBWriteTimeout,
Type_: typeUint,
Update: func(c *Config, v string) { c.RBWriteTimeout = parseUint(keyRBWriteTimeout, v, c) },
Update: func(c *Config, v string) { c.RBWriteTimeout = parseUint(KeyRBWriteTimeout, v, c) },
Validate: func(c *Config) {
c.RBWriteTimeout = lessThanOrEqual(keyRBWriteTimeout, c.RBWriteTimeout, 0, c, defaultRBWriteTimeout)
c.RBWriteTimeout = lessThanOrEqual(KeyRBWriteTimeout, c.RBWriteTimeout, 0, c, defaultRBWriteTimeout)
},
},
{
Name: keyRecPeriod,
Name: KeyRecPeriod,
Type_: typeFloat,
Update: func(c *Config, v string) {
_v, err := strconv.ParseFloat(v, 64)
if err != nil {
c.Logger.Log(logger.Warning, fmt.Sprintf("invalid %s param", keyRecPeriod), "value", v)
c.Logger.Log(logger.Warning, fmt.Sprintf("invalid %s param", KeyRecPeriod), "value", v)
}
c.RecPeriod = _v
},
},
{
Name: keyRotation,
Name: KeyRotation,
Type_: typeUint,
Update: func(c *Config, v string) { c.Rotation = parseUint(keyRotation, v, c) },
Update: func(c *Config, v string) { c.Rotation = parseUint(KeyRotation, v, c) },
},
{
Name: keyRTMPURL,
Name: KeyRTMPURL,
Type_: typeString,
Update: func(c *Config, v string) { c.RTMPURL = v },
},
{
Name: keyRTPAddress,
Name: KeyRTPAddress,
Type_: typeString,
Update: func(c *Config, v string) { c.RTPAddress = v },
Validate: func(c *Config) {
if c.RTPAddress == "" {
c.LogInvalidField(keyRTPAddress, defaultRTPAddr)
c.LogInvalidField(KeyRTPAddress, defaultRTPAddr)
c.RTPAddress = defaultRTPAddr
}
},
},
{
Name: keySampleRate,
Name: KeySampleRate,
Type_: typeUint,
Update: func(c *Config, v string) { c.SampleRate = parseUint(keySampleRate, v, c) },
Update: func(c *Config, v string) { c.SampleRate = parseUint(KeySampleRate, v, c) },
},
{
Name: keySaturation,
Name: KeySaturation,
Type_: "int",
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
@ -558,24 +558,24 @@ var Variables = []struct {
},
},
{
Name: keySuppress,
Name: KeySuppress,
Type_: typeBool,
Update: func(c *Config, v string) {
c.Suppress = parseBool(keySuppress, v, c)
c.Suppress = parseBool(KeySuppress, v, c)
c.Logger.(*logger.Logger).SetSuppress(c.Suppress)
},
},
{
Name: keyVBRBitrate,
Name: KeyVBRBitrate,
Type_: typeUint,
Update: func(c *Config, v string) { c.VBRBitrate = parseUint(keyVBRBitrate, v, c) },
Update: func(c *Config, v string) { c.VBRBitrate = parseUint(KeyVBRBitrate, v, c) },
},
{
Name: keyVBRQuality,
Name: KeyVBRQuality,
Type_: "enum:standard,fair,good,great,excellent",
Update: func(c *Config, v string) {
c.VBRQuality = Quality(parseEnum(
keyVBRQuality,
KeyVBRQuality,
v,
map[string]uint8{
"standard": uint8(QualityStandard),
@ -589,14 +589,14 @@ var Variables = []struct {
},
},
{
Name: keyVerticalFlip,
Name: KeyVerticalFlip,
Type_: typeBool,
Update: func(c *Config, v string) { c.VerticalFlip = parseBool(keyVerticalFlip, v, c) },
Update: func(c *Config, v string) { c.VerticalFlip = parseBool(KeyVerticalFlip, v, c) },
},
{
Name: keyWidth,
Name: KeyWidth,
Type_: typeUint,
Update: func(c *Config, v string) { c.Width = parseUint(keyWidth, v, c) },
Update: func(c *Config, v string) { c.Width = parseUint(KeyWidth, v, c) },
},
}