mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
examples: use RWMutex when possible (#730)
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type server struct {
|
type server struct {
|
||||||
s *gortsplib.Server
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +52,8 @@ func (s *server) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) {
|
|||||||
func (s *server) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (s *server) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("describe request")
|
log.Printf("describe request")
|
||||||
|
|
||||||
s.mutex.Lock()
|
s.mutex.RLock()
|
||||||
defer s.mutex.Unlock()
|
defer s.mutex.RUnlock()
|
||||||
|
|
||||||
// stream is not available yet
|
// stream is not available yet
|
||||||
if s.stream == nil {
|
if s.stream == nil {
|
||||||
@@ -71,8 +71,8 @@ func (s *server) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Re
|
|||||||
func (s *server) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (s *server) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
s.mutex.Lock()
|
s.mutex.RLock()
|
||||||
defer s.mutex.Unlock()
|
defer s.mutex.RUnlock()
|
||||||
|
|
||||||
// stream is not available yet
|
// stream is not available yet
|
||||||
if s.stream == nil {
|
if s.stream == nil {
|
||||||
|
@@ -30,7 +30,7 @@ const (
|
|||||||
|
|
||||||
type serverHandler struct {
|
type serverHandler struct {
|
||||||
s *gortsplib.Server
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
publisher *gortsplib.ServerSession
|
publisher *gortsplib.ServerSession
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (
|
|||||||
}, nil, liberrors.ErrServerAuth{}
|
}, nil, liberrors.ErrServerAuth{}
|
||||||
}
|
}
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
@@ -147,8 +147,8 @@ func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
|
@@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
type serverHandler struct {
|
type serverHandler struct {
|
||||||
s *gortsplib.Server
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
publisher *gortsplib.ServerSession
|
publisher *gortsplib.ServerSession
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,8 @@ func (sh *serverHandler) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionClo
|
|||||||
func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("describe request")
|
log.Printf("describe request")
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
@@ -108,8 +108,8 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
type serverHandler struct {
|
type serverHandler struct {
|
||||||
s *gortsplib.Server
|
s *gortsplib.Server
|
||||||
mutex sync.Mutex
|
mutex sync.RWMutex
|
||||||
stream *gortsplib.ServerStream
|
stream *gortsplib.ServerStream
|
||||||
publisher *gortsplib.ServerSession
|
publisher *gortsplib.ServerSession
|
||||||
}
|
}
|
||||||
@@ -58,8 +58,8 @@ func (sh *serverHandler) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionClo
|
|||||||
func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("describe request")
|
log.Printf("describe request")
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
@@ -107,8 +107,8 @@ func (sh *serverHandler) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (
|
|||||||
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
func (sh *serverHandler) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) {
|
||||||
log.Printf("setup request")
|
log.Printf("setup request")
|
||||||
|
|
||||||
sh.mutex.Lock()
|
sh.mutex.RLock()
|
||||||
defer sh.mutex.Unlock()
|
defer sh.mutex.RUnlock()
|
||||||
|
|
||||||
// no one is publishing yet
|
// no one is publishing yet
|
||||||
if sh.stream == nil {
|
if sh.stream == nil {
|
||||||
|
Reference in New Issue
Block a user