Browse Source

expose request path to runOn commands as an environment variable

pull/55/head
Liwei 6 years ago
parent
commit
c0b0b23c41
  1. 6
      client.go
  2. 5
      main.go
  3. 3
      path.go
  4. 7
      rtsp-simple-server.yml

6
client.go

@ -829,6 +829,9 @@ func (c *client) runPlay(path string) {
var onReadCmd *exec.Cmd var onReadCmd *exec.Cmd
if confp.RunOnRead != "" { if confp.RunOnRead != "" {
onReadCmd = exec.Command("/bin/sh", "-c", confp.RunOnRead) onReadCmd = exec.Command("/bin/sh", "-c", confp.RunOnRead)
onReadCmd.Env = append(os.Environ(),
"RTSP_SERVER_PATH="+path,
)
onReadCmd.Stdout = os.Stdout onReadCmd.Stdout = os.Stdout
onReadCmd.Stderr = os.Stderr onReadCmd.Stderr = os.Stderr
err := onReadCmd.Start() err := onReadCmd.Start()
@ -928,6 +931,9 @@ func (c *client) runRecord(path string) {
var onPublishCmd *exec.Cmd var onPublishCmd *exec.Cmd
if confp.RunOnPublish != "" { if confp.RunOnPublish != "" {
onPublishCmd = exec.Command("/bin/sh", "-c", confp.RunOnPublish) onPublishCmd = exec.Command("/bin/sh", "-c", confp.RunOnPublish)
onPublishCmd.Env = append(os.Environ(),
"RTSP_SERVER_PATH="+path,
)
onPublishCmd.Stdout = os.Stdout onPublishCmd.Stdout = os.Stdout
onPublishCmd.Stderr = os.Stderr onPublishCmd.Stderr = os.Stderr
err := onPublishCmd.Start() err := onPublishCmd.Start()

5
main.go

@ -260,9 +260,12 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
return nil, err return nil, err
} }
for _, confp := range conf.Paths { for path, confp := range conf.Paths {
if confp.RunOnInit != "" { if confp.RunOnInit != "" {
onInitCmd := exec.Command("/bin/sh", "-c", confp.RunOnInit) onInitCmd := exec.Command("/bin/sh", "-c", confp.RunOnInit)
onInitCmd.Env = append(os.Environ(),
"RTSP_SERVER_PATH="+path,
)
onInitCmd.Stdout = os.Stdout onInitCmd.Stdout = os.Stdout
onInitCmd.Stderr = os.Stderr onInitCmd.Stderr = os.Stderr
err := onInitCmd.Start() err := onInitCmd.Start()

3
path.go

@ -122,6 +122,9 @@ func (pa *path) describe(client *client) {
pa.lastActivation = time.Now() pa.lastActivation = time.Now()
pa.onDemandCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnDemand) pa.onDemandCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnDemand)
pa.onDemandCmd.Env = append(os.Environ(),
"RTSP_SERVER_PATH="+pa.id,
)
pa.onDemandCmd.Stdout = os.Stdout pa.onDemandCmd.Stdout = os.Stdout
pa.onDemandCmd.Stderr = os.Stderr pa.onDemandCmd.Stderr = os.Stderr
err := pa.onDemandCmd.Start() err := pa.onDemandCmd.Start()

7
rtsp-simple-server.yml

@ -43,19 +43,26 @@ 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 is available as an environment variable $RTSP_SERVER_PATH
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 actual path from the request (useful for wildcard paths) is available as an
# environment variable $RTSP_SERVER_PATH
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 actual path from the client (useful for wildcard paths) is available as an
# environment variable $RTSP_SERVER_PATH
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 actual path from the client (useful for wildcard paths) is available as an
# environment variable $RTSP_SERVER_PATH
runOnRead: runOnRead:
# username required to publish # username required to publish

Loading…
Cancel
Save