Browse Source

fix default value of some settings (#2367)

rtmpServerKey, rtmpServerCert, recordPath, rpiCameraExposure,
rpiCameraAWB, rpiCameraDenoise, rpiCameraMetering, rpiCameraAfMode,
rpiCameraAfRange, rpiCameraAfSpeed were not set correctly when missing
in the configuration file.
pull/2376/head
Alessandro Ros 2 years ago committed by GitHub
parent
commit
b86dc979ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      internal/conf/conf.go
  2. 52
      internal/conf/conf_test.go
  3. 7
      internal/conf/path.go

5
internal/conf/conf.go

@ -371,6 +371,8 @@ func (conf *Conf) UnmarshalJSON(b []byte) error {
conf.RTMP = true conf.RTMP = true
conf.RTMPAddress = ":1935" conf.RTMPAddress = ":1935"
conf.RTMPSAddress = ":1936" conf.RTMPSAddress = ":1936"
conf.RTMPServerKey = "server.key"
conf.RTMPServerCert = "server.crt"
// HLS // HLS
conf.HLS = true conf.HLS = true
@ -391,13 +393,14 @@ func (conf *Conf) UnmarshalJSON(b []byte) error {
conf.WebRTCServerCert = "server.crt" conf.WebRTCServerCert = "server.crt"
conf.WebRTCAllowOrigin = "*" conf.WebRTCAllowOrigin = "*"
conf.WebRTCICEServers2 = []WebRTCICEServer{{URL: "stun:stun.l.google.com:19302"}} conf.WebRTCICEServers2 = []WebRTCICEServer{{URL: "stun:stun.l.google.com:19302"}}
conf.WebRTCICEHostNAT1To1IPs = []string{}
// SRT // SRT
conf.SRT = true conf.SRT = true
conf.SRTAddress = ":8890" conf.SRTAddress = ":8890"
// Record // Record
conf.RecordPath = "./recordings/%path/%Y-%m-%d_%H-%M-%S" conf.RecordPath = "./recordings/%path/%Y-%m-%d_%H-%M-%S-%f"
conf.RecordFormat = "fmp4" conf.RecordFormat = "fmp4"
conf.RecordPartDuration = 100 * StringDuration(time.Millisecond) conf.RecordPartDuration = 100 * StringDuration(time.Millisecond)
conf.RecordSegmentDuration = 3600 * StringDuration(time.Second) conf.RecordSegmentDuration = 3600 * StringDuration(time.Second)

52
internal/conf/conf_test.go

@ -58,11 +58,18 @@ func TestConfFromFile(t *testing.T) {
RPICameraContrast: 1, RPICameraContrast: 1,
RPICameraSaturation: 1, RPICameraSaturation: 1,
RPICameraSharpness: 1, RPICameraSharpness: 1,
RPICameraExposure: "normal",
RPICameraAWB: "auto",
RPICameraDenoise: "off",
RPICameraMetering: "centre",
RPICameraFPS: 30, RPICameraFPS: 30,
RPICameraIDRPeriod: 60, RPICameraIDRPeriod: 60,
RPICameraBitrate: 1000000, RPICameraBitrate: 1000000,
RPICameraProfile: "main", RPICameraProfile: "main",
RPICameraLevel: "4.1", RPICameraLevel: "4.1",
RPICameraAfMode: "auto",
RPICameraAfRange: "normal",
RPICameraAfSpeed: "normal",
RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX", RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX",
RunOnDemandStartTimeout: 5 * StringDuration(time.Second), RunOnDemandStartTimeout: 5 * StringDuration(time.Second),
RunOnDemandCloseAfter: 10 * StringDuration(time.Second), RunOnDemandCloseAfter: 10 * StringDuration(time.Second),
@ -129,11 +136,18 @@ func TestConfFromFileAndEnv(t *testing.T) {
RPICameraContrast: 1, RPICameraContrast: 1,
RPICameraSaturation: 1, RPICameraSaturation: 1,
RPICameraSharpness: 1, RPICameraSharpness: 1,
RPICameraExposure: "normal",
RPICameraAWB: "auto",
RPICameraDenoise: "off",
RPICameraMetering: "centre",
RPICameraFPS: 30, RPICameraFPS: 30,
RPICameraIDRPeriod: 60, RPICameraIDRPeriod: 60,
RPICameraBitrate: 1000000, RPICameraBitrate: 1000000,
RPICameraProfile: "main", RPICameraProfile: "main",
RPICameraLevel: "4.1", RPICameraLevel: "4.1",
RPICameraAfMode: "auto",
RPICameraAfRange: "normal",
RPICameraAfSpeed: "normal",
RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX", RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX",
RunOnDemandStartTimeout: 10 * StringDuration(time.Second), RunOnDemandStartTimeout: 10 * StringDuration(time.Second),
RunOnDemandCloseAfter: 10 * StringDuration(time.Second), RunOnDemandCloseAfter: 10 * StringDuration(time.Second),
@ -161,11 +175,18 @@ func TestConfFromEnvOnly(t *testing.T) {
RPICameraContrast: 1, RPICameraContrast: 1,
RPICameraSaturation: 1, RPICameraSaturation: 1,
RPICameraSharpness: 1, RPICameraSharpness: 1,
RPICameraExposure: "normal",
RPICameraAWB: "auto",
RPICameraDenoise: "off",
RPICameraMetering: "centre",
RPICameraFPS: 30, RPICameraFPS: 30,
RPICameraIDRPeriod: 60, RPICameraIDRPeriod: 60,
RPICameraBitrate: 1000000, RPICameraBitrate: 1000000,
RPICameraProfile: "main", RPICameraProfile: "main",
RPICameraLevel: "4.1", RPICameraLevel: "4.1",
RPICameraAfMode: "auto",
RPICameraAfRange: "normal",
RPICameraAfSpeed: "normal",
RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX", RPICameraTextOverlay: "%Y-%m-%d %H:%M:%S - MediaMTX",
RunOnDemandStartTimeout: 10 * StringDuration(time.Second), RunOnDemandStartTimeout: 10 * StringDuration(time.Second),
RunOnDemandCloseAfter: 10 * StringDuration(time.Second), RunOnDemandCloseAfter: 10 * StringDuration(time.Second),
@ -291,3 +312,34 @@ func TestConfErrors(t *testing.T) {
}) })
} }
} }
func TestSampleConfFile(t *testing.T) {
func() {
conf1, confPath1, err := Load("../../mediamtx.yml", nil)
require.NoError(t, err)
require.Equal(t, "../../mediamtx.yml", confPath1)
delete(conf1.Paths, "all")
conf2, confPath2, err := Load("", nil)
require.NoError(t, err)
require.Equal(t, "", confPath2)
require.Equal(t, conf1, conf2)
}()
func() {
conf1, confPath1, err := Load("../../mediamtx.yml", nil)
require.NoError(t, err)
require.Equal(t, "../../mediamtx.yml", confPath1)
tmpf, err := writeTempFile([]byte("paths:\n all:"))
require.NoError(t, err)
defer os.Remove(tmpf)
conf2, confPath2, err := Load(tmpf, nil)
require.NoError(t, err)
require.Equal(t, tmpf, confPath2)
require.Equal(t, conf1.Paths, conf2.Paths)
}()
}

