diff --git a/internal/core/rtmp_conn.go b/internal/core/rtmp_conn.go index ac5cab02..5c43ae62 100644 --- a/internal/core/rtmp_conn.go +++ b/internal/core/rtmp_conn.go @@ -147,12 +147,17 @@ func (c *rtmpConn) run() { defer c.log(logger.Info, "closed") if c.runOnConnect != "" { + c.log(logger.Info, "runOnConnect command started") _, port, _ := net.SplitHostPort(c.rtspAddress) onConnectCmd := externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ Path: "", Port: port, }) - defer onConnectCmd.Close() + + defer func() { + onConnectCmd.Close() + c.log(logger.Info, "runOnConnect command stopped") + }() } ctx, cancel := context.WithCancel(c.ctx) @@ -278,12 +283,16 @@ func (c *rtmpConn) runRead(ctx context.Context) error { }) if c.path.Conf().RunOnRead != "" { + c.log(logger.Info, "runOnRead command started") _, port, _ := net.SplitHostPort(c.rtspAddress) onReadCmd := externalcmd.New(c.path.Conf().RunOnRead, c.path.Conf().RunOnReadRestart, externalcmd.Environment{ Path: c.path.Name(), Port: port, }) - defer onReadCmd.Close() + defer func() { + onReadCmd.Close() + c.log(logger.Info, "runOnRead command stopped") + }() } // disable read deadline diff --git a/internal/core/rtsp_conn.go b/internal/core/rtsp_conn.go index 998c9edc..a727d9aa 100644 --- a/internal/core/rtsp_conn.go +++ b/internal/core/rtsp_conn.go @@ -75,6 +75,7 @@ func newRTSPConn( c.log(logger.Info, "opened") if c.runOnConnect != "" { + c.log(logger.Info, "runOnConnect command started") _, port, _ := net.SplitHostPort(c.rtspAddress) c.onConnectCmd = externalcmd.New(c.runOnConnect, c.runOnConnectRestart, externalcmd.Environment{ Path: "", @@ -173,6 +174,7 @@ func (c *rtspConn) OnClose(err error) { if c.onConnectCmd != nil { c.onConnectCmd.Close() + c.log(logger.Info, "runOnConnect command stopped") } } diff --git a/internal/core/rtsp_session.go b/internal/core/rtsp_session.go index c5f619ea..a76cf3e9 100644 --- a/internal/core/rtsp_session.go +++ b/internal/core/rtsp_session.go @@ -112,6 +112,8 @@ func (s *rtspSession) OnClose() { if s.ss.State() == gortsplib.ServerSessionStateRead { if s.onReadCmd != nil { 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}) if s.path.Conf().RunOnRead != "" { + s.log(logger.Info, "runOnRead command started") _, port, _ := net.SplitHostPort(s.rtspAddress) s.onReadCmd = externalcmd.New(s.path.Conf().RunOnRead, s.path.Conf().RunOnReadRestart, externalcmd.Environment{ Path: s.path.Name(), @@ -308,6 +311,7 @@ func (s *rtspSession) OnPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Res switch s.ss.State() { case gortsplib.ServerSessionStateRead: if s.onReadCmd != nil { + s.log(logger.Info, "runOnRead command stopped") s.onReadCmd.Close() }