diff --git a/conf.go b/conf.go index 6ba9c0c1..43eba1b8 100644 --- a/conf.go +++ b/conf.go @@ -194,10 +194,6 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) { return nil, fmt.Errorf("path 'all' cannot have a RTSP source; use another path") } - if confp.SourceProtocol == "" { - confp.SourceProtocol = "udp" - } - confp.sourceUrl, err = url.Parse(confp.Source) if err != nil { return nil, fmt.Errorf("'%s' is not a valid RTSP url", confp.Source) @@ -217,6 +213,9 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) { } } + if confp.SourceProtocol == "" { + confp.SourceProtocol = "udp" + } switch confp.SourceProtocol { case "udp": confp.sourceProtocolParsed = gortsplib.StreamProtocolUdp @@ -268,9 +267,6 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) { if name == "all" && confp.RunOnInit != "" { return nil, fmt.Errorf("path 'all' does not support option 'runOnInit'; use another path") } - if name == "all" && confp.RunOnDemand != "" { - return nil, fmt.Errorf("path 'all' does not support option 'runOnDemand'; use another path") - } } return conf, nil diff --git a/main.go b/main.go index 10f6a62c..67c8ba93 100644 --- a/main.go +++ b/main.go @@ -333,6 +333,7 @@ outer: path.publisherRemove() if !path.permanent { + path.onClose() delete(p.paths, evt.client.pathName) } } @@ -527,6 +528,10 @@ outer: } }() + for _, p := range p.paths { + p.onClose() + } + p.serverRtsp.close() for _, s := range p.sources { @@ -544,10 +549,6 @@ outer: <-c.done } - for _, p := range p.paths { - p.onClose() - } - if p.metrics != nil { p.metrics.close() } diff --git a/path.go b/path.go index 8062b3f0..967011cb 100644 --- a/path.go +++ b/path.go @@ -42,6 +42,8 @@ func newPath(p *program, name string, confp *confPath, permanent bool) *path { func (pa *path) onInit() { if pa.confp.RunOnInit != "" { + pa.p.log("starting on init command") + pa.onInitCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnInit) pa.onInitCmd.Env = append(os.Environ(), "RTSP_SERVER_PATH="+pa.name, @@ -57,11 +59,13 @@ func (pa *path) onInit() { func (pa *path) onClose() { if pa.onInitCmd != nil { + pa.p.log("stopping on init command (exited)") pa.onInitCmd.Process.Signal(os.Interrupt) pa.onInitCmd.Wait() } if pa.onDemandCmd != nil { + pa.p.log("stopping on demand command (exited)") pa.onDemandCmd.Process.Signal(os.Interrupt) pa.onDemandCmd.Wait() } @@ -128,7 +132,7 @@ func (pa *path) onCheck() { return false }() if !hasClientReaders { - pa.p.log("stopping on demand command since it is not requested anymore") + pa.p.log("stopping on demand command (not requested anymore)") pa.onDemandCmd.Process.Signal(os.Interrupt) pa.onDemandCmd.Wait() pa.onDemandCmd = nil diff --git a/rtsp-simple-server.yml b/rtsp-simple-server.yml index 3d539b2c..366637aa 100644 --- a/rtsp-simple-server.yml +++ b/rtsp-simple-server.yml @@ -46,23 +46,23 @@ paths: # command to run when this path is loaded by the program. # this can be used, for example, to publish a stream and keep it always opened. # This is terminated with SIGINT when the program closes. - # The path can be accessed with the variable RTSP_SERVER_PATH + # The path name is available in the RTSP_SERVER_PATH variable runOnInit: # command to run when this path is requested. # This can be used, for example, to publish a stream on demand. # This is terminated with SIGINT when the path is not requested anymore. - # The path can be accessed with the variable RTSP_SERVER_PATH + # The path name is available in the RTSP_SERVER_PATH variable runOnDemand: # command to run when a client starts publishing. # This is terminated with SIGINT when a client stops publishing. - # The path can be accessed with the variable RTSP_SERVER_PATH + # The path name is available in the RTSP_SERVER_PATH variable runOnPublish: # command to run when a clients starts reading. # This is terminated with SIGINT when a client stops reading. - # The path can be accessed with the variable RTSP_SERVER_PATH + # The path name is available in the RTSP_SERVER_PATH variable runOnRead: # username required to publish