mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
support servers which don't provide the server-port field (#21)
This commit is contained in:
@@ -149,7 +149,12 @@ func TestClientDialRead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientDialReadZeroServerPorts(t *testing.T) {
|
||||
func TestClientDialReadNoServerPorts(t *testing.T) {
|
||||
for _, ca := range []string{
|
||||
"zero",
|
||||
"no",
|
||||
} {
|
||||
t.Run(ca, func(t *testing.T) {
|
||||
l, err := net.Listen("tcp", "localhost:8554")
|
||||
require.NoError(t, err)
|
||||
defer l.Close()
|
||||
@@ -215,7 +220,12 @@ func TestClientDialReadZeroServerPorts(t *testing.T) {
|
||||
return &v
|
||||
}(),
|
||||
ClientPorts: th.ClientPorts,
|
||||
ServerPorts: &[2]int{0, 0},
|
||||
ServerPorts: func() *[2]int {
|
||||
if ca == "zero" {
|
||||
return &[2]int{0, 0}
|
||||
}
|
||||
return nil
|
||||
}(),
|
||||
}.Write(),
|
||||
},
|
||||
}.Write(bconn.Writer)
|
||||
@@ -257,6 +267,8 @@ func TestClientDialReadZeroServerPorts(t *testing.T) {
|
||||
<-frameRecv
|
||||
conn.Close()
|
||||
<-done
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientDialReadAutomaticProtocol(t *testing.T) {
|
||||
|
@@ -575,21 +575,25 @@ func (c *ClientConn) Setup(mode headers.TransportMode, track *Track,
|
||||
}
|
||||
|
||||
if proto == StreamProtocolUDP {
|
||||
if thRes.ServerPorts == nil {
|
||||
rtpListener.close()
|
||||
rtcpListener.close()
|
||||
return nil, fmt.Errorf("server ports have not been provided. Use AnyPortEnable to communicate with this server")
|
||||
}
|
||||
|
||||
if thRes.ServerPorts != nil {
|
||||
if (thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] != 0) ||
|
||||
(thRes.ServerPorts[0] != 0 && thRes.ServerPorts[1] == 0) {
|
||||
rtpListener.close()
|
||||
rtcpListener.close()
|
||||
return nil, fmt.Errorf("server ports must be both zero or both not zero")
|
||||
}
|
||||
}
|
||||
|
||||
if !c.conf.AnyPortEnable {
|
||||
if thRes.ServerPorts == nil {
|
||||
rtpListener.close()
|
||||
rtcpListener.close()
|
||||
return nil, fmt.Errorf("server ports have not been provided. Use AnyPortEnable to communicate with this server")
|
||||
}
|
||||
|
||||
if thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] == 0 {
|
||||
rtpListener.close()
|
||||
rtcpListener.close()
|
||||
return nil, fmt.Errorf("server ports have not been provided. Use AnyPortEnable to communicate with this server")
|
||||
}
|
||||
}
|
||||
@@ -623,14 +627,18 @@ func (c *ClientConn) Setup(mode headers.TransportMode, track *Track,
|
||||
if proto == StreamProtocolUDP {
|
||||
rtpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||
rtpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
||||
if thRes.ServerPorts != nil {
|
||||
rtpListener.remotePort = (*thRes.ServerPorts)[0]
|
||||
}
|
||||
rtpListener.trackID = track.ID
|
||||
rtpListener.streamType = StreamTypeRTP
|
||||
c.udpRTPListeners[track.ID] = rtpListener
|
||||
|
||||
rtcpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||
rtcpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
||||
if thRes.ServerPorts != nil {
|
||||
rtcpListener.remotePort = (*thRes.ServerPorts)[1]
|
||||
}
|
||||
rtcpListener.trackID = track.ID
|
||||
rtcpListener.streamType = StreamTypeRTCP
|
||||
c.udpRTCPListeners[track.ID] = rtcpListener
|
||||
|
Reference in New Issue
Block a user