mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-11-03 01:43:48 +08:00
cleanup
This commit is contained in:
@@ -8,14 +8,14 @@ const (
|
|||||||
retryPause = 5 * time.Second
|
retryPause = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Environment is a ExternalCmd environment.
|
// Environment is a Cmd environment.
|
||||||
type Environment struct {
|
type Environment struct {
|
||||||
Path string
|
Path string
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalCmd is an external command.
|
// Cmd is an external command.
|
||||||
type ExternalCmd struct {
|
type Cmd struct {
|
||||||
cmdstr string
|
cmdstr string
|
||||||
restart bool
|
restart bool
|
||||||
env Environment
|
env Environment
|
||||||
@@ -27,9 +27,9 @@ type ExternalCmd struct {
|
|||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New allocates an ExternalCmd.
|
// New allocates an Cmd.
|
||||||
func New(cmdstr string, restart bool, env Environment) *ExternalCmd {
|
func New(cmdstr string, restart bool, env Environment) *Cmd {
|
||||||
e := &ExternalCmd{
|
e := &Cmd{
|
||||||
cmdstr: cmdstr,
|
cmdstr: cmdstr,
|
||||||
restart: restart,
|
restart: restart,
|
||||||
env: env,
|
env: env,
|
||||||
@@ -41,13 +41,13 @@ func New(cmdstr string, restart bool, env Environment) *ExternalCmd {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes an ExternalCmd.
|
// Close closes an Cmd.
|
||||||
func (e *ExternalCmd) Close() {
|
func (e *Cmd) Close() {
|
||||||
close(e.terminate)
|
close(e.terminate)
|
||||||
<-e.done
|
<-e.done
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ExternalCmd) run() {
|
func (e *Cmd) run() {
|
||||||
defer close(e.done)
|
defer close(e.done)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *ExternalCmd) runInner() bool {
|
func (e *Cmd) runInner() bool {
|
||||||
cmd := exec.Command("/bin/sh", "-c", "exec "+e.cmdstr)
|
cmd := exec.Command("/bin/sh", "-c", "exec "+e.cmdstr)
|
||||||
|
|
||||||
cmd.Env = append(os.Environ(),
|
cmd.Env = append(os.Environ(),
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/kballard/go-shellquote"
|
"github.com/kballard/go-shellquote"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *ExternalCmd) runInner() bool {
|
func (e *Cmd) runInner() bool {
|
||||||
// on Windows the shell is not used and command is started directly
|
// on Windows the shell is not used and command is started directly
|
||||||
// variables are replaced manually in order to guarantee compatibility
|
// variables are replaced manually in order to guarantee compatibility
|
||||||
// with Linux commands
|
// with Linux commands
|
||||||
@@ -155,7 +155,7 @@ type Path struct {
|
|||||||
sourceTrackCount int
|
sourceTrackCount int
|
||||||
sourceSdp []byte
|
sourceSdp []byte
|
||||||
readers *readersMap
|
readers *readersMap
|
||||||
onDemandCmd *externalcmd.ExternalCmd
|
onDemandCmd *externalcmd.Cmd
|
||||||
describeTimer *time.Timer
|
describeTimer *time.Timer
|
||||||
sourceCloseTimer *time.Timer
|
sourceCloseTimer *time.Timer
|
||||||
sourceCloseTimerStarted bool
|
sourceCloseTimerStarted bool
|
||||||
@@ -244,7 +244,7 @@ func (pa *Path) run() {
|
|||||||
pa.startExternalSource()
|
pa.startExternalSource()
|
||||||
}
|
}
|
||||||
|
|
||||||
var onInitCmd *externalcmd.ExternalCmd
|
var onInitCmd *externalcmd.Cmd
|
||||||
if pa.conf.RunOnInit != "" {
|
if pa.conf.RunOnInit != "" {
|
||||||
pa.Log("on init command started")
|
pa.Log("on init command started")
|
||||||
onInitCmd = externalcmd.New(pa.conf.RunOnInit, pa.conf.RunOnInitRestart, externalcmd.Environment{
|
onInitCmd = externalcmd.New(pa.conf.RunOnInit, pa.conf.RunOnInitRestart, externalcmd.Environment{
|
||||||
|
|||||||
Reference in New Issue
Block a user