Browse Source

split configuration into sections

pull/235/head
aler9 6 years ago
parent
commit
a047fdc404
  1. 78
      internal/conf/conf.go
  2. 60
      rtsp-simple-server.yml

78
internal/conf/conf.go

@ -47,34 +47,37 @@ func decrypt(key string, byts []byte) ([]byte, error) {
// Conf is the main program configuration. // Conf is the main program configuration.
type Conf struct { type Conf struct {
LogLevel string `yaml:"logLevel"` LogLevel string `yaml:"logLevel"`
LogLevelParsed logger.Level `yaml:"-" json:"-"` LogLevelParsed logger.Level `yaml:"-" json:"-"`
LogDestinations []string `yaml:"logDestinations"` LogDestinations []string `yaml:"logDestinations"`
LogDestinationsParsed map[logger.Destination]struct{} `yaml:"-" json:"-"` LogDestinationsParsed map[logger.Destination]struct{} `yaml:"-" json:"-"`
LogFile string `yaml:"logFile"` LogFile string `yaml:"logFile"`
ListenIP string `yaml:"listenIP"` ListenIP string `yaml:"listenIP"`
Protocols []string `yaml:"protocols"` ReadTimeout time.Duration `yaml:"readTimeout"`
ProtocolsParsed map[gortsplib.StreamProtocol]struct{} `yaml:"-" json:"-"` WriteTimeout time.Duration `yaml:"writeTimeout"`
Encryption string `yaml:"encryption"` ReadBufferCount uint64 `yaml:"readBufferCount"`
EncryptionParsed Encryption `yaml:"-" json:"-"` Metrics bool `yaml:"metrics"`
RTSPPort int `yaml:"rtspPort"` Pprof bool `yaml:"pprof"`
RTSPSPort int `yaml:"rtspsPort"` RunOnConnect string `yaml:"runOnConnect"`
RTPPort int `yaml:"rtpPort"` RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
RTCPPort int `yaml:"rtcpPort"`
ServerKey string `yaml:"serverKey"` Protocols []string `yaml:"protocols"`
ServerCert string `yaml:"serverCert"` ProtocolsParsed map[gortsplib.StreamProtocol]struct{} `yaml:"-" json:"-"`
AuthMethods []string `yaml:"authMethods"` Encryption string `yaml:"encryption"`
AuthMethodsParsed []headers.AuthMethod `yaml:"-" json:"-"` EncryptionParsed Encryption `yaml:"-" json:"-"`
ReadTimeout time.Duration `yaml:"readTimeout"` RTSPPort int `yaml:"rtspPort"`
WriteTimeout time.Duration `yaml:"writeTimeout"` RTSPSPort int `yaml:"rtspsPort"`
ReadBufferCount uint64 `yaml:"readBufferCount"` RTPPort int `yaml:"rtpPort"`
RTMPEnable bool `yaml:"rtmpEnable"` RTCPPort int `yaml:"rtcpPort"`
RTMPPort int `yaml:"rtmpPort"` ServerKey string `yaml:"serverKey"`
Metrics bool `yaml:"metrics"` ServerCert string `yaml:"serverCert"`
Pprof bool `yaml:"pprof"` AuthMethods []string `yaml:"authMethods"`
RunOnConnect string `yaml:"runOnConnect"` AuthMethodsParsed []headers.AuthMethod `yaml:"-" json:"-"`
RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
Paths map[string]*PathConf `yaml:"paths"` RTMPEnable bool `yaml:"rtmpEnable"`
RTMPPort int `yaml:"rtmpPort"`
Paths map[string]*PathConf `yaml:"paths"`
} }
func (conf *Conf) fillAndCheck() error { func (conf *Conf) fillAndCheck() error {
@ -118,6 +121,15 @@ func (conf *Conf) fillAndCheck() error {
if conf.LogFile == "" { if conf.LogFile == "" {
conf.LogFile = "rtsp-simple-server.log" conf.LogFile = "rtsp-simple-server.log"
} }
if conf.ReadTimeout == 0 {
conf.ReadTimeout = 10 * time.Second
}
if conf.WriteTimeout == 0 {
conf.WriteTimeout = 10 * time.Second
}
if conf.ReadBufferCount == 0 {
conf.ReadBufferCount = 512
}
if len(conf.Protocols) == 0 { if len(conf.Protocols) == 0 {
conf.Protocols = []string{"udp", "tcp"} conf.Protocols = []string{"udp", "tcp"}
@ -202,16 +214,6 @@ func (conf *Conf) fillAndCheck() error {
} }
} }
if conf.ReadTimeout == 0 {
conf.ReadTimeout = 10 * time.Second
}
if conf.WriteTimeout == 0 {
conf.WriteTimeout = 10 * time.Second
}
if conf.ReadBufferCount == 0 {
conf.ReadBufferCount = 512
}
if conf.RTMPPort == 0 { if conf.RTMPPort == 0 {
conf.RTMPPort = 1935 conf.RTMPPort = 1935
} }

60
rtsp-simple-server.yml

@ -1,4 +1,7 @@
###############################################
# General options
# sets the verbosity of the program; available values are "warn", "info", "debug". # sets the verbosity of the program; available values are "warn", "info", "debug".
logLevel: info logLevel: info
# destinations of log messages; available values are "stdout", "file" and "syslog". # destinations of log messages; available values are "stdout", "file" and "syslog".
@ -8,6 +11,29 @@ logFile: rtsp-simple-server.log
# listen IP. If provided, all listeners will listen on this specific IP. # listen IP. If provided, all listeners will listen on this specific IP.
listenIP: listenIP:
# timeout of read operations.
readTimeout: 10s
# timeout of write operations.
writeTimeout: 10s
# number of read buffers.
# a higher number allows a higher throughput,
# a lower number allows to save RAM.
readBufferCount: 512
# enable Prometheus-compatible metrics on port 9998.
metrics: no
# enable pprof on port 9999 to monitor performances.
pprof: no
# command to run when a client connects to the server.
# this is terminated with SIGINT when a client disconnects from the server.
# the server port is available in the RTSP_PORT variable.
runOnConnect:
# the restart parameter allows to restart the command if it exits suddenly.
runOnConnectRestart: no
###############################################
# RTSP options
# supported RTSP stream protocols. # supported RTSP stream protocols.
# UDP is the most performant, but can cause problems if there's a NAT between # UDP is the most performant, but can cause problems if there's a NAT between
@ -32,31 +58,17 @@ serverKey: server.key
serverCert: server.crt serverCert: server.crt
# authentication methods. # authentication methods.
authMethods: [basic, digest] authMethods: [basic, digest]
# timeout of read operations.
readTimeout: 10s ###############################################
# timeout of write operations. # RTMP options
writeTimeout: 10s
# number of read buffers.
# a higher number allows a higher throughput,
# a lower number allows to save RAM.
readBufferCount: 512
# enable a RTMP listener that allows to receive streams with RTMP. # enable a RTMP listener that allows to receive streams with RTMP.
rtmpEnable: no rtmpEnable: no
# port of the RTMP listener. # port of the RTMP listener.
rtmpPort: 1935 rtmpPort: 1935
# enable Prometheus-compatible metrics on port 9998. ###############################################
metrics: no # Path options
# enable pprof on port 9999 to monitor performances.
pprof: no
# command to run when a client connects to the server.
# this is terminated with SIGINT when a client disconnects from the server.
# the server port is available in the RTSP_PORT variable.
# the restart parameter allows to restart the command if it exits suddenly.
runOnConnect:
runOnConnectRestart: no
# these settings are path-dependent. # these settings are path-dependent.
# it's possible to use regular expressions by using a tilde as prefix. # it's possible to use regular expressions by using a tilde as prefix.
@ -67,7 +79,7 @@ runOnConnectRestart: no
paths: paths:
all: all:
# source of the stream - this can be: # source of the stream - this can be:
# * record -> the stream is provided by a RTSP client # * record -> the stream is published by a RTSP or RTMP client
# * rtsp://existing-url -> the stream is pulled from another RTSP server # * rtsp://existing-url -> the stream is pulled from another RTSP server
# * rtsps://existing-url -> the stream is pulled from another RTSP server # * rtsps://existing-url -> the stream is pulled from another RTSP server
# * rtmp://existing-url -> the stream is pulled from a RTMP server # * rtmp://existing-url -> the stream is pulled from a RTMP server
@ -119,8 +131,8 @@ paths:
# this is terminated with SIGINT when the program closes. # this is terminated with SIGINT when the program closes.
# the path name is available in the RTSP_PATH variable. # the path name is available in the RTSP_PATH variable.
# the server port is available in the RTSP_PORT variable. # the server port is available in the RTSP_PORT variable.
# the restart parameter allows to restart the command if it exits suddenly.
runOnInit: runOnInit:
# the restart parameter allows to restart the command if it exits suddenly.
runOnInitRestart: no runOnInitRestart: no
# command to run when this path is requested. # command to run when this path is requested.
@ -128,8 +140,8 @@ paths:
# this is terminated with SIGINT when the path is not requested anymore. # this is terminated with SIGINT when the path is not requested anymore.
# the path name is available in the RTSP_PATH variable. # the path name is available in the RTSP_PATH variable.
# the server port is available in the RTSP_PORT variable. # the server port is available in the RTSP_PORT variable.
# the restart parameter allows to restart the command if it exits suddenly.
runOnDemand: runOnDemand:
# the restart parameter allows to restart the command if it exits suddenly.
runOnDemandRestart: no runOnDemandRestart: no
# readers will be put on hold until the runOnDemand command starts publishing # readers will be put on hold until the runOnDemand command starts publishing
# or until this amount of time has passed. # or until this amount of time has passed.
@ -142,14 +154,14 @@ paths:
# this is terminated with SIGINT when a client stops publishing. # this is terminated with SIGINT when a client stops publishing.
# the path name is available in the RTSP_PATH variable. # the path name is available in the RTSP_PATH variable.
# the server port is available in the RTSP_PORT variable. # the server port is available in the RTSP_PORT variable.
# the restart parameter allows to restart the command if it exits suddenly.
runOnPublish: runOnPublish:
# the restart parameter allows to restart the command if it exits suddenly.
runOnPublishRestart: no runOnPublishRestart: no
# command to run when a clients starts reading. # command to run when a clients starts reading.
# this is terminated with SIGINT when a client stops reading. # this is terminated with SIGINT when a client stops reading.
# the path name is available in the RTSP_PATH variable. # the path name is available in the RTSP_PATH variable.
# the server port is available in the RTSP_PORT variable. # the server port is available in the RTSP_PORT variable.
# the restart parameter allows to restart the command if it exits suddenly.
runOnRead: runOnRead:
# the restart parameter allows to restart the command if it exits suddenly.
runOnReadRestart: no runOnReadRestart: no

Loading…
Cancel
Save