Browse Source

print log messages when runOnConnect and runOnRead are started or stopped

pull/666/head
aler9 5 years ago
parent
commit
160966e81b
  1. 13
      internal/core/rtmp_conn.go
  2. 2
      internal/core/rtsp_conn.go
  3. 4
      internal/core/rtsp_session.go

13
internal/core/rtmp_conn.go

@ -147,12 +147,17 @@ func (c *rtmpConn) run() {
defer c.log(logger.Info, "closed") defer c.log(logger.Info, "closed")
if c.runOnConnect != "" { if c.runOnConnect != "" {
c.log(logger.Info, "runOnConnect command started")
_, port, _ := net.SplitHostPort(c.rtspAddress) _, port, _ := net.SplitHostPort(c.rtspAddress)
onConnectCmd := externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ onConnectCmd := externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{
Path: "", Path: "",
Port: port, Port: port,
}) })
defer onConnectCmd.Close()
defer func() {
onConnectCmd.Close()
c.log(logger.Info, "runOnConnect command stopped")
}()
} }
ctx, cancel := context.WithCancel(c.ctx) ctx, cancel := context.WithCancel(c.ctx)
@ -278,12 +283,16 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
}) })
if c.path.Conf().RunOnRead != "" { if c.path.Conf().RunOnRead != "" {
c.log(logger.Info, "runOnRead command started")
_, port, _ := net.SplitHostPort(c.rtspAddress) _, port, _ := net.SplitHostPort(c.rtspAddress)
onReadCmd := externalcmd.New(c.path.Conf().RunOnRead, c.path.Conf().RunOnReadRestart, externalcmd.Environment{ onReadCmd := externalcmd.New(c.path.Conf().RunOnRead, c.path.Conf().RunOnReadRestart, externalcmd.Environment{
Path: c.path.Name(), Path: c.path.Name(),
Port: port, Port: port,
}) })
defer onReadCmd.Close() defer func() {
onReadCmd.Close()
c.log(logger.Info, "runOnRead command stopped")
}()
} }
// disable read deadline // disable read deadline

2
internal/core/rtsp_conn.go

@ -75,6 +75,7 @@ func newRTSPConn(
c.log(logger.Info, "opened") c.log(logger.Info, "opened")
if c.runOnConnect != "" { if c.runOnConnect != "" {
c.log(logger.Info, "runOnConnect command started")
_, port, _ := net.SplitHostPort(c.rtspAddress) _, port, _ := net.SplitHostPort(c.rtspAddress)
c.onConnectCmd = externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ c.onConnectCmd = externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{
Path: "", Path: "",
@ -173,6 +174,7 @@ func (c *rtspConn) OnClose(err error) {
if c.onConnectCmd != nil { if c.onConnectCmd != nil {
c.onConnectCmd.Close() c.onConnectCmd.Close()
c.log(logger.Info, "runOnConnect command stopped")
} }
} }

4
internal/core/rtsp_session.go

@ -112,6 +112,8 @@ func (s *rtspSession) OnClose() {
if s.ss.State() == gortsplib.ServerSessionStateRead { if s.ss.State() == gortsplib.ServerSessionStateRead {
if s.onReadCmd != nil { if s.onReadCmd != nil {
s.onReadCmd.Close() s.onReadCmd.Close()
s.onReadCmd = nil
s.log(logger.Info, "runOnRead command stopped")
} }
} }
@ -262,6 +264,7 @@ func (s *rtspSession) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Respo
s.path.OnReaderPlay(pathReaderPlayReq{Author: s}) s.path.OnReaderPlay(pathReaderPlayReq{Author: s})
if s.path.Conf().RunOnRead != "" { if s.path.Conf().RunOnRead != "" {
s.log(logger.Info, "runOnRead command started")
_, port, _ := net.SplitHostPort(s.rtspAddress) _, port, _ := net.SplitHostPort(s.rtspAddress)
s.onReadCmd = externalcmd.New(s.path.Conf().RunOnRead, s.path.Conf().RunOnReadRestart, externalcmd.Environment{ s.onReadCmd = externalcmd.New(s.path.Conf().RunOnRead, s.path.Conf().RunOnReadRestart, externalcmd.Environment{
Path: s.path.Name(), Path: s.path.Name(),
@ -308,6 +311,7 @@ func (s *rtspSession) OnPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Res
switch s.ss.State() { switch s.ss.State() {
case gortsplib.ServerSessionStateRead: case gortsplib.ServerSessionStateRead:
if s.onReadCmd != nil { if s.onReadCmd != nil {
s.log(logger.Info, "runOnRead command stopped")
s.onReadCmd.Close() s.onReadCmd.Close()
} }

Loading…
Cancel
Save