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-10-07 21:48:37 +00:00
|
|
|
"sort"
|
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-12-26 12:41:15 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/api"
|
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-12-26 12:41:15 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/metrics"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/pprof"
|
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"
|
2023-12-08 18:17:17 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/hls"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/rtmp"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/rtsp"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/srt"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/servers/webrtc"
|
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-10-07 21:48:37 +00:00
|
|
|
func gatherCleanerEntries(paths map[string]*conf.Path) []record.CleanerEntry {
|
|
|
|
out := make(map[record.CleanerEntry]struct{})
|
|
|
|
|
|
|
|
for _, pa := range paths {
|
2023-11-10 12:51:52 +00:00
|
|
|
if pa.Record && pa.RecordDeleteAfter != 0 {
|
2023-10-07 21:48:37 +00:00
|
|
|
entry := record.CleanerEntry{
|
2023-12-02 14:35:21 +00:00
|
|
|
PathFormat: pa.RecordPath,
|
|
|
|
Format: pa.RecordFormat,
|
|
|
|
DeleteAfter: time.Duration(pa.RecordDeleteAfter),
|
2023-10-07 21:48:37 +00:00
|
|
|
}
|
|
|
|
out[entry] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out2 := make([]record.CleanerEntry, len(out))
|
|
|
|
i := 0
|
|
|
|
|
|
|
|
for v := range out {
|
|
|
|
out2[i] = v
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(out2, func(i, j int) bool {
|
2023-12-02 14:35:21 +00:00
|
|
|
if out2[i].PathFormat != out2[j].PathFormat {
|
|
|
|
return out2[i].PathFormat < out2[j].PathFormat
|
2023-10-07 21:48:37 +00:00
|
|
|
}
|
2023-12-02 14:15:17 +00:00
|
|
|
return out2[i].DeleteAfter < out2[j].DeleteAfter
|
2023-10-07 21:48:37 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return out2
|
|
|
|
}
|
|
|
|
|
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-10-31 13:19:04 +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
|
2023-12-26 12:41:15 +00:00
|
|
|
metrics *metrics.Metrics
|
|
|
|
pprof *pprof.PPROF
|
2023-09-16 15:27:07 +00:00
|
|
|
recordCleaner *record.Cleaner
|
2021-12-21 11:39:32 +00:00
|
|
|
pathManager *pathManager
|
2023-12-08 18:17:17 +00:00
|
|
|
rtspServer *rtsp.Server
|
|
|
|
rtspsServer *rtsp.Server
|
|
|
|
rtmpServer *rtmp.Server
|
|
|
|
rtmpsServer *rtmp.Server
|
|
|
|
hlsServer *hls.Server
|
|
|
|
webRTCServer *webrtc.Server
|
|
|
|
srtServer *srt.Server
|
2023-12-26 12:41:15 +00:00
|
|
|
api *api.API
|
2021-12-21 11:39:32 +00:00
|
|
|
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{}
|
|
|
|
}
|
|
|
|
|
2023-10-31 13:19:04 +00:00
|
|
|
// New allocates a Core.
|
2021-07-24 13:55:42 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
// Log implements logger.Writer.
|
2021-07-24 13:55:42 +00:00
|
|
|
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
|
|
|
|
2023-10-01 20:56:51 +00:00
|
|
|
if p.confPath != "" {
|
|
|
|
a, _ := filepath.Abs(p.confPath)
|
|
|
|
p.Log(logger.Info, "configuration loaded from %s", a)
|
|
|
|
} else {
|
2023-09-16 20:14:13 +00:00
|
|
|
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
|
2023-10-01 20:56:51 +00:00
|
|
|
// to allow the maximum possible number of clients.
|
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 {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics = &metrics.Metrics{
|
2023-12-03 15:59:35 +00:00
|
|
|
Address: p.conf.MetricsAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
Parent: p,
|
|
|
|
}
|
2023-12-26 12:41:15 +00:00
|
|
|
err := p.metrics.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
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 {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.pprof = &pprof.PPROF{
|
|
|
|
Address: p.conf.PPROFAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.pprof.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:48:37 +00:00
|
|
|
cleanerEntries := gatherCleanerEntries(p.conf.Paths)
|
|
|
|
if len(cleanerEntries) != 0 &&
|
2023-09-16 15:27:07 +00:00
|
|
|
p.recordCleaner == nil {
|
2023-12-02 14:15:17 +00:00
|
|
|
p.recordCleaner = &record.Cleaner{
|
|
|
|
Entries: cleanerEntries,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
p.recordCleaner.Initialize()
|
2023-09-16 15:27:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 12:49:09 +00:00
|
|
|
if p.pathManager == nil {
|
|
|
|
p.pathManager = newPathManager(
|
2023-12-15 11:10:16 +00:00
|
|
|
p.conf.LogLevel,
|
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,
|
2021-07-24 13:55:42 +00:00
|
|
|
p.conf.Paths,
|
2021-12-22 18:13:56 +00:00
|
|
|
p.externalCmdPool,
|
2022-12-15 23:50:47 +00:00
|
|
|
p,
|
|
|
|
)
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetPathManager(p.pathManager)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
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)]
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtspServer = &rtsp.Server{
|
|
|
|
Address: p.conf.RTSPAddress,
|
|
|
|
AuthMethods: p.conf.AuthMethods,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteTimeout: p.conf.WriteTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
UseUDP: useUDP,
|
|
|
|
UseMulticast: useMulticast,
|
|
|
|
RTPAddress: p.conf.RTPAddress,
|
|
|
|
RTCPAddress: p.conf.RTCPAddress,
|
|
|
|
MulticastIPRange: p.conf.MulticastIPRange,
|
|
|
|
MulticastRTPPort: p.conf.MulticastRTPPort,
|
|
|
|
MulticastRTCPPort: p.conf.MulticastRTCPPort,
|
|
|
|
IsTLS: false,
|
|
|
|
ServerCert: "",
|
|
|
|
ServerKey: "",
|
|
|
|
RTSPAddress: p.conf.RTSPAddress,
|
|
|
|
Protocols: p.conf.Protocols,
|
|
|
|
RunOnConnect: p.conf.RunOnConnect,
|
|
|
|
RunOnConnectRestart: p.conf.RunOnConnectRestart,
|
|
|
|
RunOnDisconnect: p.conf.RunOnDisconnect,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.rtspServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTSPServer(p.rtspServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
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 {
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtspsServer = &rtsp.Server{
|
|
|
|
Address: p.conf.RTSPSAddress,
|
|
|
|
AuthMethods: p.conf.AuthMethods,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteTimeout: p.conf.WriteTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
UseUDP: false,
|
|
|
|
UseMulticast: false,
|
|
|
|
RTPAddress: "",
|
|
|
|
RTCPAddress: "",
|
|
|
|
MulticastIPRange: "",
|
|
|
|
MulticastRTPPort: 0,
|
|
|
|
MulticastRTCPPort: 0,
|
|
|
|
IsTLS: true,
|
|
|
|
ServerCert: p.conf.ServerCert,
|
|
|
|
ServerKey: p.conf.ServerKey,
|
|
|
|
RTSPAddress: p.conf.RTSPAddress,
|
|
|
|
Protocols: p.conf.Protocols,
|
|
|
|
RunOnConnect: p.conf.RunOnConnect,
|
|
|
|
RunOnConnectRestart: p.conf.RunOnConnectRestart,
|
|
|
|
RunOnDisconnect: p.conf.RunOnDisconnect,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.rtspsServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTSPSServer(p.rtspsServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
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 {
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtmpServer = &rtmp.Server{
|
|
|
|
Address: p.conf.RTMPAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteTimeout: p.conf.WriteTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
IsTLS: false,
|
|
|
|
ServerCert: "",
|
|
|
|
ServerKey: "",
|
|
|
|
RTSPAddress: p.conf.RTSPAddress,
|
|
|
|
RunOnConnect: p.conf.RunOnConnect,
|
|
|
|
RunOnConnectRestart: p.conf.RunOnConnectRestart,
|
|
|
|
RunOnDisconnect: p.conf.RunOnDisconnect,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.rtmpServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-08-16 11:53:04 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTMPServer(p.rtmpServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
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 {
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtmpsServer = &rtmp.Server{
|
|
|
|
Address: p.conf.RTMPSAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteTimeout: p.conf.WriteTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
IsTLS: true,
|
|
|
|
ServerCert: p.conf.RTMPServerCert,
|
|
|
|
ServerKey: p.conf.RTMPServerKey,
|
|
|
|
RTSPAddress: p.conf.RTSPAddress,
|
|
|
|
RunOnConnect: p.conf.RunOnConnect,
|
|
|
|
RunOnConnectRestart: p.conf.RunOnConnectRestart,
|
|
|
|
RunOnDisconnect: p.conf.RunOnDisconnect,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.rtmpsServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
2023-12-03 15:59:35 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTMPSServer(p.rtmpsServer)
|
2023-12-03 15:59:35 +00:00
|
|
|
}
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.HLS &&
|
2023-12-08 18:17:17 +00:00
|
|
|
p.hlsServer == nil {
|
|
|
|
p.hlsServer = &hls.Server{
|
|
|
|
Address: p.conf.HLSAddress,
|
|
|
|
Encryption: p.conf.HLSEncryption,
|
|
|
|
ServerKey: p.conf.HLSServerKey,
|
|
|
|
ServerCert: p.conf.HLSServerCert,
|
|
|
|
ExternalAuthenticationURL: p.conf.ExternalAuthenticationURL,
|
|
|
|
AlwaysRemux: p.conf.HLSAlwaysRemux,
|
|
|
|
Variant: p.conf.HLSVariant,
|
|
|
|
SegmentCount: p.conf.HLSSegmentCount,
|
|
|
|
SegmentDuration: p.conf.HLSSegmentDuration,
|
|
|
|
PartDuration: p.conf.HLSPartDuration,
|
|
|
|
SegmentMaxSize: p.conf.HLSSegmentMaxSize,
|
|
|
|
AllowOrigin: p.conf.HLSAllowOrigin,
|
|
|
|
TrustedProxies: p.conf.HLSTrustedProxies,
|
|
|
|
Directory: p.conf.HLSDirectory,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.hlsServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.pathManager.setHLSServer(p.hlsServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetHLSServer(p.hlsServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.WebRTC &&
|
2023-12-08 18:17:17 +00:00
|
|
|
p.webRTCServer == nil {
|
|
|
|
p.webRTCServer = &webrtc.Server{
|
2023-11-12 22:55:28 +00:00
|
|
|
Address: p.conf.WebRTCAddress,
|
|
|
|
Encryption: p.conf.WebRTCEncryption,
|
|
|
|
ServerKey: p.conf.WebRTCServerKey,
|
|
|
|
ServerCert: p.conf.WebRTCServerCert,
|
|
|
|
AllowOrigin: p.conf.WebRTCAllowOrigin,
|
|
|
|
TrustedProxies: p.conf.WebRTCTrustedProxies,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
LocalUDPAddress: p.conf.WebRTCLocalUDPAddress,
|
|
|
|
LocalTCPAddress: p.conf.WebRTCLocalTCPAddress,
|
|
|
|
IPsFromInterfaces: p.conf.WebRTCIPsFromInterfaces,
|
|
|
|
IPsFromInterfacesList: p.conf.WebRTCIPsFromInterfacesList,
|
|
|
|
AdditionalHosts: p.conf.WebRTCAdditionalHosts,
|
|
|
|
ICEServers: p.conf.WebRTCICEServers2,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
2023-12-26 12:41:15 +00:00
|
|
|
err := p.webRTCServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
2023-12-08 18:17:17 +00:00
|
|
|
p.webRTCServer = nil
|
2023-08-26 16:54:28 +00:00
|
|
|
return err
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetWebRTCServer(p.webRTCServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.SRT &&
|
|
|
|
p.srtServer == nil {
|
2023-12-08 18:17:17 +00:00
|
|
|
p.srtServer = &srt.Server{
|
|
|
|
Address: p.conf.SRTAddress,
|
|
|
|
RTSPAddress: p.conf.RTSPAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
WriteTimeout: p.conf.WriteTimeout,
|
|
|
|
WriteQueueSize: p.conf.WriteQueueSize,
|
|
|
|
UDPMaxPayloadSize: p.conf.UDPMaxPayloadSize,
|
|
|
|
RunOnConnect: p.conf.RunOnConnect,
|
|
|
|
RunOnConnectRestart: p.conf.RunOnConnectRestart,
|
|
|
|
RunOnDisconnect: p.conf.RunOnDisconnect,
|
|
|
|
ExternalCmdPool: p.externalCmdPool,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
Parent: p,
|
|
|
|
}
|
2023-12-26 12:41:15 +00:00
|
|
|
err := p.srtServer.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
2023-12-03 15:42:12 +00:00
|
|
|
|
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetSRTServer(p.srtServer)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 16:54:28 +00:00
|
|
|
if p.conf.API &&
|
|
|
|
p.api == nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.api = &api.API{
|
|
|
|
Address: p.conf.APIAddress,
|
|
|
|
ReadTimeout: p.conf.ReadTimeout,
|
|
|
|
Conf: p.conf,
|
|
|
|
PathManager: p.pathManager,
|
|
|
|
RTSPServer: p.rtspServer,
|
|
|
|
RTSPSServer: p.rtspsServer,
|
|
|
|
RTMPServer: p.rtmpServer,
|
|
|
|
RTMPSServer: p.rtmpsServer,
|
|
|
|
HLSServer: p.hlsServer,
|
|
|
|
WebRTCServer: p.webRTCServer,
|
|
|
|
SRTServer: p.srtServer,
|
|
|
|
Parent: p,
|
|
|
|
}
|
|
|
|
err := p.api.Initialize()
|
2023-08-26 16:54:28 +00:00
|
|
|
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 ||
|
2023-10-07 21:48:37 +00:00
|
|
|
!reflect.DeepEqual(gatherCleanerEntries(newConf.Paths), gatherCleanerEntries(p.conf.Paths)) ||
|
|
|
|
closeLogger
|
2023-09-16 15:27:07 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
closePathManager := newConf == nil ||
|
2023-12-15 11:10:16 +00:00
|
|
|
newConf.LogLevel != p.conf.LogLevel ||
|
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-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) {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.pathManager.ReloadConf(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-12-08 18:17:17 +00:00
|
|
|
closeHLSServer := 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-12-08 18:17:17 +00:00
|
|
|
closeWebRTCServer := 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-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 ||
|
2023-11-12 22:55:28 +00:00
|
|
|
newConf.WebRTCLocalUDPAddress != p.conf.WebRTCLocalUDPAddress ||
|
|
|
|
newConf.WebRTCLocalTCPAddress != p.conf.WebRTCLocalTCPAddress ||
|
|
|
|
newConf.WebRTCIPsFromInterfaces != p.conf.WebRTCIPsFromInterfaces ||
|
|
|
|
!reflect.DeepEqual(newConf.WebRTCIPsFromInterfacesList, p.conf.WebRTCIPsFromInterfacesList) ||
|
|
|
|
!reflect.DeepEqual(newConf.WebRTCAdditionalHosts, p.conf.WebRTCAdditionalHosts) ||
|
|
|
|
!reflect.DeepEqual(newConf.WebRTCICEServers2, p.conf.WebRTCICEServers2) ||
|
2023-08-03 21:12:05 +00:00
|
|
|
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-12-08 18:17:17 +00:00
|
|
|
closeHLSServer ||
|
|
|
|
closeWebRTCServer ||
|
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 {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.api.Close()
|
2021-07-04 16:13:49 +00:00
|
|
|
p.api = nil
|
2021-09-06 16:39:15 +00:00
|
|
|
} else if !calledByAPI { // avoid a loop
|
2023-12-26 12:41:15 +00:00
|
|
|
p.api.ReloadConf(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 {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetSRTServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.srtServer.Close()
|
2023-07-31 19:20:09 +00:00
|
|
|
p.srtServer = nil
|
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
if closeWebRTCServer && p.webRTCServer != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetWebRTCServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.webRTCServer.Close()
|
|
|
|
p.webRTCServer = nil
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
if closeHLSServer && p.hlsServer != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetHLSServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.pathManager.setHLSServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.hlsServer.Close()
|
|
|
|
p.hlsServer = nil
|
2021-07-24 13:55:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:53:04 +00:00
|
|
|
if closeRTMPSServer && p.rtmpsServer != nil {
|
2023-12-03 15:59:35 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTMPSServer(nil)
|
2023-12-03 15:59:35 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtmpsServer.Close()
|
2022-08-16 11:53:04 +00:00
|
|
|
p.rtmpsServer = nil
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:13:49 +00:00
|
|
|
if closeRTMPServer && p.rtmpServer != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTMPServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtmpServer.Close()
|
2021-07-24 13:55:42 +00:00
|
|
|
p.rtmpServer = nil
|
|
|
|
}
|
|
|
|
|
2023-07-16 22:33:34 +00:00
|
|
|
if closeRTSPSServer && p.rtspsServer != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTSPSServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtspsServer.Close()
|
2023-07-16 22:33:34 +00:00
|
|
|
p.rtspsServer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeRTSPServer && p.rtspServer != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetRTSPServer(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-08 18:17:17 +00:00
|
|
|
p.rtspServer.Close()
|
2023-07-16 22:33:34 +00:00
|
|
|
p.rtspServer = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closePathManager && p.pathManager != nil {
|
2023-12-03 15:42:12 +00:00
|
|
|
if p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.SetPathManager(nil)
|
2023-12-03 15:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 22:33:34 +00:00
|
|
|
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 {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.pprof.Close()
|
2021-07-24 13:55:42 +00:00
|
|
|
p.pprof = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if closeMetrics && p.metrics != nil {
|
2023-12-26 12:41:15 +00:00
|
|
|
p.metrics.Close()
|
2021-07-24 13:55:42 +00:00
|
|
|
p.metrics = nil
|
|
|
|
}
|
|
|
|
|
2023-03-20 15:15:14 +00:00
|
|
|
if newConf == nil && p.externalCmdPool != nil {
|
2023-09-23 10:49:08 +00:00
|
|
|
p.Log(logger.Info, "waiting for running hooks")
|
2021-12-21 11:39:32 +00:00
|
|
|
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
|
|
|
|
2023-12-26 12:41:15 +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():
|
|
|
|
}
|
|
|
|
}
|