mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
ServerUDPListener: set writeTimeout once
This commit is contained in:
@@ -37,7 +37,10 @@ func newServer(conf ServerConf, address string) (*Server, error) {
|
|||||||
|
|
||||||
if conf.UDPRTPListener != nil {
|
if conf.UDPRTPListener != nil {
|
||||||
conf.UDPRTPListener.streamType = StreamTypeRTP
|
conf.UDPRTPListener.streamType = StreamTypeRTP
|
||||||
|
conf.UDPRTPListener.writeTimeout = conf.WriteTimeout
|
||||||
|
|
||||||
conf.UDPRTCPListener.streamType = StreamTypeRTCP
|
conf.UDPRTCPListener.streamType = StreamTypeRTCP
|
||||||
|
conf.UDPRTCPListener.writeTimeout = conf.WriteTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
listener, err := conf.Listen("tcp", address)
|
listener, err := conf.Listen("tcp", address)
|
||||||
|
@@ -809,14 +809,14 @@ func (sc *ServerConn) WriteFrame(trackID int, streamType StreamType, payload []b
|
|||||||
track := sc.tracks[trackID]
|
track := sc.tracks[trackID]
|
||||||
|
|
||||||
if streamType == StreamTypeRTP {
|
if streamType == StreamTypeRTP {
|
||||||
return sc.conf.UDPRTPListener.write(sc.conf.WriteTimeout, payload, &net.UDPAddr{
|
return sc.conf.UDPRTPListener.write(payload, &net.UDPAddr{
|
||||||
IP: sc.ip(),
|
IP: sc.ip(),
|
||||||
Zone: sc.zone(),
|
Zone: sc.zone(),
|
||||||
Port: track.rtpPort,
|
Port: track.rtpPort,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return sc.conf.UDPRTCPListener.write(sc.conf.WriteTimeout, payload, &net.UDPAddr{
|
return sc.conf.UDPRTCPListener.write(payload, &net.UDPAddr{
|
||||||
IP: sc.ip(),
|
IP: sc.ip(),
|
||||||
Zone: sc.zone(),
|
Zone: sc.zone(),
|
||||||
Port: track.rtcpPort,
|
Port: track.rtcpPort,
|
||||||
|
@@ -40,6 +40,7 @@ func (p *publisherAddr) fill(ip net.IP, port int) {
|
|||||||
// ServerUDPListener is a UDP server that can be used to send and receive RTP and RTCP packets.
|
// ServerUDPListener is a UDP server that can be used to send and receive RTP and RTCP packets.
|
||||||
type ServerUDPListener struct {
|
type ServerUDPListener struct {
|
||||||
streamType StreamType
|
streamType StreamType
|
||||||
|
writeTimeout time.Duration
|
||||||
|
|
||||||
pc *net.UDPConn
|
pc *net.UDPConn
|
||||||
readBuf *multibuffer.MultiBuffer
|
readBuf *multibuffer.MultiBuffer
|
||||||
@@ -116,11 +117,11 @@ func (s *ServerUDPListener) port() int {
|
|||||||
return s.pc.LocalAddr().(*net.UDPAddr).Port
|
return s.pc.LocalAddr().(*net.UDPAddr).Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerUDPListener) write(writeTimeout time.Duration, buf []byte, addr *net.UDPAddr) error {
|
func (s *ServerUDPListener) write(buf []byte, addr *net.UDPAddr) error {
|
||||||
s.writeMutex.Lock()
|
s.writeMutex.Lock()
|
||||||
defer s.writeMutex.Unlock()
|
defer s.writeMutex.Unlock()
|
||||||
|
|
||||||
s.pc.SetWriteDeadline(time.Now().Add(writeTimeout))
|
s.pc.SetWriteDeadline(time.Now().Add(s.writeTimeout))
|
||||||
_, err := s.pc.WriteTo(buf, addr)
|
_, err := s.pc.WriteTo(buf, addr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user