Fix panic on processing RTCP from HomeKit cameras #287

This commit is contained in:
Alexey Khit
2023-06-29 11:13:27 +03:00
parent 253fc4c915
commit 887a491077
+14 -12
View File
@@ -46,10 +46,23 @@ func (s *Server) Serve(conn net.PacketConn) error {
// Multiplexing RTP Data and Control Packets on a Single Port // Multiplexing RTP Data and Control Packets on a Single Port
// https://datatracker.ietf.org/doc/html/rfc5761 // https://datatracker.ietf.org/doc/html/rfc5761
var handle func([]byte) error
// this is default position for SSRC in RTP packet // this is default position for SSRC in RTP packet
ssrc := binary.BigEndian.Uint32(buf[8:]) ssrc := binary.BigEndian.Uint32(buf[8:])
session, ok := s.sessions[ssrc] session, ok := s.sessions[ssrc]
if ok { if ok {
handle = session.HandleRTP
} else {
// this is default position for SSRC in RTCP packet
ssrc = binary.BigEndian.Uint32(buf[4:])
if session, ok = s.sessions[ssrc]; !ok {
continue // skip unknown ssrc
}
handle = session.HandleRTCP
}
if session.Write == nil { if session.Write == nil {
session.Write = func(b []byte) (int, error) { session.Write = func(b []byte) (int, error) {
return conn.WriteTo(b, addr) return conn.WriteTo(b, addr)
@@ -58,19 +71,8 @@ func (s *Server) Serve(conn net.PacketConn) error {
atomic.AddUint32(&session.Recv, uint32(n)) atomic.AddUint32(&session.Recv, uint32(n))
if err = session.HandleRTP(buf[:n]); err != nil { if err = handle(buf[:n]); err != nil {
return err return err
} }
} else {
// this is default position for SSRC in RTCP packet
ssrc = binary.BigEndian.Uint32(buf[4:])
if session, ok = s.sessions[ssrc]; !ok {
continue // skip unknown ssrc
}
if err = session.HandleRTCP(buf[:n]); err != nil {
return err
}
}
} }
} }