|
|
|
@ -37,13 +37,14 @@ type rtspSession struct { |
|
|
|
pathManager rtspSessionPathManager |
|
|
|
pathManager rtspSessionPathManager |
|
|
|
parent rtspSessionParent |
|
|
|
parent rtspSessionParent |
|
|
|
|
|
|
|
|
|
|
|
uuid uuid.UUID |
|
|
|
uuid uuid.UUID |
|
|
|
created time.Time |
|
|
|
created time.Time |
|
|
|
path *path |
|
|
|
path *path |
|
|
|
stream *stream |
|
|
|
stream *stream |
|
|
|
state gortsplib.ServerSessionState |
|
|
|
onReadCmd *externalcmd.Cmd // read
|
|
|
|
stateMutex sync.Mutex |
|
|
|
mutex sync.Mutex |
|
|
|
onReadCmd *externalcmd.Cmd // read
|
|
|
|
state gortsplib.ServerSessionState |
|
|
|
|
|
|
|
pathName string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newRTSPSession( |
|
|
|
func newRTSPSession( |
|
|
|
@ -77,12 +78,6 @@ func (s *rtspSession) close() { |
|
|
|
s.session.Close() |
|
|
|
s.session.Close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *rtspSession) safeState() gortsplib.ServerSessionState { |
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
|
|
|
|
defer s.stateMutex.Unlock() |
|
|
|
|
|
|
|
return s.state |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *rtspSession) remoteAddr() net.Addr { |
|
|
|
func (s *rtspSession) remoteAddr() net.Addr { |
|
|
|
return s.author.NetConn().RemoteAddr() |
|
|
|
return s.author.NetConn().RemoteAddr() |
|
|
|
} |
|
|
|
} |
|
|
|
@ -157,9 +152,10 @@ func (s *rtspSession) onAnnounce(c *rtspConn, ctx *gortsplib.ServerHandlerOnAnno |
|
|
|
|
|
|
|
|
|
|
|
s.path = res.path |
|
|
|
s.path = res.path |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStatePreRecord |
|
|
|
s.state = gortsplib.ServerSessionStatePreRecord |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.pathName = ctx.Path |
|
|
|
|
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
return &base.Response{ |
|
|
|
return &base.Response{ |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
@ -242,9 +238,10 @@ func (s *rtspSession) onSetup(c *rtspConn, ctx *gortsplib.ServerHandlerOnSetupCt |
|
|
|
s.path = res.path |
|
|
|
s.path = res.path |
|
|
|
s.stream = res.stream |
|
|
|
s.stream = res.stream |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStatePrePlay |
|
|
|
s.state = gortsplib.ServerSessionStatePrePlay |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.pathName = ctx.Path |
|
|
|
|
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
return &base.Response{ |
|
|
|
return &base.Response{ |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
@ -281,9 +278,9 @@ func (s *rtspSession) onPlay(_ *gortsplib.ServerHandlerOnPlayCtx) (*base.Respons |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStatePlay |
|
|
|
s.state = gortsplib.ServerSessionStatePlay |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.mutex.Unlock() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &base.Response{ |
|
|
|
return &base.Response{ |
|
|
|
@ -323,9 +320,9 @@ func (s *rtspSession) onRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.R |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStateRecord |
|
|
|
s.state = gortsplib.ServerSessionStateRecord |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
return &base.Response{ |
|
|
|
return &base.Response{ |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
StatusCode: base.StatusOK, |
|
|
|
@ -341,16 +338,16 @@ func (s *rtspSession) onPause(_ *gortsplib.ServerHandlerOnPauseCtx) (*base.Respo |
|
|
|
s.onReadCmd.Close() |
|
|
|
s.onReadCmd.Close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStatePrePlay |
|
|
|
s.state = gortsplib.ServerSessionStatePrePlay |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
case gortsplib.ServerSessionStateRecord: |
|
|
|
case gortsplib.ServerSessionStateRecord: |
|
|
|
s.path.publisherStop(pathPublisherStopReq{author: s}) |
|
|
|
s.path.publisherStop(pathPublisherStopReq{author: s}) |
|
|
|
|
|
|
|
|
|
|
|
s.stateMutex.Lock() |
|
|
|
s.mutex.Lock() |
|
|
|
s.state = gortsplib.ServerSessionStatePreRecord |
|
|
|
s.state = gortsplib.ServerSessionStatePreRecord |
|
|
|
s.stateMutex.Unlock() |
|
|
|
s.mutex.Unlock() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &base.Response{ |
|
|
|
return &base.Response{ |
|
|
|
@ -387,12 +384,15 @@ func (s *rtspSession) onDecodeError(ctx *gortsplib.ServerHandlerOnDecodeErrorCtx |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *rtspSession) apiItem() *apiRTSPSession { |
|
|
|
func (s *rtspSession) apiItem() *apiRTSPSession { |
|
|
|
|
|
|
|
s.mutex.Lock() |
|
|
|
|
|
|
|
defer s.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
return &apiRTSPSession{ |
|
|
|
return &apiRTSPSession{ |
|
|
|
ID: s.uuid, |
|
|
|
ID: s.uuid, |
|
|
|
Created: s.created, |
|
|
|
Created: s.created, |
|
|
|
RemoteAddr: s.remoteAddr().String(), |
|
|
|
RemoteAddr: s.remoteAddr().String(), |
|
|
|
State: func() string { |
|
|
|
State: func() string { |
|
|
|
switch s.safeState() { |
|
|
|
switch s.state { |
|
|
|
case gortsplib.ServerSessionStatePrePlay, |
|
|
|
case gortsplib.ServerSessionStatePrePlay, |
|
|
|
gortsplib.ServerSessionStatePlay: |
|
|
|
gortsplib.ServerSessionStatePlay: |
|
|
|
return "read" |
|
|
|
return "read" |
|
|
|
@ -403,6 +403,7 @@ func (s *rtspSession) apiItem() *apiRTSPSession { |
|
|
|
} |
|
|
|
} |
|
|
|
return "idle" |
|
|
|
return "idle" |
|
|
|
}(), |
|
|
|
}(), |
|
|
|
|
|
|
|
Path: s.pathName, |
|
|
|
BytesReceived: s.session.BytesReceived(), |
|
|
|
BytesReceived: s.session.BytesReceived(), |
|
|
|
BytesSent: s.session.BytesSent(), |
|
|
|
BytesSent: s.session.BytesSent(), |
|
|
|
} |
|
|
|
} |
|
|
|
|