From 61d300396d7a32cfff53252e15427b7298dc8650 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sun, 6 Aug 2023 21:40:08 +0200 Subject: [PATCH] remove 'disable' from names of configuration parameters (#2101) --- apidocs/openapi.yaml | 8 ++--- bench/proxy/start.sh | 8 ++--- internal/conf/conf.go | 32 ++++++++++++++--- internal/core/api_test.go | 4 +-- internal/core/core.go | 24 ++++++------- internal/core/hls_source_test.go | 6 ++-- internal/core/path_manager_test.go | 12 +++---- internal/core/rtmp_server_test.go | 22 ++++++------ internal/core/rtsp_server_test.go | 38 ++++++++++----------- internal/core/rtsp_source_test.go | 12 +++---- internal/highleveltests/rtsp_server_test.go | 18 +++++----- mediamtx.yml | 16 ++++----- 12 files changed, 112 insertions(+), 88 deletions(-) diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index e41a2e80..da1f7a4f 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -55,7 +55,7 @@ components: type: boolean # RTSP - rtspDisable: + rtsp: type: boolean protocols: type: array @@ -87,7 +87,7 @@ components: type: string # RTMP - rtmpDisable: + rtmp: type: boolean rtmpAddress: type: string @@ -101,7 +101,7 @@ components: type: string # HLS - hlsDisable: + hls: type: boolean hlsAddress: type: string @@ -133,7 +133,7 @@ components: type: string # WebRTC - webrtcDisable: + webrtc: type: boolean webrtcAddress: type: string diff --git a/bench/proxy/start.sh b/bench/proxy/start.sh index dd8aa02f..142d8bb7 100644 --- a/bench/proxy/start.sh +++ b/bench/proxy/start.sh @@ -7,7 +7,7 @@ PROXY_PROTOCOL=tcp # source CONF="" -CONF="${CONF}hlsDisable: yes\n" +CONF="${CONF}hls: no\n" CONF="${CONF}rtspAddress: :8555\n" CONF="${CONF}rtpAddress: :8002\n" CONF="${CONF}rtcpAddress: :8003\n" @@ -15,7 +15,7 @@ CONF="${CONF}paths:\n" CONF="${CONF} all:\n" echo -e "$CONF" > /source.conf -RTSP_RTMPDISABLE=yes /mediamtx /source.conf & +RTSP_RTMP=no /mediamtx /source.conf & sleep 1 @@ -28,7 +28,7 @@ sleep 1 # proxy CONF="" -CONF="${CONF}hlsDisable: yes\n" +CONF="${CONF}hls: no\n" CONF="${CONF}pprof: yes\n" CONF="${CONF}paths:\n" for i in $(seq 1 $PROXY_COUNT); do @@ -38,7 +38,7 @@ for i in $(seq 1 $PROXY_COUNT); do done echo -e "$CONF" > /proxy.conf -RTSP_RTMPDISABLE=yes /mediamtx /proxy.conf & +RTSP_RTMP=no /mediamtx /proxy.conf & sleep 5 diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 8dc04ce4..ea6e5ee9 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -107,7 +107,8 @@ type Conf struct { RunOnConnectRestart bool `json:"runOnConnectRestart"` // RTSP - RTSPDisable bool `json:"rtspDisable"` + RTSP bool `json:"rtsp"` + RTSPDisable bool `json:"rtspDisable"` // deprecated Protocols Protocols `json:"protocols"` Encryption Encryption `json:"encryption"` RTSPAddress string `json:"rtspAddress"` @@ -122,7 +123,8 @@ type Conf struct { AuthMethods AuthMethods `json:"authMethods"` // RTMP - RTMPDisable bool `json:"rtmpDisable"` + RTMP bool `json:"rtmp"` + RTMPDisable bool `json:"rtmpDisable"` // deprecated RTMPAddress string `json:"rtmpAddress"` RTMPEncryption Encryption `json:"rtmpEncryption"` RTMPSAddress string `json:"rtmpsAddress"` @@ -130,7 +132,8 @@ type Conf struct { RTMPServerCert string `json:"rtmpServerCert"` // HLS - HLSDisable bool `json:"hlsDisable"` + HLS bool `json:"hls"` + HLSDisable bool `json:"hlsDisable"` // depreacted HLSAddress string `json:"hlsAddress"` HLSEncryption bool `json:"hlsEncryption"` HLSServerKey string `json:"hlsServerKey"` @@ -146,7 +149,8 @@ type Conf struct { HLSDirectory string `json:"hlsDirectory"` // WebRTC - WebRTCDisable bool `json:"webrtcDisable"` + WebRTC bool `json:"webrtc"` + WebRTCDisable bool `json:"webrtcDisable"` // deprecated WebRTCAddress string `json:"webrtcAddress"` WebRTCEncryption bool `json:"webrtcEncryption"` WebRTCServerKey string `json:"webrtcServerKey"` @@ -231,6 +235,9 @@ func (conf *Conf) Check() error { } // RTSP + if conf.RTSPDisable { + conf.RTSP = false + } if conf.Encryption == EncryptionStrict { if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDP)]; ok { return fmt.Errorf("strict encryption can't be used with the UDP transport protocol") @@ -240,7 +247,20 @@ func (conf *Conf) Check() error { } } + // RTMP + if conf.RTMPDisable { + conf.RTMP = false + } + + // HLS + if conf.HLSDisable { + conf.HLS = false + } + // WebRTC + if conf.WebRTCDisable { + conf.WebRTC = false + } for _, server := range conf.WebRTCICEServers { parts := strings.Split(server, ":") if len(parts) == 5 { @@ -302,6 +322,7 @@ func (conf *Conf) UnmarshalJSON(b []byte) error { conf.PPROFAddress = "127.0.0.1:9999" // RTSP + conf.RTSP = true conf.Protocols = Protocols{ Protocol(gortsplib.TransportUDP): {}, Protocol(gortsplib.TransportUDPMulticast): {}, @@ -319,10 +340,12 @@ func (conf *Conf) UnmarshalJSON(b []byte) error { conf.AuthMethods = AuthMethods{headers.AuthBasic} // RTMP + conf.RTMP = true conf.RTMPAddress = ":1935" conf.RTMPSAddress = ":1936" // HLS + conf.HLS = true conf.HLSAddress = ":8888" conf.HLSServerKey = "server.key" conf.HLSServerCert = "server.crt" @@ -334,6 +357,7 @@ func (conf *Conf) UnmarshalJSON(b []byte) error { conf.HLSAllowOrigin = "*" // WebRTC + conf.WebRTC = true conf.WebRTCAddress = ":8889" conf.WebRTCServerKey = "server.key" conf.WebRTCServerCert = "server.crt" diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 8f3e76db..d43228b6 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -126,7 +126,7 @@ func TestAPIConfigSet(t *testing.T) { hc := &http.Client{Transport: &http.Transport{}} httpRequest(t, hc, http.MethodPost, "http://localhost:9997/v2/config/set", map[string]interface{}{ - "rtmpDisable": true, + "rtmp": false, "readTimeout": "7s", "protocols": []string{"tcp"}, }, nil) @@ -135,7 +135,7 @@ func TestAPIConfigSet(t *testing.T) { var out map[string]interface{} httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) - require.Equal(t, true, out["rtmpDisable"]) + require.Equal(t, false, out["rtmp"]) require.Equal(t, "7s", out["readTimeout"]) require.Equal(t, []interface{}{"tcp"}, out["protocols"]) } diff --git a/internal/core/core.go b/internal/core/core.go index 8dbe97b7..4437923c 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -255,7 +255,7 @@ func (p *Core) createResources(initial bool) error { ) } - if !p.conf.RTSPDisable && + if p.conf.RTSP && (p.conf.Encryption == conf.EncryptionNo || p.conf.Encryption == conf.EncryptionOptional) { if p.rtspServer == nil { @@ -292,7 +292,7 @@ func (p *Core) createResources(initial bool) error { } } - if !p.conf.RTSPDisable && + if p.conf.RTSP && (p.conf.Encryption == conf.EncryptionStrict || p.conf.Encryption == conf.EncryptionOptional) { if p.rtspsServer == nil { @@ -327,7 +327,7 @@ func (p *Core) createResources(initial bool) error { } } - if !p.conf.RTMPDisable && + if p.conf.RTMP && (p.conf.RTMPEncryption == conf.EncryptionNo || p.conf.RTMPEncryption == conf.EncryptionOptional) { if p.rtmpServer == nil { @@ -353,7 +353,7 @@ func (p *Core) createResources(initial bool) error { } } - if !p.conf.RTMPDisable && + if p.conf.RTMP && (p.conf.RTMPEncryption == conf.EncryptionStrict || p.conf.RTMPEncryption == conf.EncryptionOptional) { if p.rtmpsServer == nil { @@ -379,7 +379,7 @@ func (p *Core) createResources(initial bool) error { } } - if !p.conf.HLSDisable { + if p.conf.HLS { if p.hlsManager == nil { p.hlsManager, err = newHLSManager( p.conf.HLSAddress, @@ -408,7 +408,7 @@ func (p *Core) createResources(initial bool) error { } } - if !p.conf.WebRTCDisable { + if p.conf.WebRTC { if p.webRTCManager == nil { p.webRTCManager, err = newWebRTCManager( p.conf.WebRTCAddress, @@ -512,7 +512,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { } closeRTSPServer := newConf == nil || - newConf.RTSPDisable != p.conf.RTSPDisable || + newConf.RTSP != p.conf.RTSP || newConf.Encryption != p.conf.Encryption || newConf.RTSPAddress != p.conf.RTSPAddress || !reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) || @@ -533,7 +533,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closePathManager closeRTSPSServer := newConf == nil || - newConf.RTSPDisable != p.conf.RTSPDisable || + newConf.RTSP != p.conf.RTSP || newConf.Encryption != p.conf.Encryption || newConf.RTSPSAddress != p.conf.RTSPSAddress || !reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) || @@ -550,7 +550,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closePathManager closeRTMPServer := newConf == nil || - newConf.RTMPDisable != p.conf.RTMPDisable || + newConf.RTMP != p.conf.RTMP || newConf.RTMPEncryption != p.conf.RTMPEncryption || newConf.RTMPAddress != p.conf.RTMPAddress || newConf.ReadTimeout != p.conf.ReadTimeout || @@ -563,7 +563,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closePathManager closeRTMPSServer := newConf == nil || - newConf.RTMPDisable != p.conf.RTMPDisable || + newConf.RTMP != p.conf.RTMP || newConf.RTMPEncryption != p.conf.RTMPEncryption || newConf.RTMPSAddress != p.conf.RTMPSAddress || newConf.ReadTimeout != p.conf.ReadTimeout || @@ -578,7 +578,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closePathManager closeHLSManager := newConf == nil || - newConf.HLSDisable != p.conf.HLSDisable || + newConf.HLS != p.conf.HLS || newConf.HLSAddress != p.conf.HLSAddress || newConf.HLSEncryption != p.conf.HLSEncryption || newConf.HLSServerKey != p.conf.HLSServerKey || @@ -599,7 +599,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closeMetrics closeWebRTCManager := newConf == nil || - newConf.WebRTCDisable != p.conf.WebRTCDisable || + newConf.WebRTC != p.conf.WebRTC || newConf.WebRTCAddress != p.conf.WebRTCAddress || newConf.WebRTCEncryption != p.conf.WebRTCEncryption || newConf.WebRTCServerKey != p.conf.WebRTCServerKey || diff --git a/internal/core/hls_source_test.go b/internal/core/hls_source_test.go index 9e6d8877..ce8682aa 100644 --- a/internal/core/hls_source_test.go +++ b/internal/core/hls_source_test.go @@ -114,9 +114,9 @@ func TestHLSSource(t *testing.T) { require.NoError(t, err) defer ts.close() - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " proxied:\n" + " source: http://localhost:5780/stream.m3u8\n" + diff --git a/internal/core/path_manager_test.go b/internal/core/path_manager_test.go index 10197f57..75464233 100644 --- a/internal/core/path_manager_test.go +++ b/internal/core/path_manager_test.go @@ -159,9 +159,9 @@ func main() { t.Run(ca, func(t *testing.T) { defer os.Remove(doneFile) - p1, ok := newInstance(fmt.Sprintf("rtmpDisable: yes\n"+ - "hlsDisable: yes\n"+ - "webrtcDisable: yes\n"+ + p1, ok := newInstance(fmt.Sprintf("rtmp: no\n"+ + "hls: no\n"+ + "webrtc: no\n"+ "paths:\n"+ " '~^(on)demand$':\n"+ " runOnDemand: %s\n"+ @@ -248,9 +248,9 @@ func TestPathRunOnReady(t *testing.T) { doneFile := filepath.Join(os.TempDir(), "onready_done") defer os.Remove(doneFile) - p, ok := newInstance(fmt.Sprintf("rtmpDisable: yes\n"+ - "hlsDisable: yes\n"+ - "webrtcDisable: yes\n"+ + p, ok := newInstance(fmt.Sprintf("rtmp: no\n"+ + "hls: no\n"+ + "webrtc: no\n"+ "paths:\n"+ " test:\n"+ " runOnReady: touch %s\n", diff --git a/internal/core/rtmp_server_test.go b/internal/core/rtmp_server_test.go index c782b4df..1af97005 100644 --- a/internal/core/rtmp_server_test.go +++ b/internal/core/rtmp_server_test.go @@ -62,8 +62,8 @@ func TestRTMPServer(t *testing.T) { if encrypt == "plain" { port = "1935" - conf = "rtspDisable: yes\n" + - "hlsDisable: yes\n" + conf = "rtsp: no\n" + + "hls: no\n" } else { port = "1936" @@ -75,9 +75,9 @@ func TestRTMPServer(t *testing.T) { require.NoError(t, err) defer os.Remove(serverKeyFpath) - conf = "rtspDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + conf = "rtsp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "rtmpEncryption: \"yes\"\n" + "rtmpServerCert: " + serverCertFpath + "\n" + "rtmpServerKey: " + serverKeyFpath + "\n" @@ -218,9 +218,9 @@ func TestRTMPServer(t *testing.T) { func TestRTMPServerAuthFail(t *testing.T) { t.Run("publish", func(t *testing.T) { //nolint:dupl - p, ok := newInstance("rtspDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtsp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " publishUser: testuser2\n" + @@ -323,9 +323,9 @@ func TestRTMPServerAuthFail(t *testing.T) { }) t.Run("read", func(t *testing.T) { //nolint:dupl - p, ok := newInstance("rtspDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtsp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " readUser: testuser2\n" + diff --git a/internal/core/rtsp_server_test.go b/internal/core/rtsp_server_test.go index 744a9d02..1651198e 100644 --- a/internal/core/rtsp_server_test.go +++ b/internal/core/rtsp_server_test.go @@ -55,9 +55,9 @@ func TestRTSPServer(t *testing.T) { " all:\n" case "internal": - conf = "rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + conf = "rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " publishUser: testpublisher\n" + @@ -121,9 +121,9 @@ func TestRTSPServer(t *testing.T) { func TestRTSPServerAuthHashed(t *testing.T) { p, ok := newInstance( - "rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + "rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " publishUser: sha256:rl3rgi4NcZkpAEcacZnQ2VuOfJ0FxAqCRaKB/SwdZoQ=\n" + @@ -165,9 +165,9 @@ func TestRTSPServerAuthFail(t *testing.T) { }, } { t.Run("publish_"+ca.name, func(t *testing.T) { - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " publishUser: testuser\n" + @@ -209,9 +209,9 @@ func TestRTSPServerAuthFail(t *testing.T) { }, } { t.Run("read_"+ca.name, func(t *testing.T) { - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " readUser: testuser\n" + @@ -234,9 +234,9 @@ func TestRTSPServerAuthFail(t *testing.T) { } t.Run("ip", func(t *testing.T) { - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " all:\n" + " publishIPs: [128.0.0.1/32]\n") @@ -282,7 +282,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) { "disabled", } { t.Run(ca, func(t *testing.T) { - conf := "rtmpDisable: yes\n" + + conf := "rtmp: no\n" + "paths:\n" + " all:\n" @@ -390,9 +390,9 @@ func TestRTSPServerFallback(t *testing.T) { return "/path2" }() - p1, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p1, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " path1:\n" + " fallback: " + val + "\n" + diff --git a/internal/core/rtsp_source_test.go b/internal/core/rtsp_source_test.go index fc7f0c3d..040ca273 100644 --- a/internal/core/rtsp_source_test.go +++ b/internal/core/rtsp_source_test.go @@ -215,9 +215,9 @@ func TestRTSPSourceNoPassword(t *testing.T) { defer s.Wait() defer s.Close() - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " proxied:\n" + " source: rtsp://testuser:@127.0.0.1:8555/teststream\n" + @@ -285,9 +285,9 @@ func TestRTSPSourceRange(t *testing.T) { addConf += " rtspRangeType: smpte\n" + " rtspRangeStart: 130s\n" } - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " proxied:\n" + " source: rtsp://testuser:@127.0.0.1:8555/teststream\n" + addConf) diff --git a/internal/highleveltests/rtsp_server_test.go b/internal/highleveltests/rtsp_server_test.go index 3fd97833..69f105e5 100644 --- a/internal/highleveltests/rtsp_server_test.go +++ b/internal/highleveltests/rtsp_server_test.go @@ -42,9 +42,9 @@ func TestRTSPServerPublishRead(t *testing.T) { proto = "rtsp" port = "8554" - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "readTimeout: 20s\n" + "paths:\n" + " all:\n") @@ -62,9 +62,9 @@ func TestRTSPServerPublishRead(t *testing.T) { require.NoError(t, err) defer os.Remove(serverKeyFpath) - p, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "readTimeout: 20s\n" + "protocols: [tcp]\n" + "encryption: \"yes\"\n" + @@ -199,9 +199,9 @@ func TestRTSPServerPublishRead(t *testing.T) { } func TestRTSPServerRedirect(t *testing.T) { - p1, ok := newInstance("rtmpDisable: yes\n" + - "hlsDisable: yes\n" + - "webrtcDisable: yes\n" + + p1, ok := newInstance("rtmp: no\n" + + "hls: no\n" + + "webrtc: no\n" + "paths:\n" + " path1:\n" + " source: redirect\n" + diff --git a/mediamtx.yml b/mediamtx.yml index c0788258..3c6ac971 100644 --- a/mediamtx.yml +++ b/mediamtx.yml @@ -64,8 +64,8 @@ runOnConnectRestart: no ############################################### # RTSP parameters -# Disable support for the RTSP protocol. -rtspDisable: no +# Enable support for the RTSP protocol. +rtsp: yes # List of enabled RTSP transport protocols. # UDP is the most performant, but doesn't work when there's a NAT/firewall between # server and clients, and doesn't support encryption. @@ -104,8 +104,8 @@ authMethods: [basic] ############################################### # RTMP parameters -# Disable support for the RTMP protocol. -rtmpDisable: no +# Enable support for the RTMP protocol. +rtmp: yes # Address of the RTMP listener. This is needed only when encryption is "no" or "optional". rtmpAddress: :1935 # Encrypt connections with TLS (RTMPS). @@ -124,8 +124,8 @@ rtmpServerCert: server.crt ############################################### # HLS parameters -# Disable support for the HLS protocol. -hlsDisable: no +# Enable support for the HLS protocol. +hls: yes # Address of the HLS listener. hlsAddress: :8888 # Enable TLS/HTTPS on the HLS server. @@ -180,8 +180,8 @@ hlsDirectory: '' ############################################### # WebRTC parameters -# Disable support for the WebRTC protocol. -webrtcDisable: no +# Enable support for the WebRTC protocol. +webrtc: yes # Address of the WebRTC listener. webrtcAddress: :8889 # Enable TLS/HTTPS on the WebRTC server.