package gortsplib import ( "net" "strconv" "sync/atomic" "time" ) // connClientUDPListener is a UDP listener created by SetupUDP() to receive UDP frames. type connClientUDPListener struct { c *ConnClient pc net.PacketConn trackId int streamType StreamType publisherIp net.IP publisherPort int } func newConnClientUDPListener(c *ConnClient, port int, trackId int, streamType StreamType) (*connClientUDPListener, error) { pc, err := c.conf.ListenPacket("udp", ":"+strconv.FormatInt(int64(port), 10)) if err != nil { return nil, err } return &connClientUDPListener{ c: c, pc: pc, trackId: trackId, streamType: streamType, }, nil } func (l *connClientUDPListener) close() { l.pc.Close() } func (l *connClientUDPListener) read(buf []byte) (int, error) { for { n, addr, err := l.pc.ReadFrom(buf) if err != nil { return 0, err } uaddr := addr.(*net.UDPAddr) if !l.publisherIp.Equal(uaddr.IP) || l.publisherPort != uaddr.Port { continue } atomic.StoreInt64(l.c.udpLastFrameTimes[l.trackId], time.Now().Unix()) l.c.rtcpReceivers[l.trackId].OnFrame(l.streamType, buf[:n]) return n, nil } }