diff --git a/rtsp/udp-client.go b/rtsp/udp-client.go index b8196dfa..d0c150ca 100644 --- a/rtsp/udp-client.go +++ b/rtsp/udp-client.go @@ -92,7 +92,10 @@ func (c *UDPClient) SetupAudio() (err error) { } func (c *UDPClient) SetupVideo() (err error) { - logger := c.logger + var ( + logger = c.logger + addr *net.UDPAddr + ) defer func() { if err != nil { logger.Println(err) @@ -101,19 +104,17 @@ func (c *UDPClient) SetupVideo() (err error) { }() host := c.Conn.RemoteAddr().String() host = host[:strings.LastIndex(host, ":")] - addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VPort)) - if err != nil { + if addr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VPort)); err != nil { return } - c.VConn, err = net.DialUDP("udp", nil, addr) - if err != nil { + if c.VConn, err = net.DialUDP("udp", nil, addr); err != nil { return } networkBuffer := utils.Conf().Section("rtsp").Key("network_buffer").MustInt(1048576) - if err := c.VConn.SetReadBuffer(networkBuffer); err != nil { + if err = c.VConn.SetReadBuffer(networkBuffer); err != nil { logger.Printf("udp client video conn set read buffer error, %v", err) } - if err := c.VConn.SetWriteBuffer(networkBuffer); err != nil { + if err = c.VConn.SetWriteBuffer(networkBuffer); err != nil { logger.Printf("udp client video conn set write buffer error, %v", err) } @@ -125,10 +126,10 @@ func (c *UDPClient) SetupVideo() (err error) { if err != nil { return } - if err := c.VControlConn.SetReadBuffer(networkBuffer); err != nil { + if err = c.VControlConn.SetReadBuffer(networkBuffer); err != nil { logger.Printf("udp client video control conn set read buffer error, %v", err) } - if err := c.VControlConn.SetWriteBuffer(networkBuffer); err != nil { + if err = c.VControlConn.SetWriteBuffer(networkBuffer); err != nil { logger.Printf("udp client video control conn set write buffer error, %v", err) } return @@ -157,8 +158,8 @@ func (c *UDPClient) SendRTP(pack *RTPPack) (err error) { err = fmt.Errorf("udp client send rtp pack type[%v] failed, conn not found", pack.Type) return } - n, err := conn.Write(pack.Buffer.Bytes()) - if err != nil { + var n int + if n, err = conn.Write(pack.Buffer.Bytes()); err != nil { err = fmt.Errorf("udp client write bytes error, %v", err) return }