7
internal/conf/path.go

@ -395,11 +395,18 @@ func (pconf *PathConf) UnmarshalJSON(b []byte) error {
pconf.RPICameraContrast = 1 pconf.RPICameraContrast = 1
pconf.RPICameraSaturation = 1 pconf.RPICameraSaturation = 1
pconf.RPICameraSharpness = 1 pconf.RPICameraSharpness = 1
pconf.RPICameraExposure = "normal"
pconf.RPICameraAWB = "auto"
pconf.RPICameraDenoise = "off"
pconf.RPICameraMetering = "centre"
pconf.RPICameraFPS = 30 pconf.RPICameraFPS = 30
pconf.RPICameraIDRPeriod = 60 pconf.RPICameraIDRPeriod = 60
pconf.RPICameraBitrate = 1000000 pconf.RPICameraBitrate = 1000000
pconf.RPICameraProfile = "main" pconf.RPICameraProfile = "main"
pconf.RPICameraLevel = "4.1" pconf.RPICameraLevel = "4.1"
pconf.RPICameraAfMode = "auto"
pconf.RPICameraAfRange = "normal"
pconf.RPICameraAfSpeed = "normal"
pconf.RPICameraTextOverlay = "%Y-%m-%d %H:%M:%S - MediaMTX" pconf.RPICameraTextOverlay = "%Y-%m-%d %H:%M:%S - MediaMTX"
// External commands // External commands

Loading…
Cancel
Save