|
|
@ -91,20 +91,21 @@ func (s *UDPServer) Stop() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *UDPServer) SetupAudio() (err error) { |
|
|
|
func (s *UDPServer) SetupAudio() (err error) { |
|
|
|
logger := s.Logger() |
|
|
|
var ( |
|
|
|
addr, err := net.ResolveUDPAddr("udp", ":0") |
|
|
|
logger = s.Logger() |
|
|
|
if err != nil { |
|
|
|
addr *net.UDPAddr |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if addr, err = net.ResolveUDPAddr("udp", ":0"); err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
s.AConn, err = net.ListenUDP("udp", addr) |
|
|
|
if s.AConn, err = net.ListenUDP("udp", addr); err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
networkBuffer := utils.Conf().Section("rtsp").Key("network_buffer").MustInt(1048576) |
|
|
|
networkBuffer := utils.Conf().Section("rtsp").Key("network_buffer").MustInt(1048576) |
|
|
|
if err := s.AConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.AConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server audio conn set read buffer error, %v", err) |
|
|
|
logger.Printf("udp server audio conn set read buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.AConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.AConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server audio conn set write buffer error, %v", err) |
|
|
|
logger.Printf("udp server audio conn set write buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
la := s.AConn.LocalAddr().String() |
|
|
|
la := s.AConn.LocalAddr().String() |
|
|
@ -147,10 +148,10 @@ func (s *UDPServer) SetupAudio() (err error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.AControlConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.AControlConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server audio control conn set read buffer error, %v", err) |
|
|
|
logger.Printf("udp server audio control conn set read buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.AControlConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.AControlConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server audio control conn set write buffer error, %v", err) |
|
|
|
logger.Printf("udp server audio control conn set write buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
la = s.AControlConn.LocalAddr().String() |
|
|
|
la = s.AControlConn.LocalAddr().String() |
|
|
@ -184,8 +185,11 @@ func (s *UDPServer) SetupAudio() (err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
logger := s.Logger() |
|
|
|
var ( |
|
|
|
addr, err := net.ResolveUDPAddr("udp", ":0") |
|
|
|
logger = s.Logger() |
|
|
|
|
|
|
|
addr *net.UDPAddr |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
addr, err = net.ResolveUDPAddr("udp", ":0") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -194,10 +198,10 @@ func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
networkBuffer := utils.Conf().Section("rtsp").Key("network_buffer").MustInt(1048576) |
|
|
|
networkBuffer := utils.Conf().Section("rtsp").Key("network_buffer").MustInt(1048576) |
|
|
|
if err := s.VConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.VConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server video conn set read buffer error, %v", err) |
|
|
|
logger.Printf("udp server video conn set read buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.VConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.VConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server video conn set write buffer error, %v", err) |
|
|
|
logger.Printf("udp server video conn set write buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
la := s.VConn.LocalAddr().String() |
|
|
|
la := s.VConn.LocalAddr().String() |
|
|
@ -212,7 +216,8 @@ func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
defer logger.Printf("udp server stop listen video port[%d]", s.VPort) |
|
|
|
defer logger.Printf("udp server stop listen video port[%d]", s.VPort) |
|
|
|
timer := time.Unix(0, 0) |
|
|
|
timer := time.Unix(0, 0) |
|
|
|
for !s.Stoped { |
|
|
|
for !s.Stoped { |
|
|
|
if n, _, err := s.VConn.ReadFromUDP(bufUDP); err == nil { |
|
|
|
var n int |
|
|
|
|
|
|
|
if n, _, err = s.VConn.ReadFromUDP(bufUDP); err == nil { |
|
|
|
elapsed := time.Now().Sub(timer) |
|
|
|
elapsed := time.Now().Sub(timer) |
|
|
|
if elapsed >= 30*time.Second { |
|
|
|
if elapsed >= 30*time.Second { |
|
|
|
logger.Printf("Package recv from VConn.len:%d\n", n) |
|
|
|
logger.Printf("Package recv from VConn.len:%d\n", n) |
|
|
@ -241,10 +246,10 @@ func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.VControlConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.VControlConn.SetReadBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server video control conn set read buffer error, %v", err) |
|
|
|
logger.Printf("udp server video control conn set read buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := s.VControlConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
if err = s.VControlConn.SetWriteBuffer(networkBuffer); err != nil { |
|
|
|
logger.Printf("udp server video control conn set write buffer error, %v", err) |
|
|
|
logger.Printf("udp server video control conn set write buffer error, %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
la = s.VControlConn.LocalAddr().String() |
|
|
|
la = s.VControlConn.LocalAddr().String() |
|
|
@ -258,7 +263,8 @@ func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
logger.Printf("udp server start listen video control port[%d]", s.VControlPort) |
|
|
|
logger.Printf("udp server start listen video control port[%d]", s.VControlPort) |
|
|
|
defer logger.Printf("udp server stop listen video control port[%d]", s.VControlPort) |
|
|
|
defer logger.Printf("udp server stop listen video control port[%d]", s.VControlPort) |
|
|
|
for !s.Stoped { |
|
|
|
for !s.Stoped { |
|
|
|
if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil { |
|
|
|
var n int |
|
|
|
|
|
|
|
if n, _, err = s.VControlConn.ReadFromUDP(bufUDP); err == nil { |
|
|
|
//logger.Printf("Package recv from VControlConn.len:%d\n", n)
|
|
|
|
//logger.Printf("Package recv from VControlConn.len:%d\n", n)
|
|
|
|
rtpBytes := make([]byte, n) |
|
|
|
rtpBytes := make([]byte, n) |
|
|
|
s.AddInputBytes(n) |
|
|
|
s.AddInputBytes(n) |
|
|
|