mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
move UDP support into gortsplib
This commit is contained in:
parent
39882ef654
commit
9fb844331e
12 changed files with 195 additions and 400 deletions
104
main.go
104
main.go
|
|
@ -16,9 +16,9 @@ import (
|
|||
"github.com/aler9/rtsp-simple-server/internal/metrics"
|
||||
"github.com/aler9/rtsp-simple-server/internal/pathman"
|
||||
"github.com/aler9/rtsp-simple-server/internal/pprof"
|
||||
"github.com/aler9/rtsp-simple-server/internal/servertcp"
|
||||
"github.com/aler9/rtsp-simple-server/internal/serverplain"
|
||||
"github.com/aler9/rtsp-simple-server/internal/servertls"
|
||||
"github.com/aler9/rtsp-simple-server/internal/serverudp"
|
||||
"github.com/aler9/rtsp-simple-server/internal/serverudpl"
|
||||
"github.com/aler9/rtsp-simple-server/internal/stats"
|
||||
)
|
||||
|
||||
|
|
@ -32,9 +32,9 @@ type program struct {
|
|||
logger *logger.Logger
|
||||
metrics *metrics.Metrics
|
||||
pprof *pprof.Pprof
|
||||
serverUDPRtp *serverudp.Server
|
||||
serverUDPRtcp *serverudp.Server
|
||||
serverTCP *servertcp.Server
|
||||
serverUDPRTP *gortsplib.ServerUDPListener
|
||||
serverUDPRTCP *gortsplib.ServerUDPListener
|
||||
serverTCP *serverplain.Server
|
||||
serverTLS *servertls.Server
|
||||
pathMan *pathman.PathManager
|
||||
clientMan *clientman.ClientManager
|
||||
|
|
@ -146,7 +146,9 @@ func (p *program) createResources(initial bool) error {
|
|||
}
|
||||
|
||||
if p.logger == nil {
|
||||
p.logger, err = logger.New(p.conf.LogLevelParsed, p.conf.LogDestinationsParsed,
|
||||
p.logger, err = logger.New(
|
||||
p.conf.LogLevelParsed,
|
||||
p.conf.LogDestinationsParsed,
|
||||
p.conf.LogFile)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -179,17 +181,21 @@ func (p *program) createResources(initial bool) error {
|
|||
}
|
||||
|
||||
if _, ok := p.conf.ProtocolsParsed[gortsplib.StreamProtocolUDP]; ok {
|
||||
if p.serverUDPRtp == nil {
|
||||
p.serverUDPRtp, err = serverudp.New(p.conf.WriteTimeout,
|
||||
p.conf.RtpPort, gortsplib.StreamTypeRtp, p)
|
||||
if p.serverUDPRTP == nil {
|
||||
p.serverUDPRTP, err = serverudpl.New(
|
||||
p.conf.RTPPort,
|
||||
gortsplib.StreamTypeRTP,
|
||||
p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if p.serverUDPRtcp == nil {
|
||||
p.serverUDPRtcp, err = serverudp.New(p.conf.WriteTimeout,
|
||||
p.conf.RtcpPort, gortsplib.StreamTypeRtcp, p)
|
||||
if p.serverUDPRTCP == nil {
|
||||
p.serverUDPRTCP, err = serverudpl.New(
|
||||
p.conf.RTCPPort,
|
||||
gortsplib.StreamTypeRTCP,
|
||||
p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -198,8 +204,13 @@ func (p *program) createResources(initial bool) error {
|
|||
|
||||
if p.serverTCP == nil {
|
||||
if p.conf.EncryptionParsed == conf.EncryptionNo || p.conf.EncryptionParsed == conf.EncryptionOptional {
|
||||
p.serverTCP, err = servertcp.New(p.conf.RtspPort, p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout, p)
|
||||
p.serverTCP, err = serverplain.New(
|
||||
p.conf.RtspPort,
|
||||
p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout,
|
||||
p.serverUDPRTP,
|
||||
p.serverUDPRTCP,
|
||||
p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -208,8 +219,13 @@ func (p *program) createResources(initial bool) error {
|
|||
|
||||
if p.serverTLS == nil {
|
||||
if p.conf.EncryptionParsed == conf.EncryptionStrict || p.conf.EncryptionParsed == conf.EncryptionOptional {
|
||||
p.serverTLS, err = servertls.New(p.conf.RtspsPort, p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout, p.conf.ServerKey, p.conf.ServerCert, p)
|
||||
p.serverTLS, err = servertls.New(
|
||||
p.conf.RtspsPort,
|
||||
p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout,
|
||||
p.conf.ServerKey,
|
||||
p.conf.ServerCert,
|
||||
p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -217,16 +233,28 @@ func (p *program) createResources(initial bool) error {
|
|||
}
|
||||
|
||||
if p.pathMan == nil {
|
||||
p.pathMan = pathman.New(p.conf.RtspPort, p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout, p.conf.AuthMethodsParsed, p.conf.Paths,
|
||||
p.stats, p)
|
||||
p.pathMan = pathman.New(
|
||||
p.conf.RtspPort,
|
||||
p.conf.ReadTimeout,
|
||||
p.conf.WriteTimeout,
|
||||
p.conf.AuthMethodsParsed,
|
||||
p.conf.Paths,
|
||||
p.stats,
|
||||
p)
|
||||
}
|
||||
|
||||
if p.clientMan == nil {
|
||||
p.clientMan = clientman.New(p.conf.RtspPort, p.conf.ReadTimeout,
|
||||
p.conf.RunOnConnect, p.conf.RunOnConnectRestart,
|
||||
p.conf.ProtocolsParsed, p.stats, p.serverUDPRtp, p.serverUDPRtcp,
|
||||
p.pathMan, p.serverTCP, p.serverTLS, p)
|
||||
p.clientMan = clientman.New(
|
||||
p.conf.RtspPort,
|
||||
p.conf.ReadTimeout,
|
||||
p.conf.RunOnConnect,
|
||||
p.conf.RunOnConnectRestart,
|
||||
p.conf.ProtocolsParsed,
|
||||
p.stats,
|
||||
p.pathMan,
|
||||
p.serverTCP,
|
||||
p.serverTLS,
|
||||
p)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -252,20 +280,20 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||
closePprof = true
|
||||
}
|
||||
|
||||
closeServerUDPRtp := false
|
||||
closeServerUDPRTP := false
|
||||
if newConf == nil ||
|
||||
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
||||
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
||||
newConf.RtpPort != p.conf.RtpPort {
|
||||
closeServerUDPRtp = true
|
||||
newConf.RTPPort != p.conf.RTPPort {
|
||||
closeServerUDPRTP = true
|
||||
}
|
||||
|
||||
closeServerUDPRtcp := false
|
||||
closeServerUDPRTCP := false
|
||||
if newConf == nil ||
|
||||
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
||||
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
||||
newConf.RtcpPort != p.conf.RtcpPort {
|
||||
closeServerUDPRtcp = true
|
||||
newConf.RTCPPort != p.conf.RTCPPort {
|
||||
closeServerUDPRTCP = true
|
||||
}
|
||||
|
||||
closeServerTCP := false
|
||||
|
|
@ -273,7 +301,9 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
|
||||
newConf.RtspPort != p.conf.RtspPort ||
|
||||
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
||||
newConf.WriteTimeout != p.conf.WriteTimeout {
|
||||
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
||||
closeServerUDPRTP ||
|
||||
closeServerUDPRTCP {
|
||||
closeServerTCP = true
|
||||
}
|
||||
|
||||
|
|
@ -299,8 +329,6 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||
|
||||
closeClientMan := false
|
||||
if newConf == nil ||
|
||||
closeServerUDPRtp ||
|
||||
closeServerUDPRtcp ||
|
||||
closeServerTCP ||
|
||||
closeServerTLS ||
|
||||
closePathMan ||
|
||||
|
|
@ -337,14 +365,14 @@ func (p *program) closeResources(newConf *conf.Conf) {
|
|||
p.serverTCP = nil
|
||||
}
|
||||
|
||||
if closeServerUDPRtcp && p.serverUDPRtcp != nil {
|
||||
p.serverUDPRtcp.Close()
|
||||
p.serverUDPRtcp = nil
|
||||
if closeServerUDPRTCP && p.serverUDPRTCP != nil {
|
||||
p.serverUDPRTCP.Close()
|
||||
p.serverUDPRTCP = nil
|
||||
}
|
||||
|
||||
if closeServerUDPRtp && p.serverUDPRtp != nil {
|
||||
p.serverUDPRtp.Close()
|
||||
p.serverUDPRtp = nil
|
||||
if closeServerUDPRTP && p.serverUDPRTP != nil {
|
||||
p.serverUDPRTP.Close()
|
||||
p.serverUDPRTP = nil
|
||||
}
|
||||
|
||||
if closePprof && p.pprof != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue