mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-17 12:14:34 +00:00
use RWMutex instead of Mutex
This commit is contained in:
parent
b02a15b8df
commit
076f5977bd
10
main.go
10
main.go
@ -16,7 +16,7 @@ type program struct {
|
||||
rtspPort int
|
||||
rtpPort int
|
||||
rtcpPort int
|
||||
mutex sync.Mutex
|
||||
mutex sync.RWMutex
|
||||
rtspl *rtspListener
|
||||
rtpl *udpListener
|
||||
rtcpl *udpListener
|
||||
@ -36,8 +36,8 @@ func newProgram(rtspPort int, rtpPort int, rtcpPort int) (*program, error) {
|
||||
var err error
|
||||
|
||||
p.rtpl, err = newUdpListener(rtpPort, "RTP", func(l *udpListener, buf []byte) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.mutex.RLock()
|
||||
defer p.mutex.RUnlock()
|
||||
for c := range p.clients {
|
||||
if c.state == "PLAY" {
|
||||
l.nconn.WriteTo(buf, &net.UDPAddr{
|
||||
@ -52,8 +52,8 @@ func newProgram(rtspPort int, rtpPort int, rtcpPort int) (*program, error) {
|
||||
}
|
||||
|
||||
p.rtcpl, err = newUdpListener(rtcpPort, "RTCP", func(l *udpListener, buf []byte) {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
p.mutex.RLock()
|
||||
defer p.mutex.RUnlock()
|
||||
for c := range p.clients {
|
||||
if c.state == "PLAY" {
|
||||
l.nconn.WriteTo(buf, &net.UDPAddr{
|
||||
|
@ -125,8 +125,8 @@ func (c *rtspClient) run(wg sync.WaitGroup) {
|
||||
}
|
||||
|
||||
sdp, err := func() ([]byte, error) {
|
||||
c.p.mutex.Lock()
|
||||
defer c.p.mutex.Unlock()
|
||||
c.p.mutex.RLock()
|
||||
defer c.p.mutex.RUnlock()
|
||||
|
||||
if len(c.p.streamSdp) == 0 {
|
||||
return nil, fmt.Errorf("no one is streaming")
|
||||
|
Loading…
Reference in New Issue
Block a user