mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-11-01 19:42:37 +08:00
allow onDemandCmd when path is 'all'
This commit is contained in:
10
conf.go
10
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")
|
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)
|
confp.sourceUrl, err = url.Parse(confp.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("'%s' is not a valid RTSP url", confp.Source)
|
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 {
|
switch confp.SourceProtocol {
|
||||||
case "udp":
|
case "udp":
|
||||||
confp.sourceProtocolParsed = gortsplib.StreamProtocolUdp
|
confp.sourceProtocolParsed = gortsplib.StreamProtocolUdp
|
||||||
@@ -268,9 +267,6 @@ func loadConf(fpath string, stdin io.Reader) (*conf, error) {
|
|||||||
if name == "all" && confp.RunOnInit != "" {
|
if name == "all" && confp.RunOnInit != "" {
|
||||||
return nil, fmt.Errorf("path 'all' does not support option 'runOnInit'; use another path")
|
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
|
return conf, nil
|
||||||
|
|||||||
9
main.go
9
main.go
@@ -333,6 +333,7 @@ outer:
|
|||||||
path.publisherRemove()
|
path.publisherRemove()
|
||||||
|
|
||||||
if !path.permanent {
|
if !path.permanent {
|
||||||
|
path.onClose()
|
||||||
delete(p.paths, evt.client.pathName)
|
delete(p.paths, evt.client.pathName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -527,6 +528,10 @@ outer:
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
for _, p := range p.paths {
|
||||||
|
p.onClose()
|
||||||
|
}
|
||||||
|
|
||||||
p.serverRtsp.close()
|
p.serverRtsp.close()
|
||||||
|
|
||||||
for _, s := range p.sources {
|
for _, s := range p.sources {
|
||||||
@@ -544,10 +549,6 @@ outer:
|
|||||||
<-c.done
|
<-c.done
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range p.paths {
|
|
||||||
p.onClose()
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.metrics != nil {
|
if p.metrics != nil {
|
||||||
p.metrics.close()
|
p.metrics.close()
|
||||||
}
|
}
|
||||||
|
|||||||
6
path.go
6
path.go
@@ -42,6 +42,8 @@ func newPath(p *program, name string, confp *confPath, permanent bool) *path {
|
|||||||
|
|
||||||
func (pa *path) onInit() {
|
func (pa *path) onInit() {
|
||||||
if pa.confp.RunOnInit != "" {
|
if pa.confp.RunOnInit != "" {
|
||||||
|
pa.p.log("starting on init command")
|
||||||
|
|
||||||
pa.onInitCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnInit)
|
pa.onInitCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnInit)
|
||||||
pa.onInitCmd.Env = append(os.Environ(),
|
pa.onInitCmd.Env = append(os.Environ(),
|
||||||
"RTSP_SERVER_PATH="+pa.name,
|
"RTSP_SERVER_PATH="+pa.name,
|
||||||
@@ -57,11 +59,13 @@ func (pa *path) onInit() {
|
|||||||
|
|
||||||
func (pa *path) onClose() {
|
func (pa *path) onClose() {
|
||||||
if pa.onInitCmd != nil {
|
if pa.onInitCmd != nil {
|
||||||
|
pa.p.log("stopping on init command (exited)")
|
||||||
pa.onInitCmd.Process.Signal(os.Interrupt)
|
pa.onInitCmd.Process.Signal(os.Interrupt)
|
||||||
pa.onInitCmd.Wait()
|
pa.onInitCmd.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
if pa.onDemandCmd != nil {
|
if pa.onDemandCmd != nil {
|
||||||
|
pa.p.log("stopping on demand command (exited)")
|
||||||
pa.onDemandCmd.Process.Signal(os.Interrupt)
|
pa.onDemandCmd.Process.Signal(os.Interrupt)
|
||||||
pa.onDemandCmd.Wait()
|
pa.onDemandCmd.Wait()
|
||||||
}
|
}
|
||||||
@@ -128,7 +132,7 @@ func (pa *path) onCheck() {
|
|||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
if !hasClientReaders {
|
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.Process.Signal(os.Interrupt)
|
||||||
pa.onDemandCmd.Wait()
|
pa.onDemandCmd.Wait()
|
||||||
pa.onDemandCmd = nil
|
pa.onDemandCmd = nil
|
||||||
|
|||||||
@@ -46,23 +46,23 @@ paths:
|
|||||||
# command to run when this path is loaded by the program.
|
# 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 can be used, for example, to publish a stream and keep it always opened.
|
||||||
# This is terminated with SIGINT when the program closes.
|
# 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:
|
runOnInit:
|
||||||
|
|
||||||
# command to run when this path is requested.
|
# command to run when this path is requested.
|
||||||
# This can be used, for example, to publish a stream on demand.
|
# This can be used, for example, to publish a stream on demand.
|
||||||
# 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 can be accessed with the variable RTSP_SERVER_PATH
|
# The path name is available in the RTSP_SERVER_PATH variable
|
||||||
runOnDemand:
|
runOnDemand:
|
||||||
|
|
||||||
# command to run when a client starts publishing.
|
# command to run when a client starts publishing.
|
||||||
# This is terminated with SIGINT when a client stops 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:
|
runOnPublish:
|
||||||
|
|
||||||
# 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 can be accessed with the variable RTSP_SERVER_PATH
|
# The path name is available in the RTSP_SERVER_PATH variable
|
||||||
runOnRead:
|
runOnRead:
|
||||||
|
|
||||||
# username required to publish
|
# username required to publish
|
||||||
|
|||||||
Reference in New Issue
Block a user