input/gvctrl/gvctrl.go: added extra form fields in the case of channel 1 control

Also updated testing. Added a new test.
This commit is contained in:
Saxon 2019-10-25 12:03:13 +10:30
parent c01879d364
commit f74e3a3d7c
2 changed files with 68 additions and 19 deletions

View File

@ -208,7 +208,7 @@ func TestHeight(t *testing.T) {
{
s: settings{ch: 1},
h: 1080,
want: settings{ch: 1, res: "192001080"},
want: settings{ch: 1, res: "19201080"},
},
{
s: settings{ch: 1},
@ -372,7 +372,7 @@ func TestPopulateForm(t *testing.T) {
}{
{
in: newSettings(),
want: "dwConnType=5&mpeg_type=10&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=0&max_bit_rate=512000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEnableIO=1&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bEnableOSDCameraName=1&bCamNamePos=2&bEnableOSDDate=1&bDatePos=2&bEnableOSDTime=1&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
want: "dwConnType=5&mpeg_type=10&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=0&max_bit_rate=512000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bCamNamePos=2&bDatePos=2&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
},
{
in: settings{
@ -384,8 +384,9 @@ func TestPopulateForm(t *testing.T) {
vbrBitrate: defaultVBRBitrate,
cbrBitrate: defaultCBRBitrate,
refresh: defaultRefresh,
ch: 2,
},
want: "dwConnType=5&mpeg_type=28&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=0&max_bit_rate=512000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEnableIO=1&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bEnableOSDCameraName=1&bCamNamePos=2&bEnableOSDDate=1&bDatePos=2&bEnableOSDTime=1&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
want: "dwConnType=5&mpeg_type=28&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=0&max_bit_rate=512000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bCamNamePos=2&bDatePos=2&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
},
{
in: settings{
@ -397,8 +398,9 @@ func TestPopulateForm(t *testing.T) {
vbrBitrate: defaultVBRBitrate,
cbrBitrate: defaultCBRBitrate,
refresh: defaultRefresh,
ch: 2,
},
want: "dwConnType=5&mpeg_type=4&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=1&dwVbrQuality=2&vbrmaxbitrate=500000&custom_qp_init=25&gop_N=1500&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEnableIO=1&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bEnableOSDCameraName=1&bCamNamePos=2&bEnableOSDDate=1&bDatePos=2&bEnableOSDTime=1&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
want: "dwConnType=5&mpeg_type=4&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=1&dwVbrQuality=2&vbrmaxbitrate=500000&custom_qp_init=25&gop_N=1500&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bCamNamePos=2&bDatePos=2&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
},
{
in: settings{
@ -410,8 +412,23 @@ func TestPopulateForm(t *testing.T) {
vbrBitrate: defaultVBRBitrate,
cbrBitrate: defaultCBRBitrate,
refresh: defaultRefresh,
ch: 2,
},
want: "dwConnType=5&mpeg_type=10&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=1&dwVbrQuality=2&vbrmaxbitrate=250000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEnableIO=1&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bEnableOSDCameraName=1&bCamNamePos=2&bEnableOSDDate=1&bDatePos=2&bEnableOSDTime=1&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
want: "dwConnType=5&mpeg_type=10&dwflicker_hz=0&szResolution=6400360&dwFrameRate=25000&vbr_enable=1&dwVbrQuality=2&vbrmaxbitrate=250000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&dwEncProfile=1&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&bEbIoIn=1&bEbIoIn1=1&bOSDFontSize=0&bCamNamePos=2&bDatePos=2&bTimePos=2&szOsdCamName=Camera&u16PostAlarmBuf=1&dwCameraId=1&LangCode=undefined&Recflag=0&submit=Apply",
},
{
in: settings{
codec: CodecH264,
res: res1080,
frameRate: defaultFrameRate,
vbr: "0",
quality: defaultQuality,
vbrBitrate: defaultVBRBitrate,
cbrBitrate: "2048000",
refresh: defaultRefresh,
ch: 1,
},
want: "dwConnType=5&mpeg_type=10&dwflicker_less=1&dwflicker_hz=0&szResolution=19201080&dwFrameRate=25000&vbr_enable=0&max_bit_rate=2048000&custom_rate_control_type=0&custom_bitrate=0&custom_qp_init=25&custom_qp_min=10&custom_qp_max=40&gop_N=2000&bSliceMode=4&dwEncProfile=3&dwEncLevel=31&dwEntropy=0&u8PreAlarmBuf=1&u32PostAlarmBuf2Disk=1&u8SplitInterval=5&szCamName=Camera&bEbIoIn=1&bEbIoIn1=1&szOsdCamName=Camera&bOSDFontSize=0&bCamNamePos=2&bDatePos=2&bTimePos=2&bAudioCodec=7&bTVoutFormat=2&bReadyLed=0&bLedLan=0&bLedWan=0&bLedMonitor=0&bAlarmLedAutoLevel=5&bAlarmLedAutoDuration=60&bAlarmLed=1&face_detect_level=1&bDayNight=0&bDayNightAutoLevel=3&bIRout=0&bAutoIris=0&IrisType=1&bBLC=0&bIR=1&bNSR=0&ReplaceHomePreset1=0&u16PostAlarmBuf=1&dwCameraId=0&LangCode=undefined&Recflag=0&webpageEncoding=windows-1252&submit=Apply",
},
}

View File

@ -36,10 +36,10 @@ import (
// The strings used in encoding the settings form to indicate resultion.
const (
res256 = "4480256" // 480x256
res360 = "6400360" // 640x360
res720 = "12800720" // 1280x720
res1080 = "192001080" // 1920x1080
res256 = "4480256" // 480x256
res360 = "6400360" // 640x360
res720 = "12800720" // 1280x720
res1080 = "19201080" // 1920x1080
)
// Default values for fields in the settings struct when the newSettings
@ -121,6 +121,37 @@ func populateForm(s settings) url.Values {
f.Set("dwFrameRate", s.frameRate)
f.Set("custom_qp_init", "25")
if s.ch == 1 {
f.Set("dwflicker_less", "1")
f.Set("bSliceMode", "4")
f.Set("dwCameraId", "0")
f.Set("szCamName", "Camera")
f.Set("bAudioCodec", "7")
f.Set("bTVoutFormat", "2")
f.Set("bReadyLed", "0")
f.Set("bLedLan", "0")
f.Set("bLedWan", "0")
f.Set("bLedMonitor", "0")
f.Set("bAlarmLedAutoLevel", "5")
f.Set("bAlarmLedAutoDuration", "60")
f.Set("bAlarmLed", "1")
f.Set("face_detect_level", "1")
f.Set("bDayNight", "0")
f.Set("bDayNightAutoLevel", "3")
f.Set("bIRout", "0")
f.Set("bAutoIris", "0")
f.Set("IrisType", "1")
f.Set("bBLC", "0")
f.Set("bIR", "1")
f.Set("bNSR", "0")
f.Set("ReplaceHomePreset1", "0")
f.Set("webpageEncoding", "windows-1252")
} else if s.ch == 2 {
f.Set("dwCameraId", "1")
} else {
panic("invalid channel")
}
if s.codec == CodecMJPEG {
f.Set("vbr_enable", "1")
f.Set("dwVbrQuality", string(s.quality))
@ -160,7 +191,12 @@ func populateForm(s settings) url.Values {
}
if s.codec == CodecH264 || s.codec == CodecH265 {
f.Set("dwEncProfile", "1")
if s.ch == 1 {
f.Set("dwEncProfile", "3")
} else {
f.Set("dwEncProfile", "1")
}
f.Set("dwEncLevel", "31")
f.Set("dwEntropy", "0")
}
@ -168,21 +204,17 @@ func populateForm(s settings) url.Values {
f.Set("u8PreAlarmBuf", "1")
f.Set("u32PostAlarmBuf2Disk", "1")
f.Set("u8SplitInterval", "5")
f.Set("bEnableIO", "1")
f.Set("bEbIoIn", "1")
f.Set("bEbIoIn1", "1")
f.Set("bOSDFontSize", "0")
f.Set("bEnableOSDCameraName", "1")
f.Set("bCamNamePos", "2")
f.Set("bEnableOSDDate", "1")
f.Set("bDatePos", "2")
f.Set("bEnableOSDTime", "1")
f.Set("bTimePos", "2")
f.Set("szOsdCamName", "Camera")
f.Set("bOSDFontSize", "0")
f.Set("bCamNamePos", "2")
f.Set("bDatePos", "2")
f.Set("bTimePos", "2")
f.Set("u16PostAlarmBuf", "1")
f.Set("dwCameraId", "1") // Channel=1 => cameraID=0 and chanel=2 => cameraID=1
f.Set("LangCode", "undefined")
f.Set("Recflag", "0")
f.Set("submit", "Apply")
return f
}