|
|
|
@ -91,20 +91,21 @@ func (s *UDPServer) Stop() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *UDPServer) SetupAudio() (err error) { |
|
|
|
|
logger := s.Logger() |
|
|
|
|
addr, err := net.ResolveUDPAddr("udp", ":0") |
|
|
|
|
if err != nil { |
|
|
|
|
var ( |
|
|
|
|
logger = s.Logger() |
|
|
|
|
addr *net.UDPAddr |
|
|
|
|
) |
|
|
|
|
if addr, err = net.ResolveUDPAddr("udp", ":0"); err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
s.AConn, err = net.ListenUDP("udp", addr) |
|
|
|
|
if err != nil { |
|
|
|
|
if s.AConn, err = net.ListenUDP("udp", addr); err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
la := s.AConn.LocalAddr().String() |
|
|
|
@ -147,10 +148,10 @@ func (s *UDPServer) SetupAudio() (err error) {
|
|
|
|
|
if err != nil { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
la = s.AControlConn.LocalAddr().String() |
|
|
|
@ -184,8 +185,11 @@ func (s *UDPServer) SetupAudio() (err error) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *UDPServer) SetupVideo() (err error) { |
|
|
|
|
logger := s.Logger() |
|
|
|
|
addr, err := net.ResolveUDPAddr("udp", ":0") |
|
|
|
|
var ( |
|
|
|
|
logger = s.Logger() |
|
|
|
|
addr *net.UDPAddr |
|
|
|
|
) |
|
|
|
|
addr, err = net.ResolveUDPAddr("udp", ":0") |
|
|
|
|
if err != nil { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -194,10 +198,10 @@ func (s *UDPServer) SetupVideo() (err error) {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
timer := time.Unix(0, 0) |
|
|
|
|
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) |
|
|
|
|
if elapsed >= 30*time.Second { |
|
|
|
|
logger.Printf("Package recv from VConn.len:%d\n", n) |
|
|
|
@ -241,10 +246,10 @@ func (s *UDPServer) SetupVideo() (err error) {
|
|
|
|
|
if err != nil { |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
defer logger.Printf("udp server stop listen video control port[%d]", s.VControlPort) |
|
|
|
|
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)
|
|
|
|
|
rtpBytes := make([]byte, n) |
|
|
|
|
s.AddInputBytes(n) |
|
|
|
|