2019-12-28 21:07:03 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-05-10 19:32:59 +00:00
|
|
|
"context"
|
2019-12-28 21:07:03 +00:00
|
|
|
"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
|
|
|
|
|
|
|
"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/conf"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/confwatcher"
|
2021-05-09 15:22:24 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/hlsserver"
|
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-05-09 15:02:14 +00:00
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rtmpserver"
|
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rtspserver"
|
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-05-10 19:32:59 +00:00
|
|
|
ctx context.Context
|
|
|
|
ctxCancel func()
|
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-04-27 17:04:05 +00:00
|
|
|
pathMan *pathman.PathManager
|
2021-05-09 15:02:14 +00:00
|
|
|
serverRTSPPlain *rtspserver.Server
|
|
|
|
serverRTSPTLS *rtspserver.Server
|
|
|
|
serverRTMP *rtmpserver.Server
|
|
|
|
serverHLS *hlsserver.Server
|
2021-03-06 08:11:46 +00:00
|
|
|
confWatcher *confwatcher.ConfWatcher
|
2020-10-19 20:17:48 +00:00
|
|
|
|
2021-05-10 19:32:59 +00:00
|
|
|
// out
|
|
|
|
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()
|
|
|
|
|
2021-05-10 19:32:59 +00:00
|
|
|
ctx, ctxCancel := context.WithCancel(context.Background())
|
|
|
|
|
2020-10-19 20:17:48 +00:00
|
|
|
p := &program{
|
2021-05-10 19:32:59 +00:00
|
|
|
ctx: ctx,
|
|
|
|
ctxCancel: ctxCancel,
|
2020-10-24 17:55:47 +00:00
|
|
|
confPath: *argConfPath,
|
2020-10-19 20:17:48 +00:00
|
|
|
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() {
|
2021-05-10 19:32:59 +00:00
|
|
|
p.ctxCancel()
|
2020-10-24 17:55:47 +00:00
|
|
|
<-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
|
|
|
countPublishers := atomic.LoadInt64(p.stats.CountPublishers)
|
|
|
|
countReaders := atomic.LoadInt64(p.stats.CountReaders)
|
2020-09-03 14:24:39 +00:00
|
|
|
|
2021-05-08 20:52:10 +00:00
|
|
|
p.logger.Log(level, "[%d/%d] "+format, append([]interface{}{
|
2021-05-23 16:43:49 +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
|
|
|
|
}
|
|
|
|
|
2021-05-10 19:32:59 +00:00
|
|
|
case <-p.ctx.Done():
|
2020-08-31 22:01:17 +00:00
|
|
|
break outer
|
2020-06-27 11:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 19:32:59 +00:00
|
|
|
p.ctxCancel()
|
|
|
|
|
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(
|
2021-04-24 16:25:19 +00:00
|
|
|
p.conf.MetricsAddress,
|
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(
|
2021-04-24 16:25:19 +00:00
|
|
|
p.conf.PPROFAddress,
|
2021-01-15 17:56:35 +00:00
|
|
|
p)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.pathMan == nil {
|
2021-01-06 11:40:18 +00:00
|
|
|
p.pathMan = pathman.New(
|
2021-05-11 15:20:32 +00:00
|
|
|
p.ctx,
|
2021-04-24 16:25:19 +00:00
|
|
|
p.conf.RTSPAddress,
|
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
|
|
|
}
|
|
|
|
|
2021-04-27 11:43:15 +00:00
|
|
|
if !p.conf.RTSPDisable &&
|
|
|
|
(p.conf.EncryptionParsed == conf.EncryptionNo ||
|
|
|
|
p.conf.EncryptionParsed == conf.EncryptionOptional) {
|
|
|
|
if p.serverRTSPPlain == nil {
|
2021-06-15 20:15:51 +00:00
|
|
|
_, useUDP := p.conf.ProtocolsParsed[conf.ProtocolUDP]
|
2021-06-19 17:20:41 +00:00
|
|
|
_, useMulticast := p.conf.ProtocolsParsed[conf.ProtocolMulticast]
|
2021-05-09 15:02:14 +00:00
|
|
|
p.serverRTSPPlain, err = rtspserver.New(
|
2021-05-11 15:20:32 +00:00
|
|
|
p.ctx,
|
2021-04-27 11:43:15 +00:00
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
|
|
|
p.conf.ReadBufferSize,
|
|
|
|
useUDP,
|
2021-06-19 17:20:41 +00:00
|
|
|
useMulticast,
|
2021-04-27 11:43:15 +00:00
|
|
|
p.conf.RTPAddress,
|
|
|
|
p.conf.RTCPAddress,
|
2021-06-19 17:20:41 +00:00
|
|
|
p.conf.MulticastIPRange,
|
|
|
|
p.conf.MulticastRTPPort,
|
|
|
|
p.conf.MulticastRTCPPort,
|
2021-04-27 11:43:15 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.ProtocolsParsed,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
|
|
|
p.stats,
|
|
|
|
p.pathMan,
|
|
|
|
p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !p.conf.RTSPDisable &&
|
|
|
|
(p.conf.EncryptionParsed == conf.EncryptionStrict ||
|
|
|
|
p.conf.EncryptionParsed == conf.EncryptionOptional) {
|
|
|
|
if p.serverRTSPTLS == nil {
|
2021-05-09 15:02:14 +00:00
|
|
|
p.serverRTSPTLS, err = rtspserver.New(
|
2021-05-11 15:20:32 +00:00
|
|
|
p.ctx,
|
2021-04-27 11:43:15 +00:00
|
|
|
p.conf.RTSPSAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
|
|
|
p.conf.ReadBufferSize,
|
|
|
|
false,
|
2021-06-19 17:20:41 +00:00
|
|
|
false,
|
|
|
|
"",
|
2021-04-27 11:43:15 +00:00
|
|
|
"",
|
|
|
|
"",
|
2021-06-19 17:20:41 +00:00
|
|
|
0,
|
|
|
|
0,
|
2021-04-27 11:43:15 +00:00
|
|
|
true,
|
|
|
|
p.conf.ServerCert,
|
|
|
|
p.conf.ServerKey,
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.ProtocolsParsed,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
|
|
|
p.stats,
|
|
|
|
p.pathMan,
|
|
|
|
p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:32:23 +00:00
|
|
|
if !p.conf.RTMPDisable {
|
|
|
|
if p.serverRTMP == nil {
|
2021-05-09 15:02:14 +00:00
|
|
|
p.serverRTMP, err = rtmpserver.New(
|
2021-05-11 15:20:32 +00:00
|
|
|
p.ctx,
|
2021-04-27 16:32:23 +00:00
|
|
|
p.conf.RTMPAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.ReadBufferCount,
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
|
|
|
p.stats,
|
|
|
|
p.pathMan,
|
|
|
|
p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 17:04:05 +00:00
|
|
|
if !p.conf.HLSDisable {
|
|
|
|
if p.serverHLS == nil {
|
2021-05-09 15:02:14 +00:00
|
|
|
p.serverHLS, err = hlsserver.New(
|
2021-05-11 15:20:32 +00:00
|
|
|
p.ctx,
|
2021-04-27 17:04:05 +00:00
|
|
|
p.conf.HLSAddress,
|
|
|
|
p.conf.HLSSegmentCount,
|
|
|
|
p.conf.HLSSegmentDuration,
|
2021-06-23 17:28:27 +00:00
|
|
|
p.conf.HLSAllowOrigin,
|
2021-04-27 17:04:05 +00:00
|
|
|
p.conf.ReadBufferCount,
|
|
|
|
p.stats,
|
|
|
|
p.pathMan,
|
|
|
|
p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-04-27 11:43:15 +00:00
|
|
|
closeStats := false
|
|
|
|
if newConf == nil {
|
|
|
|
closeStats = true
|
|
|
|
}
|
|
|
|
|
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-04-27 11:43:15 +00:00
|
|
|
newConf.MetricsAddress != p.conf.MetricsAddress ||
|
|
|
|
closeStats {
|
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-04-27 11:43:15 +00:00
|
|
|
newConf.PPROFAddress != p.conf.PPROFAddress ||
|
|
|
|
closeStats {
|
2021-03-27 11:23:19 +00:00
|
|
|
closePPROF = true
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closePathMan := false
|
2020-12-13 22:43:31 +00:00
|
|
|
if newConf == nil ||
|
2021-04-24 16:25:19 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
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 ||
|
2021-04-27 11:43:15 +00:00
|
|
|
!reflect.DeepEqual(newConf.AuthMethodsParsed, p.conf.AuthMethodsParsed) ||
|
|
|
|
closeStats {
|
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
|
|
|
}
|
|
|
|
|
2021-04-27 11:43:15 +00:00
|
|
|
closeServerPlain := false
|
|
|
|
if newConf == nil ||
|
|
|
|
newConf.RTSPDisable != p.conf.RTSPDisable ||
|
|
|
|
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
|
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
|
|
|
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
|
|
|
newConf.RTPAddress != p.conf.RTPAddress ||
|
|
|
|
newConf.RTCPAddress != p.conf.RTCPAddress ||
|
2021-06-19 17:20:41 +00:00
|
|
|
newConf.MulticastIPRange != p.conf.MulticastIPRange ||
|
|
|
|
newConf.MulticastRTPPort != p.conf.MulticastRTPPort ||
|
|
|
|
newConf.MulticastRTCPPort != p.conf.MulticastRTCPPort ||
|
2021-04-27 11:43:15 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
|
|
|
closeStats ||
|
|
|
|
closePathMan {
|
|
|
|
closeServerPlain = true
|
|
|
|
}
|
|
|
|
|
|
|
|
closeServerTLS := false
|
|
|
|
if newConf == nil ||
|
|
|
|
newConf.RTSPDisable != p.conf.RTSPDisable ||
|
|
|
|
newConf.EncryptionParsed != p.conf.EncryptionParsed ||
|
|
|
|
newConf.RTSPSAddress != p.conf.RTSPSAddress ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
|
|
|
newConf.ServerCert != p.conf.ServerCert ||
|
|
|
|
newConf.ServerKey != p.conf.ServerKey ||
|
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
!reflect.DeepEqual(newConf.ProtocolsParsed, p.conf.ProtocolsParsed) ||
|
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
|
|
|
closeStats ||
|
|
|
|
closePathMan {
|
|
|
|
closeServerTLS = true
|
|
|
|
}
|
|
|
|
|
2021-04-27 16:32:23 +00:00
|
|
|
closeServerRTMP := false
|
|
|
|
if newConf == nil ||
|
|
|
|
newConf.RTMPDisable != p.conf.RTMPDisable ||
|
|
|
|
newConf.RTMPAddress != p.conf.RTMPAddress ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
|
|
|
closeStats ||
|
|
|
|
closePathMan {
|
|
|
|
closeServerRTMP = true
|
|
|
|
}
|
|
|
|
|
2021-04-27 17:04:05 +00:00
|
|
|
closeServerHLS := false
|
|
|
|
if newConf == nil ||
|
|
|
|
newConf.HLSDisable != p.conf.HLSDisable ||
|
|
|
|
newConf.HLSAddress != p.conf.HLSAddress ||
|
|
|
|
newConf.HLSSegmentCount != p.conf.HLSSegmentCount ||
|
|
|
|
newConf.HLSSegmentDuration != p.conf.HLSSegmentDuration ||
|
2021-06-23 17:28:27 +00:00
|
|
|
newConf.HLSAllowOrigin != p.conf.HLSAllowOrigin ||
|
2021-04-27 17:04:05 +00:00
|
|
|
newConf.ReadBufferCount != p.conf.ReadBufferCount ||
|
|
|
|
closeStats ||
|
|
|
|
closePathMan {
|
|
|
|
closeServerHLS = true
|
|
|
|
}
|
|
|
|
|
2021-04-27 11:43:15 +00:00
|
|
|
if closeServerTLS && p.serverRTSPTLS != nil {
|
|
|
|
p.serverRTSPTLS.Close()
|
|
|
|
p.serverRTSPTLS = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeServerPlain && p.serverRTSPPlain != nil {
|
|
|
|
p.serverRTSPPlain.Close()
|
|
|
|
p.serverRTSPPlain = 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
|
|
|
}
|
|
|
|
|
2021-04-11 17:05:08 +00:00
|
|
|
if closeServerHLS && p.serverHLS != nil {
|
|
|
|
p.serverHLS.Close()
|
|
|
|
p.serverHLS = 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-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
|
|
|
}
|