Refactoring for HomeKit client

This commit is contained in:
Alexey Khit
2022-11-11 21:56:58 +03:00
parent 7bc3534bcb
commit 77888fe086
22 changed files with 300 additions and 275 deletions
+12
View File
@@ -8,9 +8,19 @@ import (
// Server using same UDP port for SRTP and for SRTCP as the iPhone does
// this is not really necessary but anyway
type Server struct {
conn net.PacketConn
sessions map[uint32]*Session
}
func (s *Server) Port() uint16 {
addr := s.conn.LocalAddr().(*net.UDPAddr)
return uint16(addr.Port)
}
func (s *Server) Close() error {
return s.conn.Close()
}
func (s *Server) AddSession(session *Session) {
if s.sessions == nil {
s.sessions = map[uint32]*Session{}
@@ -23,6 +33,8 @@ func (s *Server) RemoveSession(session *Session) {
}
func (s *Server) Serve(conn net.PacketConn) error {
s.conn = conn
buf := make([]byte, 2048)
for {
n, addr, err := conn.ReadFrom(buf)
+6 -2
View File
@@ -37,6 +37,10 @@ func (s *Session) HandleRTP(data []byte) (err error) {
return
}
if s.Track == nil {
return
}
packet := &rtp.Packet{}
if err = packet.Unmarshal(data); err != nil {
return
@@ -90,8 +94,8 @@ func GuessProfile(masterKey []byte) srtp.ProtectionProfile {
switch len(masterKey) {
case 16:
return srtp.ProtectionProfileAes128CmHmacSha1_80
//case 32:
// return srtp.ProtectionProfileAes256CmHmacSha1_80
//case 32:
// return srtp.ProtectionProfileAes256CmHmacSha1_80
}
return 0
}