2022-09-17 19:19:45 +00:00
|
|
|
// Package core contains the main struct of the software.
|
2021-07-24 13:55:42 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-11-10 18:04:07 +00:00
|
|
|
"os/signal"
|
2023-09-16 20:14:13 +00:00
|
|
|
"path/filepath"
|
2021-07-24 13:55:42 +00:00
|
|
|
"reflect"
|
2023-09-16 20:14:13 +00:00
|
|
|
"strings"
|
2023-09-16 15:27:07 +00:00
|
|
|
"time"
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2023-01-16 20:45:20 +00:00
|
|
|
"github.com/alecthomas/kong"
|
2023-08-26 16:54:28 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v4"
|
2021-10-17 15:16:57 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/conf"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/confwatcher"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/externalcmd"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
2023-09-16 15:27:07 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/record"
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/rlimit"
|
2021-07-24 13:55:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var version = "v0.0.0"
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
var defaultConfPaths = []string{
|
|
|
|
"rtsp-simple-server.yml",
|
|
|
|
"mediamtx.yml",
|
|
|
|
"/usr/local/etc/mediamtx.yml",
|
|
|
|
"/usr/etc/mediamtx.yml",
|
|
|
|
"/etc/mediamtx/mediamtx.yml",
|
|
|
|
}
|
|
|
|
|
2023-06-21 11:53:58 +00:00
|
|
|
var cli struct {
|
|
|
|
Version bool `help:"print version"`
|
2023-09-16 20:14:13 +00:00
|
|
|
Confpath string `arg:"" default:""`
|
2023-06-21 11:53:58 +00:00
|
|
|
}
|
|
|
|
|
2023-04-01 17:52:06 +00:00
|
|
|
// Core is an instance of mediamtx.
|
2021-07-24 13:55:42 +00:00
|
|
|
type Core struct {
|
2021-12-21 11:39:32 +00:00
|
|
|
ctx context.Context
|
|
|
|
ctxCancel func()
|
|
|
|
confPath string
|
|
|
|
conf *conf.Conf
|
|
|
|
logger *logger.Logger
|
|
|
|
externalCmdPool *externalcmd.Pool
|
|
|
|
metrics *metrics
|
|
|
|
pprof *pprof
|
2023-09-16 15:27:07 +00:00
|
|
|
recordCleaner *record.Cleaner
|
2021-12-21 11:39:32 +00:00
|
|
|
pathManager *pathManager
|
|
|
|
rtspServer *rtspServer
|
|
|
|
rtspsServer *rtspServer
|
|
|
|
rtmpServer *rtmpServer
|
2022-08-16 11:53:04 +00:00
|
|
|
rtmpsServer *rtmpServer
|
2023-05-16 13:59:37 +00:00
|
|
|
hlsManager *hlsManager
|
|
|
|
webRTCManager *webRTCManager
|
2023-07-31 19:20:09 +00:00
|
|
|
srtServer *srtServer
|
2021-12-21 11:39:32 +00:00
|
|
|
api *api
|
|
|
|
confWatcher *confwatcher.ConfWatcher
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
// in
|
2022-08-04 19:07:17 +00:00
|
|
|
chAPIConfigSet chan *conf.Conf
|
2021-07-24 13:55:42 +00:00
|
|
|
|
|
|
|
// out
|
|
|
|
done chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New allocates a core.
|
|
|
|
func New(args []string) (*Core, bool) {
|
2023-01-16 20:45:20 +00:00
|
|
|
parser, err := kong.New(&cli,
|
2023-06-07 10:25:16 +00:00
|
|
|
kong.Description("MediaMTX "+version),
|
2023-01-16 20:45:20 +00:00
|
|
|
kong.UsageOnError(),
|
|
|
|
kong.ValueFormatter(func(value *kong.Value) string {
|
|
|
|
switch value.Name {
|
|
|
|
case "confpath":
|
2023-04-01 17:32:10 +00:00
|
|
|
return "path to a config file. The default is mediamtx.yml."
|
2023-01-16 20:45:20 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return kong.DefaultHelpValueFormatter(value)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-03-20 15:15:14 +00:00
|
|
|
|
2023-01-16 20:45:20 +00:00
|
|
|
_, err = parser.Parse(args)
|
|
|
|
parser.FatalIfErrorf(err)
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2023-01-16 20:45:20 +00:00
|
|
|
if cli.Version {
|
2021-07-24 13:55:42 +00:00
|
|
|
fmt.Println(version)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, ctxCancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
p := &Core{
|
2022-08-04 19:07:17 +00:00
|
|
|
ctx: ctx,
|
|
|
|
ctxCancel: ctxCancel,
|
|
|
|
chAPIConfigSet: make(chan *conf.Conf),
|
|
|
|
done: make(chan struct{}),
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
p.conf, p.confPath, err = conf.Load(cli.Confpath, defaultConfPaths)
|
2021-07-24 13:55:42 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERR: %s\n", err)
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
err = p.createResources(true)
|
|
|
|
if err != nil {
|
2021-11-26 13:46:16 +00:00
|
|
|
if p.logger != nil {
|
|
|
|
p.Log(logger.Error, "%s", err)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("ERR: %s\n", err)
|
|
|
|
}
|
2021-09-06 16:39:15 +00:00
|
|
|
p.closeResources(nil, false)
|
2021-07-24 13:55:42 +00:00
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
go p.run()
|
|
|
|
|
|
|
|
return p, true
|
|
|
|
}
|
|
|
|
|
2022-11-02 17:25:49 +00:00
|
|
|
// Close closes Core and waits for all goroutines to return.
|
|
|
|
func (p *Core) Close() {
|
2021-07-24 13:55:42 +00:00
|
|
|
p.ctxCancel()
|
|
|
|
<-p.done
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait waits for the Core to exit.
|
|
|
|
func (p *Core) Wait() {
|
|
|
|
<-p.done
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log is the main logging function.
|
|
|
|
func (p *Core) Log(level logger.Level, format string, args ...interface{}) {
|
2021-10-28 15:33:43 +00:00
|
|
|
p.logger.Log(level, format, args...)
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Core) run() {
|
|
|
|
defer close(p.done)
|
|
|
|
|
|
|
|
confChanged := func() chan struct{} {
|
|
|
|
if p.confWatcher != nil {
|
|
|
|
return p.confWatcher.Watch()
|
|
|
|
}
|
|
|
|
return make(chan struct{})
|
|
|
|
}()
|
|
|
|
|
2021-11-10 18:04:07 +00:00
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(interrupt, os.Interrupt)
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
outer:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-confChanged:
|
2021-07-04 16:13:49 +00:00
|
|
|
p.Log(logger.Info, "reloading configuration (file changed)")
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
newConf, _, err := conf.Load(p.confPath, nil)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2021-10-27 17:49:57 +00:00
|
|
|
p.Log(logger.Error, "%s", err)
|
2021-07-04 16:13:49 +00:00
|
|
|
break outer
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:39:15 +00:00
|
|
|
err = p.reloadConf(newConf, false)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2021-10-27 17:49:57 +00:00
|
|
|
p.Log(logger.Error, "%s", err)
|
2021-07-04 16:13:49 +00:00
|
|
|
break outer
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:07:17 +00:00
|
|
|
case newConf := <-p.chAPIConfigSet:
|
2021-07-04 16:13:49 +00:00
|
|
|
p.Log(logger.Info, "reloading configuration (API request)")
|
|
|
|
|
2021-09-06 16:39:15 +00:00
|
|
|
err := p.reloadConf(newConf, true)
|
2021-07-24 13:55:42 +00:00
|
|
|
if err != nil {
|
2021-10-27 17:49:57 +00:00
|
|
|
p.Log(logger.Error, "%s", err)
|
2021-07-24 13:55:42 +00:00
|
|
|
break outer
|
|
|
|
}
|
|
|
|
|
2021-11-10 18:04:07 +00:00
|
|
|
case <-interrupt:
|
|
|
|
p.Log(logger.Info, "shutting down gracefully")
|
|
|
|
break outer
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
case <-p.ctx.Done():
|
|
|
|
break outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.ctxCancel()
|
|
|
|
|
2021-09-06 16:39:15 +00:00
|
|
|
p.closeResources(nil, false)
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Core) createResources(initial bool) error {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if p.logger == nil {
|
|
|
|
p.logger, err = logger.New(
|
2021-09-27 08:36:28 +00:00
|
|
|
logger.Level(p.conf.LogLevel),
|
|
|
|
p.conf.LogDestinations,
|
2022-12-15 23:50:47 +00:00
|
|
|
p.conf.LogFile,
|
|
|
|
)
|
2021-07-24 13:55:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if initial {
|
2023-06-07 10:25:16 +00:00
|
|
|
p.Log(logger.Info, "MediaMTX %s", version)
|
2023-09-16 20:14:13 +00:00
|
|
|
|
|
|
|
if p.confPath == "" {
|
|
|
|
list := make([]string, len(defaultConfPaths))
|
|
|
|
for i, pa := range defaultConfPaths {
|
|
|
|
a, _ := filepath.Abs(pa)
|
|
|
|
list[i] = a
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Log(logger.Warn,
|
|
|
|
"configuration file not found (looked in %s), using an empty configuration",
|
|
|
|
strings.Join(list, ", "))
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 15:15: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
|
2023-08-13 14:38:23 +00:00
|
|
|
rlimit.Raise() //nolint:errcheck
|
2023-03-20 15:15:14 +00:00
|
|
|
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
|
2021-12-21 11:39:32 +00:00
|
|
|
p.externalCmdPool = externalcmd.NewPool()
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.Metrics &&
|
|
|
|
p.metrics == nil {
|
|
|
|
p.metrics, err = newMetrics(
|
|
|
|
p.conf.MetricsAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.PPROF &&
|
|
|
|
p.pprof == nil {
|
|
|
|
p.pprof, err = newPPROF(
|
|
|
|
p.conf.PPROFAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-16 15:27:07 +00:00
|
|
|
if p.conf.Record &&
|
|
|
|
p.conf.RecordDeleteAfter != 0 &&
|
|
|
|
p.recordCleaner == nil {
|
|
|
|
p.recordCleaner = record.NewCleaner(
|
|
|
|
p.conf.RecordPath,
|
|
|
|
time.Duration(p.conf.RecordDeleteAfter),
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-30 12:49:09 +00:00
|
|
|
if p.pathManager == nil {
|
|
|
|
p.pathManager = newPathManager(
|
2023-05-08 15:04:14 +00:00
|
|
|
p.conf.ExternalAuthenticationURL,
|
2021-07-24 13:55:42 +00:00
|
|
|
p.conf.RTSPAddress,
|
2023-05-08 15:04:14 +00:00
|
|
|
p.conf.AuthMethods,
|
2021-07-24 13:55:42 +00:00
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
2023-08-26 11:25:21 +00:00
|
|
|
p.conf.WriteQueueSize,
|
2023-03-31 09:53:49 +00:00
|
|
|
p.conf.UDPMaxPayloadSize,
|
2023-09-16 15:27:07 +00:00
|
|
|
p.conf.Record,
|
|
|
|
p.conf.RecordPath,
|
|
|
|
p.conf.RecordPartDuration,
|
|
|
|
p.conf.RecordSegmentDuration,
|
2021-07-24 13:55:42 +00:00
|
|
|
p.conf.Paths,
|
2021-12-22 18:13:56 +00:00
|
|
|
p.externalCmdPool,
|
2021-08-12 09:48:47 +00:00
|
|
|
p.metrics,
|
2022-12-15 23:50:47 +00:00
|
|
|
p,
|
|
|
|
)
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-06 19:40:08 +00:00
|
|
|
if p.conf.RTSP &&
|
2021-09-27 08:36:28 +00:00
|
|
|
(p.conf.Encryption == conf.EncryptionNo ||
|
2023-08-26 16:54:28 +00:00
|
|
|
p.conf.Encryption == conf.EncryptionOptional) &&
|
|
|
|
p.rtspServer == nil {
|
|
|
|
_, useUDP := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDP)]
|
|
|
|
_, useMulticast := p.conf.Protocols[conf.Protocol(gortsplib.TransportUDPMulticast)]
|
|
|
|
|
|
|
|
p.rtspServer, err = newRTSPServer(
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.AuthMethods,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
useUDP,
|
|
|
|
useMulticast,
|
|
|
|
p.conf.RTPAddress,
|
|
|
|
p.conf.RTCPAddress,
|
|
|
|
p.conf.MulticastIPRange,
|
|
|
|
p.conf.MulticastRTPPort,
|
|
|
|
p.conf.MulticastRTCPPort,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.Protocols,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RunOnDisconnect,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.externalCmdPool,
|
|
|
|
p.metrics,
|
|
|
|
p.pathManager,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 19:40:08 +00:00
|
|
|
if p.conf.RTSP &&
|
2021-09-27 08:36:28 +00:00
|
|
|
(p.conf.Encryption == conf.EncryptionStrict ||
|
2023-08-26 16:54:28 +00:00
|
|
|
p.conf.Encryption == conf.EncryptionOptional) &&
|
|
|
|
p.rtspsServer == nil {
|
|
|
|
p.rtspsServer, err = newRTSPServer(
|
|
|
|
p.conf.RTSPSAddress,
|
|
|
|
p.conf.AuthMethods,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
true,
|
|
|
|
p.conf.ServerCert,
|
|
|
|
p.conf.ServerKey,
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.Protocols,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RunOnDisconnect,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.externalCmdPool,
|
|
|
|
p.metrics,
|
|
|
|
p.pathManager,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 19:40:08 +00:00
|
|
|
if p.conf.RTMP &&
|
2022-08-16 11:53:04 +00:00
|
|
|
(p.conf.RTMPEncryption == conf.EncryptionNo ||
|
2023-08-26 16:54:28 +00:00
|
|
|
p.conf.RTMPEncryption == conf.EncryptionOptional) &&
|
|
|
|
p.rtmpServer == nil {
|
|
|
|
p.rtmpServer, err = newRTMPServer(
|
|
|
|
p.conf.RTMPAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RunOnDisconnect,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.externalCmdPool,
|
|
|
|
p.metrics,
|
|
|
|
p.pathManager,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-08-16 11:53:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-06 19:40:08 +00:00
|
|
|
if p.conf.RTMP &&
|
2022-08-16 11:53:04 +00:00
|
|
|
(p.conf.RTMPEncryption == conf.EncryptionStrict ||
|
2023-08-26 16:54:28 +00:00
|
|
|
p.conf.RTMPEncryption == conf.EncryptionOptional) &&
|
|
|
|
p.rtmpsServer == nil {
|
|
|
|
p.rtmpsServer, err = newRTMPServer(
|
|
|
|
p.conf.RTMPSAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
true,
|
|
|
|
p.conf.RTMPServerCert,
|
|
|
|
p.conf.RTMPServerKey,
|
|
|
|
p.conf.RTSPAddress,
|
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RunOnDisconnect,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.externalCmdPool,
|
|
|
|
p.metrics,
|
|
|
|
p.pathManager,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.HLS &&
|
|
|
|
p.hlsManager == nil {
|
|
|
|
p.hlsManager, err = newHLSManager(
|
|
|
|
p.conf.HLSAddress,
|
|
|
|
p.conf.HLSEncryption,
|
|
|
|
p.conf.HLSServerKey,
|
|
|
|
p.conf.HLSServerCert,
|
|
|
|
p.conf.ExternalAuthenticationURL,
|
|
|
|
p.conf.HLSAlwaysRemux,
|
|
|
|
p.conf.HLSVariant,
|
|
|
|
p.conf.HLSSegmentCount,
|
|
|
|
p.conf.HLSSegmentDuration,
|
|
|
|
p.conf.HLSPartDuration,
|
|
|
|
p.conf.HLSSegmentMaxSize,
|
|
|
|
p.conf.HLSAllowOrigin,
|
|
|
|
p.conf.HLSTrustedProxies,
|
|
|
|
p.conf.HLSDirectory,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
p.pathManager,
|
|
|
|
p.metrics,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.WebRTC &&
|
|
|
|
p.webRTCManager == nil {
|
|
|
|
p.webRTCManager, err = newWebRTCManager(
|
|
|
|
p.conf.WebRTCAddress,
|
|
|
|
p.conf.WebRTCEncryption,
|
|
|
|
p.conf.WebRTCServerKey,
|
|
|
|
p.conf.WebRTCServerCert,
|
|
|
|
p.conf.WebRTCAllowOrigin,
|
|
|
|
p.conf.WebRTCTrustedProxies,
|
|
|
|
p.conf.WebRTCICEServers2,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
p.conf.WebRTCICEHostNAT1To1IPs,
|
|
|
|
p.conf.WebRTCICEUDPMuxAddress,
|
|
|
|
p.conf.WebRTCICETCPMuxAddress,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.externalCmdPool,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.pathManager,
|
|
|
|
p.metrics,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.SRT &&
|
|
|
|
p.srtServer == nil {
|
|
|
|
p.srtServer, err = newSRTServer(
|
|
|
|
p.conf.SRTAddress,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RTSPAddress,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf.WriteTimeout,
|
|
|
|
p.conf.WriteQueueSize,
|
|
|
|
p.conf.UDPMaxPayloadSize,
|
2023-09-16 17:21:48 +00:00
|
|
|
p.conf.RunOnConnect,
|
|
|
|
p.conf.RunOnConnectRestart,
|
|
|
|
p.conf.RunOnDisconnect,
|
2023-08-26 16:54:28 +00:00
|
|
|
p.externalCmdPool,
|
|
|
|
p.pathManager,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.API &&
|
|
|
|
p.api == nil {
|
|
|
|
p.api, err = newAPI(
|
|
|
|
p.conf.APIAddress,
|
|
|
|
p.conf.ReadTimeout,
|
|
|
|
p.conf,
|
|
|
|
p.pathManager,
|
|
|
|
p.rtspServer,
|
|
|
|
p.rtspsServer,
|
|
|
|
p.rtmpServer,
|
|
|
|
p.rtmpsServer,
|
|
|
|
p.hlsManager,
|
|
|
|
p.webRTCManager,
|
|
|
|
p.srtServer,
|
|
|
|
p,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
if initial && p.confPath != "" {
|
2021-12-21 11:39:32 +00:00
|
|
|
p.confWatcher, err = confwatcher.New(p.confPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:39:15 +00:00
|
|
|
func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
2022-12-15 23:50:47 +00:00
|
|
|
closeLogger := newConf == nil ||
|
2023-09-01 17:54:34 +00:00
|
|
|
newConf.LogLevel != p.conf.LogLevel ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.LogDestinations, p.conf.LogDestinations) ||
|
2022-12-15 23:50:47 +00:00
|
|
|
newConf.LogFile != p.conf.LogFile
|
2023-09-16 20:14:13 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeMetrics := newConf == nil ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.Metrics != p.conf.Metrics ||
|
2023-04-11 18:47:19 +00:00
|
|
|
newConf.MetricsAddress != p.conf.MetricsAddress ||
|
2023-09-01 17:54:34 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
closeLogger
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closePPROF := newConf == nil ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.PPROF != p.conf.PPROF ||
|
2023-04-11 18:47:19 +00:00
|
|
|
newConf.PPROFAddress != p.conf.PPROFAddress ||
|
2023-09-01 17:54:34 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
closeLogger
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2023-09-16 15:27:07 +00:00
|
|
|
closeRecorderCleaner := newConf == nil ||
|
|
|
|
newConf.Record != p.conf.Record ||
|
|
|
|
newConf.RecordPath != p.conf.RecordPath ||
|
|
|
|
newConf.RecordDeleteAfter != p.conf.RecordDeleteAfter
|
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closePathManager := newConf == nil ||
|
2023-05-08 15:04:14 +00:00
|
|
|
newConf.ExternalAuthenticationURL != p.conf.ExternalAuthenticationURL ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
2023-05-08 15:04:14 +00:00
|
|
|
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2023-03-31 09:53:49 +00:00
|
|
|
newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize ||
|
2023-09-16 15:27:07 +00:00
|
|
|
newConf.Record != p.conf.Record ||
|
|
|
|
newConf.RecordPath != p.conf.RecordPath ||
|
|
|
|
newConf.RecordPartDuration != p.conf.RecordPartDuration ||
|
|
|
|
newConf.RecordSegmentDuration != p.conf.RecordSegmentDuration ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closeMetrics ||
|
|
|
|
closeLogger
|
2022-12-15 23:50:47 +00:00
|
|
|
if !closePathManager && !reflect.DeepEqual(newConf.Paths, p.conf.Paths) {
|
2022-08-04 19:07:17 +00:00
|
|
|
p.pathManager.confReload(newConf.Paths)
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeRTSPServer := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.RTSP != p.conf.RTSP ||
|
2021-09-27 08:36:28 +00:00
|
|
|
newConf.Encryption != p.conf.Encryption ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
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 ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RunOnDisconnect != p.conf.RunOnDisconnect ||
|
2021-08-12 09:48:47 +00:00
|
|
|
closeMetrics ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeRTSPSServer := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.RTSP != p.conf.RTSP ||
|
2021-09-27 08:36:28 +00:00
|
|
|
newConf.Encryption != p.conf.Encryption ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RTSPSAddress != p.conf.RTSPSAddress ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.ServerCert != p.conf.ServerCert ||
|
|
|
|
newConf.ServerKey != p.conf.ServerKey ||
|
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
2021-09-27 08:36:28 +00:00
|
|
|
!reflect.DeepEqual(newConf.Protocols, p.conf.Protocols) ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RunOnDisconnect != p.conf.RunOnDisconnect ||
|
2021-08-12 09:48:47 +00:00
|
|
|
closeMetrics ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeRTMPServer := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.RTMP != p.conf.RTMP ||
|
2022-08-16 11:53:04 +00:00
|
|
|
newConf.RTMPEncryption != p.conf.RTMPEncryption ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RTMPAddress != p.conf.RTMPAddress ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RunOnDisconnect != p.conf.RunOnDisconnect ||
|
2021-08-12 09:48:47 +00:00
|
|
|
closeMetrics ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2021-07-24 13:55:42 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeRTMPSServer := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.RTMP != p.conf.RTMP ||
|
2022-08-16 11:53:04 +00:00
|
|
|
newConf.RTMPEncryption != p.conf.RTMPEncryption ||
|
|
|
|
newConf.RTMPSAddress != p.conf.RTMPSAddress ||
|
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2022-08-16 11:53:04 +00:00
|
|
|
newConf.RTMPServerCert != p.conf.RTMPServerCert ||
|
|
|
|
newConf.RTMPServerKey != p.conf.RTMPServerKey ||
|
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RunOnDisconnect != p.conf.RunOnDisconnect ||
|
2022-08-16 11:53:04 +00:00
|
|
|
closeMetrics ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2022-08-16 11:53:04 +00:00
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
closeHLSManager := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.HLS != p.conf.HLS ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.HLSAddress != p.conf.HLSAddress ||
|
2022-12-15 23:50:47 +00:00
|
|
|
newConf.HLSEncryption != p.conf.HLSEncryption ||
|
|
|
|
newConf.HLSServerKey != p.conf.HLSServerKey ||
|
|
|
|
newConf.HLSServerCert != p.conf.HLSServerCert ||
|
2021-12-22 18:13:56 +00:00
|
|
|
newConf.ExternalAuthenticationURL != p.conf.ExternalAuthenticationURL ||
|
2021-07-29 14:56:40 +00:00
|
|
|
newConf.HLSAlwaysRemux != p.conf.HLSAlwaysRemux ||
|
2022-05-31 17:17:26 +00:00
|
|
|
newConf.HLSVariant != p.conf.HLSVariant ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.HLSSegmentCount != p.conf.HLSSegmentCount ||
|
|
|
|
newConf.HLSSegmentDuration != p.conf.HLSSegmentDuration ||
|
2022-05-31 17:17:26 +00:00
|
|
|
newConf.HLSPartDuration != p.conf.HLSPartDuration ||
|
2022-01-29 15:10:08 +00:00
|
|
|
newConf.HLSSegmentMaxSize != p.conf.HLSSegmentMaxSize ||
|
2021-07-24 13:55:42 +00:00
|
|
|
newConf.HLSAllowOrigin != p.conf.HLSAllowOrigin ||
|
2022-06-21 11:41:15 +00:00
|
|
|
!reflect.DeepEqual(newConf.HLSTrustedProxies, p.conf.HLSTrustedProxies) ||
|
2023-03-19 23:22:21 +00:00
|
|
|
newConf.HLSDirectory != p.conf.HLSDirectory ||
|
2023-04-11 18:47:19 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2021-11-05 16:29:13 +00:00
|
|
|
closePathManager ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closeMetrics ||
|
|
|
|
closeLogger
|
2022-12-15 23:50:47 +00:00
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
closeWebRTCManager := newConf == nil ||
|
2023-08-06 19:40:08 +00:00
|
|
|
newConf.WebRTC != p.conf.WebRTC ||
|
2022-12-15 23:50:47 +00:00
|
|
|
newConf.WebRTCAddress != p.conf.WebRTCAddress ||
|
2022-12-19 22:26:07 +00:00
|
|
|
newConf.WebRTCEncryption != p.conf.WebRTCEncryption ||
|
2022-12-15 23:50:47 +00:00
|
|
|
newConf.WebRTCServerKey != p.conf.WebRTCServerKey ||
|
|
|
|
newConf.WebRTCServerCert != p.conf.WebRTCServerCert ||
|
|
|
|
newConf.WebRTCAllowOrigin != p.conf.WebRTCAllowOrigin ||
|
|
|
|
!reflect.DeepEqual(newConf.WebRTCTrustedProxies, p.conf.WebRTCTrustedProxies) ||
|
2023-06-30 14:47:10 +00:00
|
|
|
!reflect.DeepEqual(newConf.WebRTCICEServers2, p.conf.WebRTCICEServers2) ||
|
2023-04-11 18:47:19 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2022-12-30 14:39:20 +00:00
|
|
|
!reflect.DeepEqual(newConf.WebRTCICEHostNAT1To1IPs, p.conf.WebRTCICEHostNAT1To1IPs) ||
|
2022-12-30 16:23:41 +00:00
|
|
|
newConf.WebRTCICEUDPMuxAddress != p.conf.WebRTCICEUDPMuxAddress ||
|
2023-08-03 21:12:05 +00:00
|
|
|
newConf.WebRTCICETCPMuxAddress != p.conf.WebRTCICETCPMuxAddress ||
|
|
|
|
closeMetrics ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
closeSRTServer := newConf == nil ||
|
|
|
|
newConf.SRT != p.conf.SRT ||
|
|
|
|
newConf.SRTAddress != p.conf.SRTAddress ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
2023-07-31 19:20:09 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
|
|
|
newConf.WriteTimeout != p.conf.WriteTimeout ||
|
2023-08-26 11:25:21 +00:00
|
|
|
newConf.WriteQueueSize != p.conf.WriteQueueSize ||
|
2023-07-31 19:20:09 +00:00
|
|
|
newConf.UDPMaxPayloadSize != p.conf.UDPMaxPayloadSize ||
|
2023-09-16 17:21:48 +00:00
|
|
|
newConf.RunOnConnect != p.conf.RunOnConnect ||
|
|
|
|
newConf.RunOnConnectRestart != p.conf.RunOnConnectRestart ||
|
|
|
|
newConf.RunOnDisconnect != p.conf.RunOnDisconnect ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeLogger
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closeAPI := newConf == nil ||
|
2021-07-04 16:13:49 +00:00
|
|
|
newConf.API != p.conf.API ||
|
|
|
|
newConf.APIAddress != p.conf.APIAddress ||
|
2023-04-11 18:47:19 +00:00
|
|
|
newConf.ReadTimeout != p.conf.ReadTimeout ||
|
2021-07-04 16:13:49 +00:00
|
|
|
closePathManager ||
|
|
|
|
closeRTSPServer ||
|
|
|
|
closeRTSPSServer ||
|
2021-11-05 16:14:31 +00:00
|
|
|
closeRTMPServer ||
|
2023-05-16 13:59:37 +00:00
|
|
|
closeHLSManager ||
|
2023-07-31 19:20:09 +00:00
|
|
|
closeWebRTCManager ||
|
2023-09-01 17:54:34 +00:00
|
|
|
closeSRTServer ||
|
|
|
|
closeLogger
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2021-12-21 11:39:32 +00:00
|
|
|
if newConf == nil && p.confWatcher != nil {
|
|
|
|
p.confWatcher.Close()
|
|
|
|
p.confWatcher = nil
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:13:49 +00:00
|
|
|
if p.api != nil {
|
|
|
|
if closeAPI {
|
|
|
|
p.api.close()
|
|
|
|
p.api = nil
|
2021-09-06 16:39:15 +00:00
|
|
|
} else if !calledByAPI { // avoid a loop
|
2022-08-04 19:07:17 +00:00
|
|
|
p.api.confReload(newConf)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
if closeSRTServer && p.srtServer != nil {
|
|
|
|
p.srtServer.close()
|
|
|
|
p.srtServer = nil
|
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
if closeWebRTCManager && p.webRTCManager != nil {
|
|
|
|
p.webRTCManager.close()
|
|
|
|
p.webRTCManager = nil
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
if closeHLSManager && p.hlsManager != nil {
|
|
|
|
p.hlsManager.close()
|
|
|
|
p.hlsManager = nil
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:53:04 +00:00
|
|
|
if closeRTMPSServer && p.rtmpsServer != nil {
|
|
|
|
p.rtmpsServer.close()
|
|
|
|
p.rtmpsServer = nil
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:13:49 +00:00
|
|
|
if closeRTMPServer && p.rtmpServer != nil {
|
2021-07-24 13:55:42 +00:00
|
|
|
p.rtmpServer.close()
|
|
|
|
p.rtmpServer = nil
|
|
|
|
}
|
|
|
|
|
2023-07-16 22:33:34 +00:00
|
|
|
if closeRTSPSServer && p.rtspsServer != nil {
|
|
|
|
p.rtspsServer.close()
|
|
|
|
p.rtspsServer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeRTSPServer && p.rtspServer != nil {
|
|
|
|
p.rtspServer.close()
|
|
|
|
p.rtspServer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closePathManager && p.pathManager != nil {
|
|
|
|
p.pathManager.close()
|
|
|
|
p.pathManager = nil
|
|
|
|
}
|
|
|
|
|
2023-09-16 15:27:07 +00:00
|
|
|
if closeRecorderCleaner && p.recordCleaner != nil {
|
|
|
|
p.recordCleaner.Close()
|
|
|
|
p.recordCleaner = nil
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
if closePPROF && p.pprof != nil {
|
|
|
|
p.pprof.close()
|
|
|
|
p.pprof = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeMetrics && p.metrics != nil {
|
|
|
|
p.metrics.close()
|
|
|
|
p.metrics = nil
|
|
|
|
}
|
|
|
|
|
2023-03-20 15:15:14 +00:00
|
|
|
if newConf == nil && p.externalCmdPool != nil {
|
2021-12-21 11:39:32 +00:00
|
|
|
p.Log(logger.Info, "waiting for external commands")
|
|
|
|
p.externalCmdPool.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeLogger {
|
2021-07-24 13:55:42 +00:00
|
|
|
p.logger.Close()
|
|
|
|
p.logger = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 16:39:15 +00:00
|
|
|
func (p *Core) reloadConf(newConf *conf.Conf, calledByAPI bool) error {
|
|
|
|
p.closeResources(newConf, calledByAPI)
|
2021-07-24 13:55:42 +00:00
|
|
|
p.conf = newConf
|
|
|
|
return p.createResources(false)
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2022-08-04 19:07:17 +00:00
|
|
|
// apiConfigSet is called by api.
|
|
|
|
func (p *Core) apiConfigSet(conf *conf.Conf) {
|
2021-07-04 16:13:49 +00:00
|
|
|
select {
|
2022-08-04 19:07:17 +00:00
|
|
|
case p.chAPIConfigSet <- conf:
|
2021-07-04 16:13:49 +00:00
|
|
|
case <-p.ctx.Done():
|
|
|
|
}
|
|
|
|
}
|