Refactoring for HomeKit client
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user