Skip to content

Commit

Permalink
Fix concurrent SRTP sessions map read and map write #1489
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Feb 24, 2025
1 parent 45b223a commit effff6f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/srtp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func (s *Server) DelSession(session *Session) {
s.mu.Unlock()
}

func (s *Server) GetSession(ssrc uint32) (session *Session) {
s.mu.Lock()
session = s.sessions[ssrc]
s.mu.Unlock()
return
}

func (s *Server) handle() error {
b := make([]byte, 2048)
for {
Expand All @@ -80,14 +87,14 @@ func (s *Server) handle() error {
case 99, 110, 0x80 | 99, 0x80 | 110:
// this is default position for SSRC in RTP packet
ssrc := binary.BigEndian.Uint32(b[8:])
if session, ok := s.sessions[ssrc]; ok {
if session := s.GetSession(ssrc); session != nil {
session.ReadRTP(b[:n])
}

case 200, 201, 202, 203, 204, 205, 206, 207:
// this is default position for SSRC in RTCP packet
ssrc := binary.BigEndian.Uint32(b[4:])
if session, ok := s.sessions[ssrc]; ok {
if session := s.GetSession(ssrc); session != nil {
session.ReadRTCP(b[:n])
}
}
Expand Down

0 comments on commit effff6f

Please sign in to comment.