Skip to content

Commit effff6f

Browse files
committed
Fix concurrent SRTP sessions map read and map write #1489
1 parent 45b223a commit effff6f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/srtp/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ func (s *Server) DelSession(session *Session) {
6565
s.mu.Unlock()
6666
}
6767

68+
func (s *Server) GetSession(ssrc uint32) (session *Session) {
69+
s.mu.Lock()
70+
session = s.sessions[ssrc]
71+
s.mu.Unlock()
72+
return
73+
}
74+
6875
func (s *Server) handle() error {
6976
b := make([]byte, 2048)
7077
for {
@@ -80,14 +87,14 @@ func (s *Server) handle() error {
8087
case 99, 110, 0x80 | 99, 0x80 | 110:
8188
// this is default position for SSRC in RTP packet
8289
ssrc := binary.BigEndian.Uint32(b[8:])
83-
if session, ok := s.sessions[ssrc]; ok {
90+
if session := s.GetSession(ssrc); session != nil {
8491
session.ReadRTP(b[:n])
8592
}
8693

8794
case 200, 201, 202, 203, 204, 205, 206, 207:
8895
// this is default position for SSRC in RTCP packet
8996
ssrc := binary.BigEndian.Uint32(b[4:])
90-
if session, ok := s.sessions[ssrc]; ok {
97+
if session := s.GetSession(ssrc); session != nil {
9198
session.ReadRTCP(b[:n])
9299
}
93100
}

0 commit comments

Comments
 (0)