Browse Source

improve performance

pull/1212/head
aler9 3 years ago
parent
commit
7eb7883270
  1. 2
      go.mod
  2. 4
      go.sum
  3. 53
      internal/core/rtsp_server.go

2
go.mod

@ -5,7 +5,7 @@ go 1.18
require ( require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5 code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
github.com/abema/go-mp4 v0.8.0 github.com/abema/go-mp4 v0.8.0
github.com/aler9/gortsplib v0.0.0-20221102164639-d3c23a849c83 github.com/aler9/gortsplib v0.0.0-20221103115742-9216576d49a1
github.com/asticode/go-astits v1.10.1-0.20220319093903-4abe66a9b757 github.com/asticode/go-astits v1.10.1-0.20220319093903-4abe66a9b757
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1

4
go.sum

@ -6,8 +6,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20221102164639-d3c23a849c83 h1:Qn/TL5+Nm4g+IgQ1DODtu6oCve0plBiJsprbnLG3yfQ= github.com/aler9/gortsplib v0.0.0-20221103115742-9216576d49a1 h1:XUxZzQHzdzEKxDsyiknQCy0lHmR29zhc0MnFilXTeR4=
github.com/aler9/gortsplib v0.0.0-20221102164639-d3c23a849c83/go.mod h1:BOWNZ/QBkY/eVcRqUzJbPFEsRJshwxaxBT01K260Jeo= github.com/aler9/gortsplib v0.0.0-20221103115742-9216576d49a1/go.mod h1:BOWNZ/QBkY/eVcRqUzJbPFEsRJshwxaxBT01K260Jeo=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 h1:9WgSzBLo3a9ToSVV7sRTBYZ1GGOZUpq4+5H3SN0UZq4= github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 h1:9WgSzBLo3a9ToSVV7sRTBYZ1GGOZUpq4+5H3SN0UZq4=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82/go.mod h1:qsMrZCbeBf/mCLOeF16KDkPu4gktn/pOWyaq1aYQE7U= github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82/go.mod h1:qsMrZCbeBf/mCLOeF16KDkPu4gktn/pOWyaq1aYQE7U=
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8= github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=

53
internal/core/rtsp_server.go

@ -272,10 +272,10 @@ func (s *rtspServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) {
s.pathManager, s.pathManager,
ctx.Conn, ctx.Conn,
s) s)
s.mutex.Lock() s.mutex.Lock()
s.conns[ctx.Conn] = c s.conns[ctx.Conn] = c
s.mutex.Unlock() s.mutex.Unlock()
ctx.Conn.SetUserData(c)
} }
// OnConnClose implements gortsplib.ServerHandlerOnConnClose. // OnConnClose implements gortsplib.ServerHandlerOnConnClose.
@ -284,34 +284,25 @@ func (s *rtspServer) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx) {
c := s.conns[ctx.Conn] c := s.conns[ctx.Conn]
delete(s.conns, ctx.Conn) delete(s.conns, ctx.Conn)
s.mutex.Unlock() s.mutex.Unlock()
c.onClose(ctx.Error) c.onClose(ctx.Error)
} }
// OnRequest implements gortsplib.ServerHandlerOnRequest. // OnRequest implements gortsplib.ServerHandlerOnRequest.
func (s *rtspServer) OnRequest(sc *gortsplib.ServerConn, req *base.Request) { func (s *rtspServer) OnRequest(sc *gortsplib.ServerConn, req *base.Request) {
s.mutex.Lock() c := sc.UserData().(*rtspConn)
c := s.conns[sc]
s.mutex.Unlock()
c.onRequest(req) c.onRequest(req)
} }
// OnResponse implements gortsplib.ServerHandlerOnResponse. // OnResponse implements gortsplib.ServerHandlerOnResponse.
func (s *rtspServer) OnResponse(sc *gortsplib.ServerConn, res *base.Response) { func (s *rtspServer) OnResponse(sc *gortsplib.ServerConn, res *base.Response) {
s.mutex.Lock() c := sc.UserData().(*rtspConn)
c := s.conns[sc]
s.mutex.Unlock()
c.OnResponse(res) c.OnResponse(res)
} }
// OnSessionOpen implements gortsplib.ServerHandlerOnSessionOpen. // OnSessionOpen implements gortsplib.ServerHandlerOnSessionOpen.
func (s *rtspServer) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) { func (s *rtspServer) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) {
s.mutex.Lock() s.mutex.Lock()
id, _ := s.newSessionID() id, _ := s.newSessionID()
se := newRTSPSession( se := newRTSPSession(
s.isTLS, s.isTLS,
s.protocols, s.protocols,
@ -321,9 +312,9 @@ func (s *rtspServer) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx)
s.externalCmdPool, s.externalCmdPool,
s.pathManager, s.pathManager,
s) s)
s.sessions[ctx.Session] = se s.sessions[ctx.Session] = se
s.mutex.Unlock() s.mutex.Unlock()
ctx.Session.SetUserData(se)
} }
// OnSessionClose implements gortsplib.ServerHandlerOnSessionClose. // OnSessionClose implements gortsplib.ServerHandlerOnSessionClose.
@ -341,67 +332,51 @@ func (s *rtspServer) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCt
// OnDescribe implements gortsplib.ServerHandlerOnDescribe. // OnDescribe implements gortsplib.ServerHandlerOnDescribe.
func (s *rtspServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx, func (s *rtspServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx,
) (*base.Response, *gortsplib.ServerStream, error) { ) (*base.Response, *gortsplib.ServerStream, error) {
s.mutex.RLock() c := ctx.Conn.UserData().(*rtspConn)
c := s.conns[ctx.Conn]
s.mutex.RUnlock()
return c.onDescribe(ctx) return c.onDescribe(ctx)
} }
// OnAnnounce implements gortsplib.ServerHandlerOnAnnounce. // OnAnnounce implements gortsplib.ServerHandlerOnAnnounce.
func (s *rtspServer) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) { func (s *rtspServer) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) {
s.mutex.RLock() c := ctx.Conn.UserData().(*rtspConn)
c := s.conns[ctx.Conn] se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
return se.onAnnounce(c, ctx) return se.onAnnounce(c, ctx)
} }
// OnSetup implements gortsplib.ServerHandlerOnSetup. // OnSetup implements gortsplib.ServerHandlerOnSetup.
func (s *rtspServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) { func (s *rtspServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
s.mutex.RLock() c := ctx.Conn.UserData().(*rtspConn)
c := s.conns[ctx.Conn] se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
return se.onSetup(c, ctx) return se.onSetup(c, ctx)
} }
// OnPlay implements gortsplib.ServerHandlerOnPlay. // OnPlay implements gortsplib.ServerHandlerOnPlay.
func (s *rtspServer) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { func (s *rtspServer) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) {
s.mutex.RLock() se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
return se.onPlay(ctx) return se.onPlay(ctx)
} }
// OnRecord implements gortsplib.ServerHandlerOnRecord. // OnRecord implements gortsplib.ServerHandlerOnRecord.
func (s *rtspServer) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) { func (s *rtspServer) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) {
s.mutex.RLock() se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
return se.onRecord(ctx) return se.onRecord(ctx)
} }
// OnPause implements gortsplib.ServerHandlerOnPause. // OnPause implements gortsplib.ServerHandlerOnPause.
func (s *rtspServer) OnPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Response, error) { func (s *rtspServer) OnPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Response, error) {
s.mutex.RLock() se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
return se.onPause(ctx) return se.onPause(ctx)
} }
// OnPacketRTP implements gortsplib.ServerHandlerOnPacketRTP. // OnPacketRTP implements gortsplib.ServerHandlerOnPacketRTP.
func (s *rtspServer) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) { func (s *rtspServer) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) {
s.mutex.RLock() se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
se.onPacketRTP(ctx) se.onPacketRTP(ctx)
} }
// OnDecodeError implements gortsplib.ServerHandlerOnOnDecodeError. // OnDecodeError implements gortsplib.ServerHandlerOnOnDecodeError.
func (s *rtspServer) OnDecodeError(ctx *gortsplib.ServerHandlerOnDecodeErrorCtx) { func (s *rtspServer) OnDecodeError(ctx *gortsplib.ServerHandlerOnDecodeErrorCtx) {
s.mutex.RLock() se := ctx.Session.UserData().(*rtspSession)
se := s.sessions[ctx.Session]
s.mutex.RUnlock()
se.onDecodeError(ctx) se.onDecodeError(ctx)
} }

Loading…
Cancel
Save