diff --git a/README.md b/README.md index fdcd35e6321..ad412e9a525 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ The `--network=host` flag is mandatory for RTSP to work, since Docker can change ``` docker run --rm -it \ --e MTX_PROTOCOLS=tcp \ +-e MTX_RTSPTRANSPORTS=tcp \ -e MTX_WEBRTCADDITIONALHOSTS=192.168.x.x \ -p 8554:8554 \ -p 1935:1935 \ @@ -1264,7 +1264,7 @@ There are 3 ways to change the configuration: Parameters that have array as value can be overridden by setting a comma-separated list. For example: ``` - MTX_PROTOCOLS="tcp,udp" + MTX_RTSPTRANSPORTS="tcp,udp" ``` Parameters in maps can be overridden by using underscores, in the following way: @@ -2266,13 +2266,13 @@ openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650 ``` -Edit `mediamtx.yml`, and set the `protocols`, `encryption`, `serverKey` and serverCert parameters: +Edit `mediamtx.yml` and set the `rtspTransports`, `encryption`, `serverKey` and serverCert parameters: ```yml -protocols: [tcp] -encryption: optional -serverKey: server.key -serverCert: server.crt +rtspTransports: [tcp] +rtspEncryption: optional +rtspServerKey: server.key +rtspServerCert: server.crt ``` Streams can be published and read with the `rtsps` scheme and the `8322` port: @@ -2294,7 +2294,7 @@ In some scenarios, when publishing or reading from the server with RTSP, frames * The stream throughput is too big and the stream can't be transmitted correctly with the UDP transport protocol. UDP is more performant, faster and more efficient than TCP, but doesn't have a retransmission mechanism, that is needed in case of streams that need a large bandwidth. A solution consists in switching to TCP: ```yml - protocols: [tcp] + rtspTransports: [tcp] ``` In case the source is a camera: @@ -2319,7 +2319,7 @@ openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650 ``` -Edit mediamtx.yml, and set the `rtmpEncryption`, `rtmpServerKey` and `rtmpServerCert` parameters: +Edit mediamtx.yml and set the `rtmpEncryption`, `rtmpServerKey` and `rtmpServerCert` parameters: ```yml rtmpEncryption: optional diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index ad9720c7895..5d25d6fcdfa 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -165,11 +165,11 @@ components: # RTSP server rtsp: type: boolean - protocols: + rtspTransports: type: array items: type: string - encryption: + rtspEncryption: type: string rtspAddress: type: string @@ -185,9 +185,9 @@ components: type: integer multicastRTCPPort: type: integer - serverKey: + rtspServerKey: type: string - serverCert: + rtspServerCert: type: string rtspAuthMethods: type: array diff --git a/internal/conf/conf.go b/internal/conf/conf.go index cdd91ca0fe5..b7b8f1b80db 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -218,8 +218,10 @@ type Conf struct { // RTSP server RTSP bool `json:"rtsp"` RTSPDisable *bool `json:"rtspDisable,omitempty"` // deprecated - Protocols Protocols `json:"protocols"` - Encryption Encryption `json:"encryption"` + Protocols *RTSPTransports `json:"protocols,omitempty"` // deprecated + RTSPTransports RTSPTransports `json:"rtspTransports"` + Encryption *Encryption `json:"encryption,omitempty"` // deprecated + RTSPEncryption Encryption `json:"rtspEncryption"` RTSPAddress string `json:"rtspAddress"` RTSPSAddress string `json:"rtspsAddress"` RTPAddress string `json:"rtpAddress"` @@ -227,8 +229,10 @@ type Conf struct { MulticastIPRange string `json:"multicastIPRange"` MulticastRTPPort int `json:"multicastRTPPort"` MulticastRTCPPort int `json:"multicastRTCPPort"` - ServerKey string `json:"serverKey"` - ServerCert string `json:"serverCert"` + ServerKey *string `json:"serverKey,omitempty"` + ServerCert *string `json:"serverCert,omitempty"` + RTSPServerKey string `json:"rtspServerKey"` + RTSPServerCert string `json:"rtspServerCert"` AuthMethods *RTSPAuthMethods `json:"authMethods,omitempty"` // deprecated RTSPAuthMethods RTSPAuthMethods `json:"rtspAuthMethods"` @@ -352,10 +356,10 @@ func (conf *Conf) setDefaults() { // RTSP server conf.RTSP = true - conf.Protocols = Protocols{ - Protocol(gortsplib.TransportUDP): {}, - Protocol(gortsplib.TransportUDPMulticast): {}, - Protocol(gortsplib.TransportTCP): {}, + conf.RTSPTransports = RTSPTransports{ + gortsplib.TransportUDP: {}, + gortsplib.TransportUDPMulticast: {}, + gortsplib.TransportTCP: {}, } conf.RTSPAddress = ":8554" conf.RTSPSAddress = ":8322" @@ -364,8 +368,8 @@ func (conf *Conf) setDefaults() { conf.MulticastIPRange = "224.1.0.0/16" conf.MulticastRTPPort = 8002 conf.MulticastRTCPPort = 8003 - conf.ServerKey = "server.key" - conf.ServerCert = "server.crt" + conf.RTSPServerKey = "server.key" + conf.RTSPServerCert = "server.crt" conf.RTSPAuthMethods = RTSPAuthMethods{auth.ValidateMethodBasic} // RTMP server @@ -581,12 +585,18 @@ func (conf *Conf) Validate() error { if conf.RTSPDisable != nil { conf.RTSP = !*conf.RTSPDisable } - 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") + if conf.Protocols != nil { + conf.RTSPTransports = *conf.Protocols + } + if conf.Encryption != nil { + conf.RTSPEncryption = *conf.Encryption + } + if conf.RTSPEncryption == EncryptionStrict { + if _, ok := conf.RTSPTransports[gortsplib.TransportUDP]; ok { + return fmt.Errorf("strict encryption cannot be used with the UDP transport protocol") } - if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDPMulticast)]; ok { - return fmt.Errorf("strict encryption can't be used with the UDP-multicast transport protocol") + if _, ok := conf.RTSPTransports[gortsplib.TransportUDPMulticast]; ok { + return fmt.Errorf("strict encryption cannot be used with the UDP-multicast transport protocol") } } if conf.AuthMethods != nil { @@ -602,6 +612,12 @@ func (conf *Conf) Validate() error { } } } + if conf.ServerCert != nil { + conf.RTSPServerCert = *conf.ServerCert + } + if conf.ServerKey != nil { + conf.RTSPServerKey = *conf.ServerKey + } // RTMP diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index f7b8c9e93e6..91eb4222f7d 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -134,7 +134,7 @@ func TestConfFromFileAndEnv(t *testing.T) { require.NoError(t, err) require.Equal(t, tmpf, confPath) - require.Equal(t, Protocols{Protocol(gortsplib.TransportTCP): {}}, conf.Protocols) + require.Equal(t, RTSPTransports{gortsplib.TransportTCP: {}}, conf.RTSPTransports) require.Equal(t, false, conf.RTMP) pa, ok := conf.Paths["cam1"] @@ -292,15 +292,15 @@ func TestConfErrors(t *testing.T) { }, { "invalid strict encryption 1", - "encryption: strict\n" + - "protocols: [udp]\n", - "strict encryption can't be used with the UDP transport protocol", + "rtspEncryption: strict\n" + + "rtspTransports: [udp]\n", + "strict encryption cannot be used with the UDP transport protocol", }, { "invalid strict encryption 2", - "encryption: strict\n" + - "protocols: [multicast]\n", - "strict encryption can't be used with the UDP-multicast transport protocol", + "rtspEncryption: strict\n" + + "rtspTransports: [multicast]\n", + "strict encryption cannot be used with the UDP-multicast transport protocol", }, { "invalid ICE server", diff --git a/internal/conf/encryption.go b/internal/conf/encryption.go index 039fb0090fb..c2728c95f2b 100644 --- a/internal/conf/encryption.go +++ b/internal/conf/encryption.go @@ -5,7 +5,7 @@ import ( "fmt" ) -// Encryption is the encryption parameter. +// Encryption is the rtspEncryption / rtmpEncryption parameter. type Encryption int // values. diff --git a/internal/conf/rtsp_transport.go b/internal/conf/rtsp_transport.go index 6cc6b2232ba..f39cb4e293a 100644 --- a/internal/conf/rtsp_transport.go +++ b/internal/conf/rtsp_transport.go @@ -58,7 +58,7 @@ func (d *RTSPTransport) UnmarshalJSON(b []byte) error { d.Transport = nil default: - return fmt.Errorf("invalid protocol '%s'", in) + return fmt.Errorf("invalid transport '%s'", in) } return nil diff --git a/internal/conf/protocol.go b/internal/conf/rtsp_transports.go similarity index 53% rename from internal/conf/protocol.go rename to internal/conf/rtsp_transports.go index 747130619e1..1a043b5ca84 100644 --- a/internal/conf/protocol.go +++ b/internal/conf/rtsp_transports.go @@ -9,14 +9,11 @@ import ( "github.com/bluenviron/gortsplib/v4" ) -// Protocol is a RTSP transport. -type Protocol gortsplib.Transport - -// Protocols is the protocols parameter. -type Protocols map[Protocol]struct{} +// RTSPTransports is the rtspTransports parameter. +type RTSPTransports map[gortsplib.Transport]struct{} // MarshalJSON implements json.Marshaler. -func (d Protocols) MarshalJSON() ([]byte, error) { +func (d RTSPTransports) MarshalJSON() ([]byte, error) { out := make([]string, len(d)) i := 0 @@ -24,10 +21,10 @@ func (d Protocols) MarshalJSON() ([]byte, error) { var v string switch p { - case Protocol(gortsplib.TransportUDP): + case gortsplib.TransportUDP: v = "udp" - case Protocol(gortsplib.TransportUDPMulticast): + case gortsplib.TransportUDPMulticast: v = "multicast" default: @@ -44,27 +41,27 @@ func (d Protocols) MarshalJSON() ([]byte, error) { } // UnmarshalJSON implements json.Unmarshaler. -func (d *Protocols) UnmarshalJSON(b []byte) error { +func (d *RTSPTransports) UnmarshalJSON(b []byte) error { var in []string if err := json.Unmarshal(b, &in); err != nil { return err } - *d = make(Protocols) + *d = make(RTSPTransports) for _, proto := range in { switch proto { case "udp": - (*d)[Protocol(gortsplib.TransportUDP)] = struct{}{} + (*d)[gortsplib.TransportUDP] = struct{}{} case "multicast": - (*d)[Protocol(gortsplib.TransportUDPMulticast)] = struct{}{} + (*d)[gortsplib.TransportUDPMulticast] = struct{}{} case "tcp": - (*d)[Protocol(gortsplib.TransportTCP)] = struct{}{} + (*d)[gortsplib.TransportTCP] = struct{}{} default: - return fmt.Errorf("invalid protocol: %s", proto) + return fmt.Errorf("invalid transport: %s", proto) } } @@ -72,7 +69,7 @@ func (d *Protocols) UnmarshalJSON(b []byte) error { } // UnmarshalEnv implements env.Unmarshaler. -func (d *Protocols) UnmarshalEnv(_ string, v string) error { +func (d *RTSPTransports) UnmarshalEnv(_ string, v string) error { byts, _ := json.Marshal(strings.Split(v, ",")) return d.UnmarshalJSON(byts) } diff --git a/internal/core/api_test.go b/internal/core/api_test.go index a7d21434ce6..f8235ec753d 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -151,9 +151,9 @@ func TestAPIPathsList(t *testing.T) { defer os.Remove(serverKeyFpath) p, ok := newInstance("api: yes\n" + - "encryption: optional\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + + "rtspEncryption: optional\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" + "paths:\n" + " mypath:\n") require.Equal(t, true, ok) @@ -367,10 +367,10 @@ func TestAPIProtocolListGet(t *testing.T) { switch ca { case "rtsps conns", "rtsps sessions": - conf += "protocols: [tcp]\n" + - "encryption: strict\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + conf += "rtspTransports: [tcp]\n" + + "rtspEncryption: strict\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" case "rtmps": conf += "rtmpEncryption: strict\n" + @@ -860,10 +860,10 @@ func TestAPIProtocolGetNotFound(t *testing.T) { switch ca { case "rtsps conns", "rtsps sessions": - conf += "protocols: [tcp]\n" + - "encryption: strict\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + conf += "rtspTransports: [tcp]\n" + + "rtspEncryption: strict\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" case "rtmps": conf += "rtmpEncryption: strict\n" + @@ -957,10 +957,10 @@ func TestAPIProtocolKick(t *testing.T) { conf := "api: yes\n" if ca == "rtsps" { - conf += "protocols: [tcp]\n" + - "encryption: strict\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + conf += "rtspTransports: [tcp]\n" + + "rtspEncryption: strict\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" } conf += "paths:\n" + @@ -1114,10 +1114,10 @@ func TestAPIProtocolKickNotFound(t *testing.T) { conf := "api: yes\n" if ca == "rtsps" { - conf += "protocols: [tcp]\n" + - "encryption: strict\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + conf += "rtspTransports: [tcp]\n" + + "rtspEncryption: strict\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" } conf += "paths:\n" + diff --git a/internal/core/core.go b/internal/core/core.go index 4255d8dd9dc..b7389450d7e 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -354,11 +354,11 @@ func (p *Core) createResources(initial bool) error { } if p.conf.RTSP && - (p.conf.Encryption == conf.EncryptionNo || - p.conf.Encryption == conf.EncryptionOptional) && + (p.conf.RTSPEncryption == conf.EncryptionNo || + p.conf.RTSPEncryption == conf.EncryptionOptional) && p.rtspServer == nil { - _, useUDP := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDP)] - _, useMulticast := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDPMulticast)] + _, useUDP := p.conf.RTSPTransports[gortsplib.TransportUDP] + _, useMulticast := p.conf.RTSPTransports[gortsplib.TransportUDPMulticast] i := &rtsp.Server{ Address: p.conf.RTSPAddress, @@ -377,7 +377,7 @@ func (p *Core) createResources(initial bool) error { ServerCert: "", ServerKey: "", RTSPAddress: p.conf.RTSPAddress, - Protocols: p.conf.Protocols, + Transports: p.conf.RTSPTransports, RunOnConnect: p.conf.RunOnConnect, RunOnConnectRestart: p.conf.RunOnConnectRestart, RunOnDisconnect: p.conf.RunOnDisconnect, @@ -397,8 +397,8 @@ func (p *Core) createResources(initial bool) error { } if p.conf.RTSP && - (p.conf.Encryption == conf.EncryptionStrict || - p.conf.Encryption == conf.EncryptionOptional) && + (p.conf.RTSPEncryption == conf.EncryptionStrict || + p.conf.RTSPEncryption == conf.EncryptionOptional) && p.rtspsServer == nil { i := &rtsp.Server{ Address: p.conf.RTSPSAddress, @@ -414,10 +414,10 @@ func (p *Core) createResources(initial bool) error { MulticastRTPPort: 0, MulticastRTCPPort: 0, IsTLS: true, - ServerCert: p.conf.ServerCert, - ServerKey: p.conf.ServerKey, + ServerCert: p.conf.RTSPServerCert, + ServerKey: p.conf.RTSPServerKey, RTSPAddress: p.conf.RTSPAddress, - Protocols: p.conf.Protocols, + Transports: p.conf.RTSPTransports, RunOnConnect: p.conf.RunOnConnect, RunOnConnectRestart: p.conf.RunOnConnectRestart, RunOnDisconnect: p.conf.RunOnDisconnect, @@ -708,20 +708,19 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closeRTSPServer := newConf == nil || newConf.RTSP != p.conf.RTSP || - newConf.Encryption != p.conf.Encryption || + newConf.RTSPEncryption != p.conf.RTSPEncryption || newConf.RTSPAddress != p.conf.RTSPAddress || !reflect.DeepEqual(newConf.RTSPAuthMethods, p.conf.RTSPAuthMethods) || newConf.ReadTimeout != p.conf.ReadTimeout || newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteQueueSize != p.conf.WriteQueueSize || - !reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) || newConf.RTPAddress != p.conf.RTPAddress || newConf.RTCPAddress != p.conf.RTCPAddress || newConf.MulticastIPRange != p.conf.MulticastIPRange || newConf.MulticastRTPPort != p.conf.MulticastRTPPort || newConf.MulticastRTCPPort != p.conf.MulticastRTCPPort || newConf.RTSPAddress != p.conf.RTSPAddress || - !reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) || + !reflect.DeepEqual(newConf.RTSPTransports, p.conf.RTSPTransports) || newConf.RunOnConnect != p.conf.RunOnConnect || newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart || newConf.RunOnDisconnect != p.conf.RunOnDisconnect || @@ -731,16 +730,16 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { closeRTSPSServer := newConf == nil || newConf.RTSP != p.conf.RTSP || - newConf.Encryption != p.conf.Encryption || + newConf.RTSPEncryption != p.conf.RTSPEncryption || newConf.RTSPSAddress != p.conf.RTSPSAddress || !reflect.DeepEqual(newConf.RTSPAuthMethods, p.conf.RTSPAuthMethods) || newConf.ReadTimeout != p.conf.ReadTimeout || newConf.WriteTimeout != p.conf.WriteTimeout || newConf.WriteQueueSize != p.conf.WriteQueueSize || - newConf.ServerCert != p.conf.ServerCert || - newConf.ServerKey != p.conf.ServerKey || + newConf.RTSPServerCert != p.conf.RTSPServerCert || + newConf.RTSPServerKey != p.conf.RTSPServerKey || newConf.RTSPAddress != p.conf.RTSPAddress || - !reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) || + !reflect.DeepEqual(newConf.RTSPTransports, p.conf.RTSPTransports) || newConf.RunOnConnect != p.conf.RunOnConnect || newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart || newConf.RunOnDisconnect != p.conf.RunOnDisconnect || diff --git a/internal/core/core_test.go b/internal/core/core_test.go index 7123d287442..15c061ae626 100644 --- a/internal/core/core_test.go +++ b/internal/core/core_test.go @@ -57,7 +57,7 @@ func TestCoreErrors(t *testing.T) { }, { "rtsps", - "encryption: strict\n" + + "rtspEncryption: strict\n" + "rtspAddress: invalid\n", }, { diff --git a/internal/core/metrics_test.go b/internal/core/metrics_test.go index b061e52209a..db8da285c35 100644 --- a/internal/core/metrics_test.go +++ b/internal/core/metrics_test.go @@ -56,9 +56,9 @@ func TestMetrics(t *testing.T) { "metrics: yes\n" + "webrtcServerCert: " + serverCertFpath + "\n" + "webrtcServerKey: " + serverKeyFpath + "\n" + - "encryption: optional\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + + "rtspEncryption: optional\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" + "rtmpEncryption: optional\n" + "rtmpServerCert: " + serverCertFpath + "\n" + "rtmpServerKey: " + serverKeyFpath + "\n" + diff --git a/internal/core/path_test.go b/internal/core/path_test.go index bd98bbd2b4b..bc4b2b6882f 100644 --- a/internal/core/path_test.go +++ b/internal/core/path_test.go @@ -170,9 +170,9 @@ func TestPathRunOnConnect(t *testing.T) { func() { p, ok := newInstance(fmt.Sprintf( - "encryption: optional\n"+ - "serverCert: "+serverCertFpath+"\n"+ - "serverKey: "+serverKeyFpath+"\n"+ + "rtspEncryption: optional\n"+ + "rtspServerCert: "+serverCertFpath+"\n"+ + "rtspServerKey: "+serverKeyFpath+"\n"+ "rtmpEncryption: optional\n"+ "rtmpServerCert: "+serverCertFpath+"\n"+ "rtmpServerKey: "+serverKeyFpath+"\n"+ @@ -338,9 +338,9 @@ func TestPathRunOnRead(t *testing.T) { func() { p, ok := newInstance(fmt.Sprintf( - "encryption: optional\n"+ - "serverCert: "+serverCertFpath+"\n"+ - "serverKey: "+serverKeyFpath+"\n"+ + "rtspEncryption: optional\n"+ + "rtspServerCert: "+serverCertFpath+"\n"+ + "rtspServerKey: "+serverKeyFpath+"\n"+ "rtmpEncryption: optional\n"+ "rtmpServerCert: "+serverCertFpath+"\n"+ "rtmpServerKey: "+serverKeyFpath+"\n"+ diff --git a/internal/servers/rtsp/server.go b/internal/servers/rtsp/server.go index 0c22dfebf37..d8b81558ab7 100644 --- a/internal/servers/rtsp/server.go +++ b/internal/servers/rtsp/server.go @@ -75,7 +75,7 @@ type Server struct { ServerCert string ServerKey string RTSPAddress string - Protocols map[conf.Protocol]struct{} + Transports conf.RTSPTransports RunOnConnect string RunOnConnectRestart bool RunOnDisconnect string @@ -235,7 +235,7 @@ func (s *Server) OnResponse(sc *gortsplib.ServerConn, res *base.Response) { func (s *Server) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) { se := &session{ isTLS: s.IsTLS, - protocols: s.Protocols, + transports: s.Transports, rsession: ctx.Session, rconn: ctx.Conn, rserver: s.srv, diff --git a/internal/servers/rtsp/server_test.go b/internal/servers/rtsp/server_test.go index a22c089db87..8348beeb2ae 100644 --- a/internal/servers/rtsp/server_test.go +++ b/internal/servers/rtsp/server_test.go @@ -108,7 +108,7 @@ func TestServerPublish(t *testing.T) { ServerCert: "", ServerKey: "", RTSPAddress: "", - Protocols: map[conf.Protocol]struct{}{conf.Protocol(gortsplib.TransportTCP): {}}, + Transports: conf.RTSPTransports{gortsplib.TransportTCP: {}}, RunOnConnect: "", RunOnConnectRestart: false, RunOnDisconnect: "", @@ -202,7 +202,7 @@ func TestServerRead(t *testing.T) { ServerCert: "", ServerKey: "", RTSPAddress: "", - Protocols: map[conf.Protocol]struct{}{conf.Protocol(gortsplib.TransportTCP): {}}, + Transports: conf.RTSPTransports{gortsplib.TransportTCP: {}}, RunOnConnect: "", RunOnConnectRestart: false, RunOnDisconnect: "", diff --git a/internal/servers/rtsp/session.go b/internal/servers/rtsp/session.go index eb9a49ee6c5..0465dcb8f7b 100644 --- a/internal/servers/rtsp/session.go +++ b/internal/servers/rtsp/session.go @@ -25,7 +25,7 @@ import ( type session struct { isTLS bool - protocols map[conf.Protocol]struct{} + transports conf.RTSPTransports rsession *gortsplib.ServerSession rconn *gortsplib.ServerConn rserver *gortsplib.Server @@ -163,7 +163,7 @@ func (s *session) onSetup(c *conn, ctx *gortsplib.ServerHandlerOnSetupCtx, // we have only to handle the case in which the transport protocol is TCP // and it is disabled. if ctx.Transport == gortsplib.TransportTCP { - if _, ok := s.protocols[conf.Protocol(gortsplib.TransportTCP)]; !ok { + if _, ok := s.transports[gortsplib.TransportTCP]; !ok { return &base.Response{ StatusCode: base.StatusUnsupportedTransport, }, nil, nil diff --git a/internal/testhighlevel/rtsp_server_test.go b/internal/testhighlevel/rtsp_server_test.go index e62bf404c11..a6bb8e5e64a 100644 --- a/internal/testhighlevel/rtsp_server_test.go +++ b/internal/testhighlevel/rtsp_server_test.go @@ -66,10 +66,10 @@ func TestRTSPServerPublishRead(t *testing.T) { "hls: no\n" + "webrtc: no\n" + "readTimeout: 20s\n" + - "protocols: [tcp]\n" + - "encryption: \"yes\"\n" + - "serverCert: " + serverCertFpath + "\n" + - "serverKey: " + serverKeyFpath + "\n" + + "rtspTransports: [tcp]\n" + + "rtspEncryption: \"yes\"\n" + + "rtspServerCert: " + serverCertFpath + "\n" + + "rtspServerKey: " + serverKeyFpath + "\n" + "paths:\n" + " all_others:\n") require.Equal(t, true, ok) diff --git a/mediamtx.yml b/mediamtx.yml index 2546d233ada..33c14189353 100644 --- a/mediamtx.yml +++ b/mediamtx.yml @@ -227,10 +227,10 @@ rtsp: yes # UDP-multicast allows to save bandwidth when clients are all in the same LAN. # TCP is the most versatile, and does support encryption. # The handshake is always performed with TCP. -protocols: [udp, multicast, tcp] +rtspTransports: [udp, multicast, tcp] # Encrypt handshakes and TCP streams with TLS (RTSPS). # Available values are "no", "strict", "optional". -encryption: "no" +rtspEncryption: "no" # Address of the TCP/RTSP listener. This is needed only when encryption is "no" or "optional". rtspAddress: :8554 # Address of the TCP/TLS/RTSPS listener. This is needed only when encryption is "strict" or "optional". @@ -249,9 +249,9 @@ multicastRTCPPort: 8003 # This can be generated with: # openssl genrsa -out server.key 2048 # openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650 -serverKey: server.key +rtspServerKey: server.key # Path to the server certificate. This is needed only when encryption is "strict" or "optional". -serverCert: server.crt +rtspServerCert: server.crt # Authentication methods. Available are "basic" and "digest". # "digest" doesn't provide any additional security and is available for compatibility only. rtspAuthMethods: [basic]