2022-09-17 19:19:45 +00:00
|
|
|
// Package conf contains the struct that holds the configuration of the software.
|
2020-10-13 22:50:08 +00:00
|
|
|
package conf
|
2020-07-12 11:16:33 +00:00
|
|
|
|
|
|
|
import (
|
2021-01-16 14:42:54 +00:00
|
|
|
"encoding/base64"
|
2021-09-26 13:50:35 +00:00
|
|
|
"encoding/json"
|
2020-07-12 11:16:33 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-09-27 12:59:27 +00:00
|
|
|
"reflect"
|
2022-12-12 10:49:11 +00:00
|
|
|
"sort"
|
2021-12-22 18:13:56 +00:00
|
|
|
"strings"
|
2020-07-12 11:16:33 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
"github.com/bluenviron/gohlslib"
|
2023-04-01 16:39:12 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v3"
|
|
|
|
"github.com/bluenviron/gortsplib/v3/pkg/headers"
|
2021-01-16 14:42:54 +00:00
|
|
|
"golang.org/x/crypto/nacl/secretbox"
|
2020-07-12 11:16:33 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
2020-10-13 21:36:27 +00:00
|
|
|
|
2023-04-01 17:52:06 +00:00
|
|
|
"github.com/aler9/mediamtx/internal/logger"
|
2020-07-12 11:16:33 +00:00
|
|
|
)
|
|
|
|
|
2021-01-16 14:42:54 +00:00
|
|
|
func decrypt(key string, byts []byte) ([]byte, error) {
|
|
|
|
enc, err := base64.StdEncoding.DecodeString(string(byts))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var secretKey [32]byte
|
|
|
|
copy(secretKey[:], key)
|
|
|
|
|
|
|
|
var decryptNonce [24]byte
|
|
|
|
copy(decryptNonce[:], enc[:24])
|
|
|
|
decrypted, ok := secretbox.Open(nil, enc[24:], &decryptNonce, &secretKey)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("decryption error")
|
|
|
|
}
|
|
|
|
|
|
|
|
return decrypted, nil
|
|
|
|
}
|
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
func loadFromFile(fpath string, conf *Conf) (bool, error) {
|
2023-04-01 17:32:10 +00:00
|
|
|
if fpath == "mediamtx.yml" {
|
|
|
|
// give priority to the legacy configuration file, in order not to break
|
|
|
|
// existing setups
|
|
|
|
if _, err := os.Stat("rtsp-simple-server.yml"); err == nil {
|
|
|
|
fpath = "rtsp-simple-server.yml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mediamtx.yml is optional
|
2021-09-26 13:50:35 +00:00
|
|
|
// other configuration files are not
|
2023-04-01 17:32:10 +00:00
|
|
|
if fpath == "mediamtx.yml" || fpath == "rtsp-simple-server.yml" {
|
2021-09-26 13:50:35 +00:00
|
|
|
if _, err := os.Stat(fpath); err != nil {
|
|
|
|
return false, nil
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
2021-09-26 13:50:35 +00:00
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2022-09-17 19:19:45 +00:00
|
|
|
byts, err := os.ReadFile(fpath)
|
2021-09-26 13:50:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
2023-04-01 17:32:10 +00:00
|
|
|
if key, ok := os.LookupEnv("RTSP_CONFKEY"); ok { // legacy format
|
|
|
|
byts, err = decrypt(key, byts)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if key, ok := os.LookupEnv("MTX_CONFKEY"); ok {
|
2021-09-26 13:50:35 +00:00
|
|
|
byts, err = decrypt(key, byts)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
2021-09-26 13:50:35 +00:00
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
// load YAML config into a generic map
|
|
|
|
var temp interface{}
|
|
|
|
err = yaml.Unmarshal(byts, &temp)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert interface{} keys into string keys to avoid JSON errors
|
2022-03-08 17:50:41 +00:00
|
|
|
var convert func(i interface{}) (interface{}, error)
|
|
|
|
convert = func(i interface{}) (interface{}, error) {
|
2021-09-26 13:50:35 +00:00
|
|
|
switch x := i.(type) {
|
|
|
|
case map[interface{}]interface{}:
|
|
|
|
m2 := map[string]interface{}{}
|
|
|
|
for k, v := range x {
|
2022-03-08 17:50:41 +00:00
|
|
|
ks, ok := k.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("integer keys are not supported (%v)", k)
|
|
|
|
}
|
|
|
|
|
|
|
|
m2[ks], err = convert(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
2022-03-08 17:50:41 +00:00
|
|
|
return m2, nil
|
2021-09-27 12:59:27 +00:00
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
case []interface{}:
|
|
|
|
a2 := make([]interface{}, len(x))
|
|
|
|
for i, v := range x {
|
2022-03-08 17:50:41 +00:00
|
|
|
a2[i], err = convert(v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-09-26 13:50:35 +00:00
|
|
|
}
|
2022-03-08 17:50:41 +00:00
|
|
|
return a2, nil
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
2021-09-27 12:59:27 +00:00
|
|
|
|
2022-03-08 17:50:41 +00:00
|
|
|
return i, nil
|
|
|
|
}
|
|
|
|
temp, err = convert(temp)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2021-09-26 13:50:35 +00:00
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2021-09-27 12:59:27 +00:00
|
|
|
// check for non-existent parameters
|
|
|
|
var checkNonExistentFields func(what interface{}, ref interface{}) error
|
|
|
|
checkNonExistentFields = func(what interface{}, ref interface{}) error {
|
|
|
|
if what == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ma, ok := what.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("not a map")
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range ma {
|
|
|
|
fi := func() reflect.Type {
|
|
|
|
rr := reflect.TypeOf(ref)
|
|
|
|
for i := 0; i < rr.NumField(); i++ {
|
|
|
|
f := rr.Field(i)
|
|
|
|
if f.Tag.Get("json") == k {
|
|
|
|
return f.Type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}()
|
|
|
|
if fi == nil {
|
|
|
|
return fmt.Errorf("non-existent parameter: '%s'", k)
|
|
|
|
}
|
|
|
|
|
|
|
|
if fi == reflect.TypeOf(map[string]*PathConf{}) && v != nil {
|
|
|
|
ma2, ok := v.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("parameter %s is not a map", k)
|
|
|
|
}
|
|
|
|
|
|
|
|
for k2, v2 := range ma2 {
|
|
|
|
err := checkNonExistentFields(v2, reflect.Zero(fi.Elem().Elem()).Interface())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("parameter %s, key %s: %s", k, k2, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = checkNonExistentFields(temp, Conf{})
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
// convert the generic map into JSON
|
|
|
|
byts, err = json.Marshal(temp)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the configuration from JSON
|
|
|
|
err = json.Unmarshal(byts, conf)
|
|
|
|
if err != nil {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conf is a configuration.
|
|
|
|
type Conf struct {
|
|
|
|
// general
|
2021-12-22 18:13:56 +00:00
|
|
|
LogLevel LogLevel `json:"logLevel"`
|
|
|
|
LogDestinations LogDestinations `json:"logDestinations"`
|
|
|
|
LogFile string `json:"logFile"`
|
|
|
|
ReadTimeout StringDuration `json:"readTimeout"`
|
|
|
|
WriteTimeout StringDuration `json:"writeTimeout"`
|
|
|
|
ReadBufferCount int `json:"readBufferCount"`
|
2023-03-31 09:53:49 +00:00
|
|
|
UDPMaxPayloadSize int `json:"udpMaxPayloadSize"`
|
2021-12-22 18:13:56 +00:00
|
|
|
ExternalAuthenticationURL string `json:"externalAuthenticationURL"`
|
|
|
|
API bool `json:"api"`
|
|
|
|
APIAddress string `json:"apiAddress"`
|
|
|
|
Metrics bool `json:"metrics"`
|
|
|
|
MetricsAddress string `json:"metricsAddress"`
|
|
|
|
PPROF bool `json:"pprof"`
|
|
|
|
PPROFAddress string `json:"pprofAddress"`
|
|
|
|
RunOnConnect string `json:"runOnConnect"`
|
|
|
|
RunOnConnectRestart bool `json:"runOnConnectRestart"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
|
|
|
// RTSP
|
2021-09-27 08:36:28 +00:00
|
|
|
RTSPDisable bool `json:"rtspDisable"`
|
|
|
|
Protocols Protocols `json:"protocols"`
|
|
|
|
Encryption Encryption `json:"encryption"`
|
|
|
|
RTSPAddress string `json:"rtspAddress"`
|
|
|
|
RTSPSAddress string `json:"rtspsAddress"`
|
|
|
|
RTPAddress string `json:"rtpAddress"`
|
|
|
|
RTCPAddress string `json:"rtcpAddress"`
|
|
|
|
MulticastIPRange string `json:"multicastIPRange"`
|
|
|
|
MulticastRTPPort int `json:"multicastRTPPort"`
|
|
|
|
MulticastRTCPPort int `json:"multicastRTCPPort"`
|
|
|
|
ServerKey string `json:"serverKey"`
|
|
|
|
ServerCert string `json:"serverCert"`
|
|
|
|
AuthMethods AuthMethods `json:"authMethods"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
|
|
|
// RTMP
|
2022-08-16 11:53:04 +00:00
|
|
|
RTMPDisable bool `json:"rtmpDisable"`
|
|
|
|
RTMPAddress string `json:"rtmpAddress"`
|
|
|
|
RTMPEncryption Encryption `json:"rtmpEncryption"`
|
|
|
|
RTMPSAddress string `json:"rtmpsAddress"`
|
|
|
|
RTMPServerKey string `json:"rtmpServerKey"`
|
|
|
|
RTMPServerCert string `json:"rtmpServerCert"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
|
|
|
// HLS
|
|
|
|
HLSDisable bool `json:"hlsDisable"`
|
|
|
|
HLSAddress string `json:"hlsAddress"`
|
2022-12-15 23:50:47 +00:00
|
|
|
HLSEncryption bool `json:"hlsEncryption"`
|
|
|
|
HLSServerKey string `json:"hlsServerKey"`
|
|
|
|
HLSServerCert string `json:"hlsServerCert"`
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
|
2022-05-31 17:17:26 +00:00
|
|
|
HLSVariant HLSVariant `json:"hlsVariant"`
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSSegmentCount int `json:"hlsSegmentCount"`
|
|
|
|
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
|
2022-05-31 17:17:26 +00:00
|
|
|
HLSPartDuration StringDuration `json:"hlsPartDuration"`
|
2022-01-29 15:10:08 +00:00
|
|
|
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSAllowOrigin string `json:"hlsAllowOrigin"`
|
2022-06-21 11:41:15 +00:00
|
|
|
HLSTrustedProxies IPsOrCIDRs `json:"hlsTrustedProxies"`
|
2023-03-19 23:22:21 +00:00
|
|
|
HLSDirectory string `json:"hlsDirectory"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// WebRTC
|
2022-12-30 14:39:20 +00:00
|
|
|
WebRTCDisable bool `json:"webrtcDisable"`
|
|
|
|
WebRTCAddress string `json:"webrtcAddress"`
|
|
|
|
WebRTCEncryption bool `json:"webrtcEncryption"`
|
|
|
|
WebRTCServerKey string `json:"webrtcServerKey"`
|
|
|
|
WebRTCServerCert string `json:"webrtcServerCert"`
|
|
|
|
WebRTCAllowOrigin string `json:"webrtcAllowOrigin"`
|
|
|
|
WebRTCTrustedProxies IPsOrCIDRs `json:"webrtcTrustedProxies"`
|
|
|
|
WebRTCICEServers []string `json:"webrtcICEServers"`
|
|
|
|
WebRTCICEHostNAT1To1IPs []string `json:"webrtcICEHostNAT1To1IPs"`
|
2022-12-30 16:23:41 +00:00
|
|
|
WebRTCICEUDPMuxAddress string `json:"webrtcICEUDPMuxAddress"`
|
2022-12-30 14:39:20 +00:00
|
|
|
WebRTCICETCPMuxAddress string `json:"webrtcICETCPMuxAddress"`
|
2022-12-15 23:50:47 +00:00
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
// paths
|
|
|
|
Paths map[string]*PathConf `json:"paths"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load loads a Conf.
|
|
|
|
func Load(fpath string) (*Conf, bool, error) {
|
|
|
|
conf := &Conf{}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
found, err := loadFromFile(fpath, conf)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
|
2023-04-01 17:31:23 +00:00
|
|
|
err = loadFromEnvironment("RTSP", conf) // legacy prefix
|
|
|
|
if err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = loadFromEnvironment("MTX", conf)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = conf.CheckAndFillMissing()
|
|
|
|
if err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf, found, nil
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
// Clone clones the configuration.
|
|
|
|
func (conf Conf) Clone() *Conf {
|
|
|
|
enc, err := json.Marshal(conf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var dest Conf
|
|
|
|
err = json.Unmarshal(enc, &dest)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &dest
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:59:27 +00:00
|
|
|
// CheckAndFillMissing checks the configuration for errors and fills missing parameters.
|
2021-07-04 16:13:49 +00:00
|
|
|
func (conf *Conf) CheckAndFillMissing() error {
|
2022-12-15 23:50:47 +00:00
|
|
|
// general
|
2021-09-27 08:36:28 +00:00
|
|
|
if conf.LogLevel == 0 {
|
|
|
|
conf.LogLevel = LogLevel(logger.Info)
|
2020-12-08 11:21:06 +00:00
|
|
|
}
|
|
|
|
if len(conf.LogDestinations) == 0 {
|
2021-09-27 08:36:28 +00:00
|
|
|
conf.LogDestinations = LogDestinations{logger.DestinationStdout: {}}
|
2020-12-08 11:21:06 +00:00
|
|
|
}
|
|
|
|
if conf.LogFile == "" {
|
2023-04-01 17:52:06 +00:00
|
|
|
conf.LogFile = "mediamtx.log"
|
2020-12-08 11:21:06 +00:00
|
|
|
}
|
2021-02-03 08:55:11 +00:00
|
|
|
if conf.ReadTimeout == 0 {
|
2021-09-26 21:06:40 +00:00
|
|
|
conf.ReadTimeout = 10 * StringDuration(time.Second)
|
2021-02-03 08:55:11 +00:00
|
|
|
}
|
|
|
|
if conf.WriteTimeout == 0 {
|
2021-09-26 21:06:40 +00:00
|
|
|
conf.WriteTimeout = 10 * StringDuration(time.Second)
|
2021-02-03 08:55:11 +00:00
|
|
|
}
|
|
|
|
if conf.ReadBufferCount == 0 {
|
|
|
|
conf.ReadBufferCount = 512
|
|
|
|
}
|
2022-07-05 21:45:57 +00:00
|
|
|
if (conf.ReadBufferCount & (conf.ReadBufferCount - 1)) != 0 {
|
2023-03-31 09:53:49 +00:00
|
|
|
return fmt.Errorf("'readBufferCount' must be a power of two")
|
|
|
|
}
|
|
|
|
if conf.UDPMaxPayloadSize == 0 {
|
2023-04-15 11:45:20 +00:00
|
|
|
conf.UDPMaxPayloadSize = 1472
|
2023-03-31 09:53:49 +00:00
|
|
|
}
|
2023-04-15 11:45:20 +00:00
|
|
|
if conf.UDPMaxPayloadSize > 1472 {
|
|
|
|
return fmt.Errorf("'udpMaxPayloadSize' must be less than 1472")
|
2022-07-05 21:45:57 +00:00
|
|
|
}
|
2021-12-22 18:13:56 +00:00
|
|
|
if conf.ExternalAuthenticationURL != "" {
|
|
|
|
if !strings.HasPrefix(conf.ExternalAuthenticationURL, "http://") &&
|
|
|
|
!strings.HasPrefix(conf.ExternalAuthenticationURL, "https://") {
|
|
|
|
return fmt.Errorf("'externalAuthenticationURL' must be a HTTP URL")
|
|
|
|
}
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
if conf.APIAddress == "" {
|
2021-08-07 16:32:22 +00:00
|
|
|
conf.APIAddress = "127.0.0.1:9997"
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.MetricsAddress == "" {
|
2021-08-07 17:06:38 +00:00
|
|
|
conf.MetricsAddress = "127.0.0.1:9998"
|
2021-03-13 17:22:02 +00:00
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.PPROFAddress == "" {
|
2021-08-07 17:06:38 +00:00
|
|
|
conf.PPROFAddress = "127.0.0.1:9999"
|
2021-03-27 10:21:30 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// RTSP
|
2020-07-12 11:16:33 +00:00
|
|
|
if len(conf.Protocols) == 0 {
|
2021-09-27 08:36:28 +00:00
|
|
|
conf.Protocols = Protocols{
|
2021-10-22 16:41:10 +00:00
|
|
|
Protocol(gortsplib.TransportUDP): {},
|
|
|
|
Protocol(gortsplib.TransportUDPMulticast): {},
|
|
|
|
Protocol(gortsplib.TransportTCP): {},
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-27 08:36:28 +00:00
|
|
|
if conf.Encryption == EncryptionStrict {
|
2021-10-22 16:41:10 +00:00
|
|
|
if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDP)]; ok {
|
2021-11-05 16:11:40 +00:00
|
|
|
return fmt.Errorf("strict encryption can't be used with the UDP transport protocol")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDPMulticast)]; ok {
|
|
|
|
return fmt.Errorf("strict encryption can't be used with the UDP-multicast transport protocol")
|
2020-12-13 22:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.RTSPAddress == "" {
|
|
|
|
conf.RTSPAddress = ":8554"
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.RTSPSAddress == "" {
|
2022-04-16 14:24:40 +00:00
|
|
|
conf.RTSPSAddress = ":8322"
|
2020-12-13 22:43:31 +00:00
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.RTPAddress == "" {
|
|
|
|
conf.RTPAddress = ":8000"
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.RTCPAddress == "" {
|
|
|
|
conf.RTCPAddress = ":8001"
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2021-06-19 17:20:41 +00:00
|
|
|
if conf.MulticastIPRange == "" {
|
|
|
|
conf.MulticastIPRange = "224.1.0.0/16"
|
|
|
|
}
|
|
|
|
if conf.MulticastRTPPort == 0 {
|
|
|
|
conf.MulticastRTPPort = 8002
|
|
|
|
}
|
|
|
|
if conf.MulticastRTCPPort == 0 {
|
|
|
|
conf.MulticastRTCPPort = 8003
|
|
|
|
}
|
2020-12-13 22:43:31 +00:00
|
|
|
if conf.ServerKey == "" {
|
|
|
|
conf.ServerKey = "server.key"
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2020-12-13 22:43:31 +00:00
|
|
|
if conf.ServerCert == "" {
|
|
|
|
conf.ServerCert = "server.crt"
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
|
|
|
if len(conf.AuthMethods) == 0 {
|
2021-09-27 08:36:28 +00:00
|
|
|
conf.AuthMethods = AuthMethods{headers.AuthBasic, headers.AuthDigest}
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// RTMP
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.RTMPAddress == "" {
|
|
|
|
conf.RTMPAddress = ":1935"
|
2021-01-31 12:18:05 +00:00
|
|
|
}
|
2022-08-16 11:53:04 +00:00
|
|
|
if conf.RTMPSAddress == "" {
|
|
|
|
conf.RTMPSAddress = ":1936"
|
|
|
|
}
|
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// HLS
|
2021-04-24 16:25:19 +00:00
|
|
|
if conf.HLSAddress == "" {
|
|
|
|
conf.HLSAddress = ":8888"
|
2021-04-11 17:05:08 +00:00
|
|
|
}
|
2022-12-15 23:50:47 +00:00
|
|
|
if conf.HLSServerKey == "" {
|
|
|
|
conf.HLSServerKey = "server.key"
|
|
|
|
}
|
|
|
|
if conf.HLSServerCert == "" {
|
|
|
|
conf.HLSServerCert = "server.crt"
|
|
|
|
}
|
2023-03-31 14:46:05 +00:00
|
|
|
if conf.HLSVariant == 0 {
|
|
|
|
conf.HLSVariant = HLSVariant(gohlslib.MuxerVariantLowLatency)
|
|
|
|
}
|
2021-04-11 17:05:08 +00:00
|
|
|
if conf.HLSSegmentCount == 0 {
|
2022-05-31 17:17:26 +00:00
|
|
|
conf.HLSSegmentCount = 7
|
2021-04-11 17:05:08 +00:00
|
|
|
}
|
|
|
|
if conf.HLSSegmentDuration == 0 {
|
2021-09-26 21:06:40 +00:00
|
|
|
conf.HLSSegmentDuration = 1 * StringDuration(time.Second)
|
2021-04-11 17:05:08 +00:00
|
|
|
}
|
2022-05-31 17:17:26 +00:00
|
|
|
if conf.HLSPartDuration == 0 {
|
|
|
|
conf.HLSPartDuration = 200 * StringDuration(time.Millisecond)
|
|
|
|
}
|
2022-01-29 15:10:08 +00:00
|
|
|
if conf.HLSSegmentMaxSize == 0 {
|
|
|
|
conf.HLSSegmentMaxSize = 50 * 1024 * 1024
|
|
|
|
}
|
2021-06-23 17:28:27 +00:00
|
|
|
if conf.HLSAllowOrigin == "" {
|
|
|
|
conf.HLSAllowOrigin = "*"
|
|
|
|
}
|
2022-05-31 17:17:26 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// WebRTC
|
|
|
|
if conf.WebRTCAddress == "" {
|
|
|
|
conf.WebRTCAddress = ":8889"
|
|
|
|
}
|
|
|
|
if conf.WebRTCServerKey == "" {
|
|
|
|
conf.WebRTCServerKey = "server.key"
|
|
|
|
}
|
|
|
|
if conf.WebRTCServerCert == "" {
|
|
|
|
conf.WebRTCServerCert = "server.crt"
|
|
|
|
}
|
|
|
|
if conf.WebRTCAllowOrigin == "" {
|
|
|
|
conf.WebRTCAllowOrigin = "*"
|
|
|
|
}
|
|
|
|
if conf.WebRTCICEServers == nil {
|
|
|
|
conf.WebRTCICEServers = []string{"stun:stun.l.google.com:19302"}
|
|
|
|
}
|
|
|
|
|
2021-11-06 11:51:38 +00:00
|
|
|
// do not add automatically "all", since user may want to
|
|
|
|
// initialize all paths through API or hot reloading.
|
|
|
|
if conf.Paths == nil {
|
|
|
|
conf.Paths = make(map[string]*PathConf)
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 15:13:45 +00:00
|
|
|
// "all" is an alias for "~^.*$"
|
|
|
|
if _, ok := conf.Paths["all"]; ok {
|
|
|
|
conf.Paths["~^.*$"] = conf.Paths["all"]
|
|
|
|
delete(conf.Paths, "all")
|
|
|
|
}
|
|
|
|
|
2022-12-12 10:49:11 +00:00
|
|
|
sortedNames := make([]string, len(conf.Paths))
|
|
|
|
i := 0
|
|
|
|
for name := range conf.Paths {
|
|
|
|
sortedNames[i] = name
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
sort.Strings(sortedNames)
|
|
|
|
|
|
|
|
for _, name := range sortedNames {
|
|
|
|
pconf := conf.Paths[name]
|
2020-09-19 15:13:45 +00:00
|
|
|
if pconf == nil {
|
2022-12-12 10:49:11 +00:00
|
|
|
pconf = &PathConf{}
|
|
|
|
conf.Paths[name] = pconf
|
2020-07-13 09:51:17 +00:00
|
|
|
}
|
|
|
|
|
2021-12-22 18:13:56 +00:00
|
|
|
err := pconf.checkAndFillMissing(conf, name)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
2020-07-12 11:16:33 +00:00
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
return nil
|
|
|
|
}
|