cmd/rv/main.go & revid/config/variables.go: rename Variables Type_ field to Type and comment Variables global.

This commit is contained in:
Saxon Nelson-Milton 2021-07-22 13:03:01 +09:30
parent 05a6b4435a
commit 49aa588aae
2 changed files with 65 additions and 62 deletions

View File

@ -238,7 +238,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger.
func createVarMap() map[string]string {
m := make(map[string]string)
for _, v := range config.Variables {
m[v.Name] = v.Type_
m[v.Name] = v.Type
}
return m
}

View File

@ -135,40 +135,43 @@ const (
defaultMinFPS = 1.0
)
// 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.
var Variables = []struct {
Name string
Type_ string
Type string
Update func(*Config, string)
Validate func(*Config)
}{
{
Name: KeyAutoWhiteBalance,
Type_: "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
Type: "enum:off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon",
Update: func(c *Config, v string) { c.AutoWhiteBalance = v },
},
{
Name: KeyAWBGains,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.AWBGains = v },
},
{
Name: KeyBitDepth,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.BitDepth = parseUint(KeyBitDepth, v, c) },
},
{
Name: KeyBitrate,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Bitrate = parseUint(KeyBitrate, v, c) },
},
{
Name: KeyBrightness,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Brightness = parseUint(KeyBrightness, v, c) },
},
{
Name: KeyBurstPeriod,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.BurstPeriod = parseUint(KeyBurstPeriod, v, c) },
Validate: func(c *Config) {
if c.BurstPeriod <= 0 {
@ -179,12 +182,12 @@ var Variables = []struct {
},
{
Name: KeyCameraChan,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.CameraChan = uint8(parseUint(KeyCameraChan, v, c)) },
},
{
Name: KeyCameraIP,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.CameraIP = v },
Validate: func(c *Config) {
if c.CameraIP == "" {
@ -195,12 +198,12 @@ var Variables = []struct {
},
{
Name: KeyCBR,
Type_: typeBool,
Type: typeBool,
Update: func(c *Config, v string) { c.CBR = parseBool(KeyCBR, v, c) },
},
{
Name: KeyClipDuration,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
if err != nil {
@ -217,27 +220,27 @@ var Variables = []struct {
},
{
Name: KeyChannels,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Channels = parseUint(KeyChannels, v, c) },
},
{
Name: KeyContrast,
Type_: typeInt,
Type: typeInt,
Update: func(c *Config, v string) { c.Contrast = parseInt(KeyContrast, v, c) },
},
{
Name: KeyEV,
Type_: typeInt,
Type: typeInt,
Update: func(c *Config, v string) { c.EV = parseInt(KeyEV, v, c) },
},
{
Name: KeyExposure,
Type_: "enum:auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks",
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,
Type_: typeUint,
Type: typeUint,
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) {
@ -248,7 +251,7 @@ var Variables = []struct {
},
{
Name: KeyFilters,
Type_: "enums:NoOp,MOG,VariableFPS,KNN,Difference,Basic",
Type: "enums:NoOp,MOG,VariableFPS,KNN,Difference,Basic",
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}
@ -264,7 +267,7 @@ var Variables = []struct {
},
{
Name: KeyFrameRate,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.FrameRate = parseUint(KeyFrameRate, v, c) },
Validate: func(c *Config) {
if c.FrameRate <= 0 || c.FrameRate > 60 {
@ -275,22 +278,22 @@ var Variables = []struct {
},
{
Name: KeyHeight,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Height = parseUint(KeyHeight, v, c) },
},
{
Name: KeyHorizontalFlip,
Type_: typeBool,
Type: typeBool,
Update: func(c *Config, v string) { c.HorizontalFlip = parseBool(KeyHorizontalFlip, v, c) },
},
{
Name: KeyHTTPAddress,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.HTTPAddress = v },
},
{
Name: KeyInput,
Type_: "enum:raspivid,raspistill,rtsp,v4l,file,audio",
Type: "enum:raspivid,raspistill,rtsp,v4l,file,audio",
Update: func(c *Config, v string) {
c.Input = parseEnum(
KeyInput,
@ -317,7 +320,7 @@ var Variables = []struct {
},
{
Name: KeyInputCodec,
Type_: "enum:h264,h265,mjpeg,jpeg,pcm,adpcm",
Type: "enum:h264,h265,mjpeg,jpeg,pcm,adpcm",
Update: func(c *Config, v string) {
c.InputCodec = v
},
@ -330,17 +333,17 @@ var Variables = []struct {
},
{
Name: KeyInputPath,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.InputPath = v },
},
{
Name: KeyISO,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.ISO = parseUint(KeyISO, v, c) },
},
{
Name: KeyLogging,
Type_: "enum:Debug,Info,Warning,Error,Fatal",
Type: "enum:Debug,Info,Warning,Error,Fatal",
Update: func(c *Config, v string) {
switch v {
case "Debug":
@ -368,18 +371,18 @@ var Variables = []struct {
},
{
Name: KeyLoop,
Type_: typeBool,
Type: typeBool,
Update: func(c *Config, v string) { c.Loop = parseBool(KeyLoop, v, c) },
},
{
Name: KeyMinFPS,
Type_: typeUint,
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) },
},
{
Name: KeyMinFrames,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MinFrames = parseUint(KeyMinFrames, v, c) },
Validate: func(c *Config) {
const maxMinFrames = 1000
@ -391,7 +394,7 @@ var Variables = []struct {
},
{
Name: KeyMode,
Type_: "enum:Normal,Paused,Burst,Loop",
Type: "enum:Normal,Paused,Burst,Loop",
Update: func(c *Config, v string) {
c.Loop = false
if v == KeyLoop {
@ -401,27 +404,27 @@ var Variables = []struct {
},
{
Name: KeyMotionDownscaling,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionDownscaling = parseUint(KeyMotionDownscaling, v, c) },
},
{
Name: KeyMotionHistory,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionHistory = parseUint(KeyMotionHistory, v, c) },
},
{
Name: KeyMotionInterval,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionInterval = parseUint(KeyMotionInterval, v, c) },
},
{
Name: KeyMotionKernel,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionKernel = parseUint(KeyMotionKernel, v, c) },
},
{
Name: KeyMotionMinArea,
Type_: typeFloat,
Type: typeFloat,
Update: func(c *Config, v string) {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -432,17 +435,17 @@ var Variables = []struct {
},
{
Name: KeyMotionPadding,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionPadding = parseUint(KeyMotionPadding, v, c) },
},
{
Name: KeyMotionPixels,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.MotionPixels = parseUint(KeyMotionPixels, v, c) },
},
{
Name: KeyMotionThreshold,
Type_: typeFloat,
Type: typeFloat,
Update: func(c *Config, v string) {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -453,7 +456,7 @@ var Variables = []struct {
},
{
Name: KeyOutput,
Type_: "enum:File,HTTP,RTMP,RTP",
Type: "enum:File,HTTP,RTMP,RTP",
Update: func(c *Config, v string) {
c.Outputs = make([]uint8, 1)
switch strings.ToLower(v) {
@ -474,12 +477,12 @@ var Variables = []struct {
},
{
Name: KeyOutputPath,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.OutputPath = v },
},
{
Name: KeyOutputs,
Type_: "enums:File,HTTP,RTMP,RTP",
Type: "enums:File,HTTP,RTMP,RTP",
Update: func(c *Config, v string) {
outputs := strings.Split(v, ",")
c.Outputs = make([]uint8, len(outputs))
@ -509,18 +512,18 @@ var Variables = []struct {
},
{
Name: KeyPSITime,
Type_: typeUint,
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) },
},
{
Name: KeyQuantization,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Quantization = parseUint(KeyQuantization, v, c) },
},
{
Name: KeyPoolCapacity,
Type_: typeUint,
Type: typeUint,
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)
@ -528,7 +531,7 @@ var Variables = []struct {
},
{
Name: KeyPoolStartElementSize,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.PoolStartElementSize = parseUint("PoolStartElementSize", v, c) },
Validate: func(c *Config) {
c.PoolStartElementSize = lessThanOrEqual("PoolStartElementSize", c.PoolStartElementSize, 0, c, defaultPoolStartElementSize)
@ -536,7 +539,7 @@ var Variables = []struct {
},
{
Name: KeyPoolWriteTimeout,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.PoolWriteTimeout = parseUint(KeyPoolWriteTimeout, v, c) },
Validate: func(c *Config) {
c.PoolWriteTimeout = lessThanOrEqual(KeyPoolWriteTimeout, c.PoolWriteTimeout, 0, c, defaultPoolWriteTimeout)
@ -544,7 +547,7 @@ var Variables = []struct {
},
{
Name: KeyRecPeriod,
Type_: typeFloat,
Type: typeFloat,
Update: func(c *Config, v string) {
_v, err := strconv.ParseFloat(v, 64)
if err != nil {
@ -555,17 +558,17 @@ var Variables = []struct {
},
{
Name: KeyRotation,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Rotation = parseUint(KeyRotation, v, c) },
},
{
Name: KeyRTMPURL,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.RTMPURL = v },
},
{
Name: KeyRTPAddress,
Type_: typeString,
Type: typeString,
Update: func(c *Config, v string) { c.RTPAddress = v },
Validate: func(c *Config) {
if c.RTPAddress == "" {
@ -576,22 +579,22 @@ var Variables = []struct {
},
{
Name: KeySampleRate,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.SampleRate = parseUint(KeySampleRate, v, c) },
},
{
Name: KeySaturation,
Type_: typeInt,
Type: typeInt,
Update: func(c *Config, v string) { c.Saturation = parseInt(KeySaturation, v, c) },
},
{
Name: KeySharpness,
Type_: typeInt,
Type: typeInt,
Update: func(c *Config, v string) { c.Sharpness = parseInt(KeySharpness, v, c) },
},
{
Name: KeyJPEGQuality,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
if err != nil {
@ -602,7 +605,7 @@ var Variables = []struct {
},
{
Name: KeySuppress,
Type_: typeBool,
Type: typeBool,
Update: func(c *Config, v string) {
c.Suppress = parseBool(KeySuppress, v, c)
c.Logger.(*logger.Logger).SetSuppress(c.Suppress)
@ -610,7 +613,7 @@ var Variables = []struct {
},
{
Name: KeyTimelapseInterval,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
if err != nil {
@ -621,7 +624,7 @@ var Variables = []struct {
},
{
Name: KeyTimelapseDuration,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) {
_v, err := strconv.Atoi(v)
if err != nil {
@ -632,12 +635,12 @@ var Variables = []struct {
},
{
Name: KeyVBRBitrate,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.VBRBitrate = parseUint(KeyVBRBitrate, v, c) },
},
{
Name: KeyVBRQuality,
Type_: "enum:standard,fair,good,great,excellent",
Type: "enum:standard,fair,good,great,excellent",
Update: func(c *Config, v string) {
c.VBRQuality = Quality(parseEnum(
KeyVBRQuality,
@ -655,12 +658,12 @@ var Variables = []struct {
},
{
Name: KeyVerticalFlip,
Type_: typeBool,
Type: typeBool,
Update: func(c *Config, v string) { c.VerticalFlip = parseBool(KeyVerticalFlip, v, c) },
},
{
Name: KeyWidth,
Type_: typeUint,
Type: typeUint,
Update: func(c *Config, v string) { c.Width = parseUint(KeyWidth, v, c) },
},
}