2019-12-28 21:07:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-10-24 17:55:47 +00:00
|
|
|
"reflect"
|
2020-09-03 14:24:39 +00:00
|
|
|
"sync/atomic"
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-07-12 10:34:35 +00:00
|
|
|
"github.com/aler9/gortsplib"
|
2019-12-28 21:07:03 +00:00
|
|
|
"gopkg.in/alecthomas/kingpin.v2"
|
2020-10-13 22:02:55 +00:00
|
|
|
|
2020-11-01 21:56:56 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/clientman"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/conf"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/confwatcher"
|
2020-12-08 11:21:06 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/logger"
|
2020-11-01 21:56:56 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/metrics"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/pathman"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/pprof"
|
2021-03-19 12:37:14 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rlimit"
|
2021-01-31 15:58:57 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/serverrtmp"
|
2021-01-31 12:18:05 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/serverrtsp"
|
2020-11-01 21:56:56 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/stats"
|
2019-12-28 21:07:03 +00:00
|
|
|
)
|
|
|
|
|
2020-11-24 20:45:44 +00:00
|
|
|
var version = "v0.0.0"
|
2019-12-28 21:07:03 +00:00
|
|
|
|
2020-05-10 13:33:42 +00:00
|
|
|
type program struct {
|
2021-03-06 08:11:46 +00:00
|
|
|
confPath string
|
|
|
|
conf *conf.Conf
|
|
|
|
confFound bool
|
|
|
|
stats *stats.Stats
|
|
|
|
logger *logger.Logger
|
|
|
|
metrics *metrics.Metrics
|
2021-03-27 11:23:19 +00:00
|
|
|
pprof *pprof.PPROF
|
2021-03-06 08:11:46 +00:00
|
|
|
serverRTSPPlain *serverrtsp.Server
|
|
|
|
serverRTSPTLS *serverrtsp.Server
|
|
|
|
serverRTMP *serverrtmp.Server
|
|
|
|
pathMan *pathman.PathManager
|
|
|
|
clientMan *clientman.ClientManager
|
|
|
|
confWatcher *confwatcher.ConfWatcher
|
2020-10-19 20:17:48 +00:00
|
|
|
|
|
|
|
terminate chan struct{}
|
|
|
|
done chan struct{}
|
2020-05-10 13:33:42 +00:00
|
|
|
}
|
2020-02-16 15:05:08 +00:00
|
|
|
|
2020-12-08 11:21:06 +00:00
|
|
|
func newProgram(args []string) (*program, bool) {
|
2020-06-27 19:22:50 +00:00
|
|
|
k := kingpin.New("rtsp-simple-server",
|
2020-11-24 20:45:44 +00:00
|
|
|
"rtsp-simple-server "+version+"\n\nRTSP server.")
|
2020-05-11 07:31:56 +00:00
|
|
|
|
2020-06-27 19:22:50 +00:00
|
|
|
argVersion := k.Flag("version", "print version").Bool()
|
2020-10-13 22:29:27 +00:00
|
|
|
argConfPath := k.Arg("confpath", "path to a config file. The default is rtsp-simple-server.yml.").Default("rtsp-simple-server.yml").String()
|
2020-05-11 07:31:56 +00:00
|
|
|
|
2020-07-20 09:42:56 +00:00
|
|
|
kingpin.MustParse(k.Parse(args))
|
2020-05-11 07:31:56 +00:00
|
|
|
|
2020-12-05 19:42:59 +00:00
|
|
|
if *argVersion {
|
2020-11-24 20:45:44 +00:00
|
|
|
fmt.Println(version)
|
2020-05-10 19:32:40 +00:00
|
|
|
os.Exit(0)
|
2020-01-26 11:58:56 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 12:37:14 +00:00
|
|
|
// on Linux, try to raise the number of file descriptors that can be opened
|
|
|
|
// to allow the maximum possible number of clients
|
|
|
|
// do not check for errors
|
|
|
|
rlimit.Raise()
|
|
|
|
|
2020-10-19 20:17:48 +00:00
|
|
|
p := &program{
|
2020-10-24 17:55:47 +00:00
|
|
|
confPath: *argConfPath,
|
2020-10-19 20:17:48 +00:00
|
|
|
terminate: make(chan struct{}),
|
|
|
|
done: make(chan struct{}),
|
2020-09-18 22:19:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
var err error
|
2020-12-06 21:29:56 +00:00
|
|
|
p.conf, p.confFound, err = conf.Load(p.confPath)
|
2020-10-19 20:17:48 +00:00
|
|
|
if err != nil {
|
2020-12-19 19:03:28 +00:00
|
|
|
fmt.Printf("ERR: %s\n", err)
|
2020-12-08 11:21:06 +00:00
|
|
|
return nil, false
|
2020-06-30 13:12:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
err = p.createResources(true)
|
2020-08-29 17:48:41 +00:00
|
|
|
if err != nil {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.Log(logger.Info, "ERR: %s", err)
|
2020-12-13 22:43:31 +00:00
|
|
|
p.closeResources(nil)
|
2020-12-08 11:21:06 +00:00
|
|
|
return nil, false
|
2020-11-26 20:44:16 +00:00
|
|
|
}
|
|
|
|
|
2020-12-06 21:29:56 +00:00
|
|
|
if p.confFound {
|
|
|
|
p.confWatcher, err = confwatcher.New(p.confPath)
|
|
|
|
if err != nil {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.Log(logger.Info, "ERR: %s", err)
|
2020-12-13 22:43:31 +00:00
|
|
|
p.closeResources(nil)
|
2020-12-08 11:21:06 +00:00
|
|
|
return nil, false
|
2020-12-06 21:29:56 +00:00
|
|
|
}
|
2020-08-29 17:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 20:17:48 +00:00
|
|
|
go p.run()
|
2020-11-26 20:44:16 +00:00
|
|
|
|
2020-12-08 11:21:06 +00:00
|
|
|
return p, true
|
2019-12-28 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
func (p *program) close() {
|
|
|
|
close(p.terminate)
|
|
|
|
<-p.done
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:21:06 +00:00
|
|
|
func (p *program) Log(level logger.Level, format string, args ...interface{}) {
|
2020-10-19 20:17:48 +00:00
|
|
|
countClients := atomic.LoadInt64(p.stats.CountClients)
|
|
|
|
countPublishers := atomic.LoadInt64(p.stats.CountPublishers)
|
|
|
|
countReaders := atomic.LoadInt64(p.stats.CountReaders)
|
2020-09-03 14:24:39 +00:00
|
|
|
|
2020-12-08 11:21:06 +00:00
|
|
|
p.logger.Log(level, "[%d/%d/%d] "+format, append([]interface{}{countClients,
|
2020-12-05 19:42:59 +00:00
|
|
|
countPublishers, countReaders}, args...)...)
|
2020-09-14 11:41:10 +00:00
|
|
|
}
|
2020-07-30 17:21:36 +00:00
|
|
|
|
2020-06-27 11:38:35 +00:00
|
|
|
func (p *program) run() {
|
2020-10-14 17:35:21 +00:00
|
|
|
defer close(p.done)
|
|
|
|
|
2020-12-06 21:29:56 +00:00
|
|
|
confChanged := func() chan struct{} {
|
|
|
|
if p.confWatcher != nil {
|
|
|
|
return p.confWatcher.Watch()
|
|
|
|
}
|
|
|
|
return make(chan struct{})
|
|
|
|
}()
|
|
|
|
|
2020-06-27 11:38:35 +00:00
|
|
|
outer:
|
2020-07-29 21:30:42 +00:00
|
|
|
for {
|
|
|
|
select {
|
2020-12-06 21:29:56 +00:00
|
|
|
case <-confChanged:
|
2020-10-24 17:55:47 +00:00
|
|
|
err := p.reloadConf()
|
|
|
|
if err != nil {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.Log(logger.Info, "ERR: %s", err)
|
2020-10-24 17:55:47 +00:00
|
|
|
break outer
|
|
|
|
}
|
|
|
|
|
2020-08-31 22:01:17 +00:00
|
|
|
case <-p.terminate:
|
|
|
|
break outer
|
2020-06-27 11:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
p.closeResources(nil)
|
|
|
|
|
|
|
|
if p.confWatcher != nil {
|
|
|
|
p.confWatcher.Close()
|
|
|
|
}
|
2020-10-19 20:17:48 +00:00
|
|
|
}
|
2020-06-27 11:38:35 +00:00
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
func (p *program) createResources(initial bool) error {
|
2020-10-24 17:55:47 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if p.stats == nil {
|
|
|
|
p.stats = stats.New()
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:21:06 +00:00
|
|
|
if p.logger == nil {
|
2021-01-06 11:40:18 +00:00
|
|
|
p.logger, err = logger.New(
|
|
|
|
p.conf.LogLevelParsed,
|
|
|
|
p.conf.LogDestinationsParsed,
|
2020-12-08 11:21:06 +00:00
|
|
|
p.conf.LogFile)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if initial {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.Log(logger.Info, "rtsp-simple-server %s", version)
|
2020-12-06 21:29:56 +00:00
|
|
|
if !p.confFound {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.Log(logger.Warn, "configuration file not found, using the default one")
|
2020-12-06 21:29:56 +00:00
|
|
|
}
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.conf.Metrics {
|
|
|
|
if p.metrics == nil {
|
2021-01-15 17:56:35 +00:00
|
|
|
p.metrics, err = metrics.New(
|
|
|
|
p.conf.ListenIP,
|
2021-03-13 17:22:02 +00:00
|
|
|
p.conf.MetricsPort,
|
2021-01-15 17:56:35 +00:00
|
|
|
p.stats,
|
|
|
|
p)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-27 11:23:19 +00:00
|
|
|
if p.conf.PPROF {
|
2020-10-24 17:55:47 +00:00
|
|
|
if p.pprof == nil {
|
2021-01-15 17:56:35 +00:00
|
|
|
p.pprof, err = pprof.New(
|
|
|
|
p.conf.ListenIP,
|
2021-03-27 11:23:19 +00:00
|
|
|
p.conf.PPROFPort,
|
2021-01-15 17:56:35 +00:00
|
|
|
p)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 19:19:43 +00:00
|
|
|
if !p.conf.RTSPDisable &&
|
|
|
|
(p.conf.EncryptionParsed == conf.EncryptionNo ||
|
|
|
|
p.conf.EncryptionParsed == conf.EncryptionOptional) {
|
2021-03-06 08:11:46 +00:00
|
|
|
if p.serverRTSPPlain == nil {
|
|
|
|
_, useUDP := p.conf.ProtocolsParsed[gortsplib.StreamProtocolUDP]
|
|
|
|
p.serverRTSPPlain, err = serverrtsp.New(
|
2021-01-15 17:42:53 +00:00
|
|
|
p.conf.ListenIP,
|
2021-01-31 12:18:05 +00:00
|
|
|
p.conf.RTSPPort,
|
2021-03-06 08:11:46 +00:00
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
2021-03-10 18:55:26 +00:00
|
|
|
p.conf.ReadBufferSize,
|
2021-03-06 08:11:46 +00:00
|
|
|
useUDP,
|
|
|
|
p.conf.RTPPort,
|
|
|
|
p.conf.RTCPPort,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"",
|
2021-01-06 11:40:18 +00:00
|
|
|
p)
|
2020-12-13 22:43:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 19:19:43 +00:00
|
|
|
if !p.conf.RTSPDisable &&
|
|
|
|
(p.conf.EncryptionParsed == conf.EncryptionStrict ||
|
|
|
|
p.conf.EncryptionParsed == conf.EncryptionOptional) {
|
2021-03-06 08:11:46 +00:00
|
|
|
if p.serverRTSPTLS == nil {
|
|
|
|
p.serverRTSPTLS, err = serverrtsp.New(
|
2021-01-15 17:42:53 +00:00
|
|
|
p.conf.ListenIP,
|
2021-01-31 12:18:05 +00:00
|
|
|
p.conf.RTSPSPort,
|
2021-03-06 08:11:46 +00:00
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
2021-03-10 18:55:26 +00:00
|
|
|
p.conf.ReadBufferSize,
|
2021-03-06 08:11:46 +00:00
|
|
|
false,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
p.conf.ServerCert,
|
|
|
|
p.conf.ServerKey,
|
2021-01-06 11:40:18 +00:00
|
|
|
p)
|
2020-12-13 22:43:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 19:19:43 +00:00
|
|
|
if !p.conf.RTMPDisable {
|
2021-01-31 15:58:57 +00:00
|
|
|
if p.serverRTMP == nil {
|
|
|
|
p.serverRTMP, err = serverrtmp.New(
|
|
|
|
p.conf.ListenIP,
|
|
|
|
p.conf.RTMPPort,
|
|
|
|
p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
if p.pathMan == nil {
|
2021-01-06 11:40:18 +00:00
|
|
|
p.pathMan = pathman.New(
|
2021-01-31 12:18:05 +00:00
|
|
|
p.conf.RTSPPort,
|
2021-01-06 11:40:18 +00:00
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
2021-01-10 11:55:53 +00:00
|
|
|
p.conf.ReadBufferCount,
|
2021-02-18 22:26:45 +00:00
|
|
|
p.conf.ReadBufferSize,
|
2021-01-06 11:40:18 +00:00
|
|
|
p.conf.AuthMethodsParsed,
|
|
|
|
p.conf.Paths,
|
|
|
|
p.stats,
|
|
|
|
p)
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.clientMan == nil {
|
2021-01-06 11:40:18 +00:00
|
|
|
p.clientMan = clientman.New(
|
2021-01-31 12:18:05 +00:00
|
|
|
p.conf.RTSPPort,
|
2021-01-06 11:40:18 +00:00
|
|
|
p.conf.ReadTimeout,
|
2021-03-10 14:06:45 +00:00
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
2021-01-06 11:40:18 +00:00
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
|
|
|
p.conf.ProtocolsParsed,
|
|
|
|
p.stats,
|
|
|
|
p.pathMan,
|
2021-03-06 08:11:46 +00:00
|
|
|
p.serverRTSPPlain,
|
|
|
|
p.serverRTSPTLS,
|
2021-01-31 20:42:27 +00:00
|
|
|
p.serverRTMP,
|
2021-01-06 11:40:18 +00:00
|
|
|
p)
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
func (p *program) closeResources(newConf *conf.Conf) {
|
2020-12-08 11:21:06 +00:00
|
|
|
closeLogger := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
|
|
|
!reflect.DeepEqual(newConf.LogDestinationsParsed, p.conf.LogDestinationsParsed) ||
|
|
|
|
newConf.LogFile != p.conf.LogFile {
|
2020-12-08 11:21:06 +00:00
|
|
|
closeLogger = true
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closeMetrics := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-01-15 17:56:35 +00:00
|
|
|
newConf.Metrics != p.conf.Metrics ||
|
2021-03-13 17:22:02 +00:00
|
|
|
newConf.ListenIP != p.conf.ListenIP ||
|
|
|
|
newConf.MetricsPort != p.conf.MetricsPort {
|
2020-10-24 17:55:47 +00:00
|
|
|
closeMetrics = true
|
|
|
|
}
|
|
|
|
|
2021-03-27 11:23:19 +00:00
|
|
|
closePPROF := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-03-27 11:23:19 +00:00
|
|
|
newConf.PPROF != p.conf.PPROF ||
|
2021-03-27 10:21:30 +00:00
|
|
|
newConf.ListenIP != p.conf.ListenIP ||
|
2021-03-27 11:23:19 +00:00
|
|
|
newConf.PPROFPort != p.conf.PPROFPort {
|
|
|
|
closePPROF = true
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:23:45 +00:00
|
|
|
closeServerPlain := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-03-10 19:19:43 +00:00
|
|
|
newConf.RTSPDisable != p.conf.RTSPDisable ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
|
2021-01-15 17:42:53 +00:00
|
|
|
newConf.ListenIP != p.conf.ListenIP ||
|
2021-01-31 12:18:05 +00:00
|
|
|
newConf.RTSPPort != p.conf.RTSPPort ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2021-01-06 11:40:18 +00:00
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2021-01-10 11:55:53 +00:00
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
2021-03-06 08:11:46 +00:00
|
|
|
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
|
|
|
newConf.RTPPort != p.conf.RTPPort ||
|
|
|
|
newConf.RTCPPort != p.conf.RTCPPort {
|
2021-01-06 20:23:45 +00:00
|
|
|
closeServerPlain = true
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
closeServerTLS := false
|
|
|
|
if newConf == nil ||
|
2021-03-10 19:19:43 +00:00
|
|
|
newConf.RTSPDisable != p.conf.RTSPDisable ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
|
2021-01-15 17:42:53 +00:00
|
|
|
newConf.ListenIP != p.conf.ListenIP ||
|
2021-01-31 12:18:05 +00:00
|
|
|
newConf.RTSPSPort != p.conf.RTSPSPort ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2021-01-10 11:55:53 +00:00
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2021-03-06 08:11:46 +00:00
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
|
|
|
newConf.ServerCert != p.conf.ServerCert ||
|
|
|
|
newConf.ServerKey != p.conf.ServerKey {
|
2020-12-13 22:43:31 +00:00
|
|
|
closeServerTLS = true
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:42:27 +00:00
|
|
|
closeServerRTMP := false
|
|
|
|
if newConf == nil ||
|
2021-03-10 19:19:43 +00:00
|
|
|
newConf.RTMPDisable != p.conf.RTMPDisable ||
|
2021-01-31 20:42:27 +00:00
|
|
|
newConf.ListenIP != p.conf.ListenIP ||
|
|
|
|
newConf.RTMPPort != p.conf.RTMPPort ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout {
|
|
|
|
closeServerRTMP = true
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
closePathMan := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-01-31 12:18:05 +00:00
|
|
|
newConf.RTSPPort != p.conf.RTSPPort ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2021-01-10 11:55:53 +00:00
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
2021-02-18 22:26:45 +00:00
|
|
|
newConf.ReadBufferSize != p.conf.ReadBufferSize ||
|
2020-12-13 22:43:31 +00:00
|
|
|
!reflect.DeepEqual(newConf.AuthMethodsParsed, p.conf.AuthMethodsParsed) {
|
2020-10-24 17:55:47 +00:00
|
|
|
closePathMan = true
|
2020-12-13 22:43:31 +00:00
|
|
|
} else if !reflect.DeepEqual(newConf.Paths, p.conf.Paths) {
|
|
|
|
p.pathMan.OnProgramConfReload(newConf.Paths)
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closeClientMan := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-01-06 20:23:45 +00:00
|
|
|
closeServerPlain ||
|
2020-12-13 22:43:31 +00:00
|
|
|
closeServerTLS ||
|
2021-01-31 20:42:27 +00:00
|
|
|
closeServerRTMP ||
|
2020-10-24 17:55:47 +00:00
|
|
|
closePathMan ||
|
2021-01-31 12:18:05 +00:00
|
|
|
newConf.RTSPPort != p.conf.RTSPPort ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2021-03-10 14:06:45 +00:00
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
2020-12-13 22:43:31 +00:00
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
|
|
|
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) {
|
2020-10-24 17:55:47 +00:00
|
|
|
closeClientMan = true
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
closeStats := false
|
|
|
|
if newConf == nil {
|
|
|
|
closeStats = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeClientMan && p.clientMan != nil {
|
2020-10-24 17:55:47 +00:00
|
|
|
p.clientMan.Close()
|
|
|
|
p.clientMan = nil
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
if closePathMan && p.pathMan != nil {
|
2020-10-24 17:55:47 +00:00
|
|
|
p.pathMan.Close()
|
|
|
|
p.pathMan = nil
|
2021-01-31 20:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if closeServerRTMP && p.serverRTMP != nil {
|
|
|
|
p.serverRTMP.Close()
|
|
|
|
p.serverRTMP = nil
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 08:11:46 +00:00
|
|
|
if closeServerTLS && p.serverRTSPTLS != nil {
|
|
|
|
p.serverRTSPTLS.Close()
|
|
|
|
p.serverRTSPTLS = nil
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 08:11:46 +00:00
|
|
|
if closeServerPlain && p.serverRTSPPlain != nil {
|
|
|
|
p.serverRTSPPlain.Close()
|
|
|
|
p.serverRTSPPlain = nil
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-27 11:23:19 +00:00
|
|
|
if closePPROF && p.pprof != nil {
|
2020-10-24 17:55:47 +00:00
|
|
|
p.pprof.Close()
|
|
|
|
p.pprof = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeMetrics && p.metrics != nil {
|
|
|
|
p.metrics.Close()
|
|
|
|
p.metrics = nil
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
if closeLogger && p.logger != nil {
|
2020-12-08 11:21:06 +00:00
|
|
|
p.logger.Close()
|
|
|
|
p.logger = nil
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-13 22:43:31 +00:00
|
|
|
if closeStats && p.stats != nil {
|
|
|
|
p.stats.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *program) reloadConf() error {
|
|
|
|
p.Log(logger.Info, "reloading configuration")
|
|
|
|
|
|
|
|
newConf, _, err := conf.Load(p.confPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
p.closeResources(newConf)
|
|
|
|
|
|
|
|
p.conf = newConf
|
|
|
|
return p.createResources(false)
|
2020-06-27 11:38:35 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 21:07:03 +00:00
|
|
|
func main() {
|
2020-12-08 11:21:06 +00:00
|
|
|
p, ok := newProgram(os.Args[1:])
|
|
|
|
if !ok {
|
|
|
|
os.Exit(1)
|
2019-12-28 21:07:03 +00:00
|
|
|
}
|
2020-10-24 17:55:47 +00:00
|
|
|
<-p.done
|
2019-12-28 21:07:03 +00:00
|
|
|
}
|