diff --git a/main.go b/main.go index bc8189e0..6ab49daa 100644 --- a/main.go +++ b/main.go @@ -304,11 +304,11 @@ outer: p.forwardFrame(req.path, req.trackId, req.streamType, req.buf) case source := <-p.sourceReady: - source.log("ready") + source.path.log("source ready") source.path.onPublisherSetReady() case source := <-p.sourceNotReady: - source.log("not ready") + source.path.log("source not ready") source.path.onPublisherSetNotReady() case req := <-p.sourceFrame: diff --git a/path.go b/path.go index a15889c1..0d921d62 100644 --- a/path.go +++ b/path.go @@ -53,13 +53,17 @@ func newPath(p *program, name string, confp *confPath, permanent bool) *path { return pa } +func (pa *path) log(format string, args ...interface{}) { + pa.p.log("[path "+pa.name+"] "+format, args...) +} + func (pa *path) onInit() { if pa.source != nil { go pa.source.run() } if pa.confp.RunOnInit != "" { - pa.p.log("starting on init command") + pa.log("starting on init command") pa.onInitCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnInit) pa.onInitCmd.Env = append(os.Environ(), @@ -69,7 +73,7 @@ func (pa *path) onInit() { pa.onInitCmd.Stderr = os.Stderr err := pa.onInitCmd.Start() if err != nil { - pa.p.log("ERR: %s", err) + pa.log("ERR: %s", err) } } } @@ -81,13 +85,13 @@ func (pa *path) onClose() { } if pa.onInitCmd != nil { - pa.p.log("stopping on init command (exited)") + pa.log("stopping on init command (closing)") pa.onInitCmd.Process.Signal(os.Interrupt) pa.onInitCmd.Wait() } if pa.onDemandCmd != nil { - pa.p.log("stopping on demand command (exited)") + pa.log("stopping on demand command (closing)") pa.onDemandCmd.Process.Signal(os.Interrupt) pa.onDemandCmd.Wait() } @@ -152,7 +156,7 @@ func (pa *path) onCheck() { pa.source.state == sourceStateRunning && !pa.hasClients() && time.Since(pa.lastDescribeReq) >= sourceStopAfterDescribeSecs { - pa.source.log("stopping since we're not requested anymore") + pa.log("stopping on demand source since (not requested anymore)") pa.source.state = sourceStateStopped pa.source.setState <- pa.source.state } @@ -161,7 +165,7 @@ func (pa *path) onCheck() { if pa.onDemandCmd != nil && !pa.hasClientReaders() && time.Since(pa.lastDescribeReq) >= onDemandCmdStopAfterDescribeSecs { - pa.p.log("stopping on demand command (not requested anymore)") + pa.log("stopping on demand command (not requested anymore)") pa.onDemandCmd.Process.Signal(os.Interrupt) pa.onDemandCmd.Wait() pa.onDemandCmd = nil @@ -224,7 +228,7 @@ func (pa *path) onDescribe(client *client) { // on demand command is available: put the client on hold if pa.confp.RunOnDemand != "" { if pa.onDemandCmd == nil { // start if needed - pa.p.log("starting on demand command") + pa.log("starting on demand command") pa.lastDescribeActivation = time.Now() pa.onDemandCmd = exec.Command("/bin/sh", "-c", pa.confp.RunOnDemand) @@ -235,7 +239,7 @@ func (pa *path) onDescribe(client *client) { pa.onDemandCmd.Stderr = os.Stderr err := pa.onDemandCmd.Start() if err != nil { - pa.p.log("ERR: %s", err) + pa.log("ERR: %s", err) } } @@ -250,7 +254,7 @@ func (pa *path) onDescribe(client *client) { // publisher was found but is not ready: put the client on hold } else if !pa.publisherReady { if pa.source != nil && pa.source.state == sourceStateStopped { // start if needed - pa.source.log("starting on demand") + pa.log("starting on demand source") pa.lastDescribeActivation = time.Now() pa.source.state = sourceStateRunning pa.source.setState <- pa.source.state diff --git a/source.go b/source.go index 51f6b41d..f7f038aa 100644 --- a/source.go +++ b/source.go @@ -64,10 +64,6 @@ func newSource(p *program, path *path, confp *confPath) *source { return s } -func (s *source) log(format string, args ...interface{}) { - s.p.log("[source "+s.path.name+"] "+format, args...) -} - func (s *source) isPublisher() {} func (s *source) run() { @@ -96,7 +92,7 @@ outer: func (s *source) applyState(state sourceState) { if state == sourceStateRunning { if !s.innerRunning { - s.log("started") + s.path.log("source started") s.innerRunning = true s.innerTerminate = make(chan struct{}) s.innerDone = make(chan struct{}) @@ -107,7 +103,7 @@ func (s *source) applyState(state sourceState) { close(s.innerTerminate) <-s.innerDone s.innerRunning = false - s.log("stopped") + s.path.log("source stopped") } } } @@ -140,7 +136,7 @@ func (s *source) runInner() { } func (s *source) runInnerInner() bool { - s.log("connecting") + s.path.log("source connecting") var conn *gortsplib.ConnClient var err error @@ -161,21 +157,21 @@ func (s *source) runInnerInner() bool { } if err != nil { - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } _, err = conn.Options(s.confp.sourceUrl) if err != nil { conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } tracks, _, err := conn.Describe(s.confp.sourceUrl) if err != nil { conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } @@ -216,7 +212,7 @@ func (s *source) runUdp(conn *gortsplib.ConnClient) bool { } conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } @@ -229,7 +225,7 @@ func (s *source) runUdp(conn *gortsplib.ConnClient) bool { _, err := conn.Play(s.confp.sourceUrl) if err != nil { conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } @@ -295,7 +291,7 @@ outer: case err := <-tcpConnDone: conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) ret = true break outer } @@ -313,7 +309,7 @@ func (s *source) runTcp(conn *gortsplib.ConnClient) bool { _, err := conn.SetupTcp(s.confp.sourceUrl, track) if err != nil { conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } } @@ -321,7 +317,7 @@ func (s *source) runTcp(conn *gortsplib.ConnClient) bool { _, err := conn.Play(s.confp.sourceUrl) if err != nil { conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) return true } @@ -359,7 +355,7 @@ outer: case err := <-tcpConnDone: conn.Close() - s.log("ERR: %s", err) + s.path.log("source ERR: %s", err) ret = true break outer }