mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +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")
|
l, err := net.Listen("tcp", "localhost:8554")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
@@ -215,7 +220,12 @@ func TestClientDialReadZeroServerPorts(t *testing.T) {
|
|||||||
return &v
|
return &v
|
||||||
}(),
|
}(),
|
||||||
ClientPorts: th.ClientPorts,
|
ClientPorts: th.ClientPorts,
|
||||||
ServerPorts: &[2]int{0, 0},
|
ServerPorts: func() *[2]int {
|
||||||
|
if ca == "zero" {
|
||||||
|
return &[2]int{0, 0}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(),
|
||||||
}.Write(),
|
}.Write(),
|
||||||
},
|
},
|
||||||
}.Write(bconn.Writer)
|
}.Write(bconn.Writer)
|
||||||
@@ -257,6 +267,8 @@ func TestClientDialReadZeroServerPorts(t *testing.T) {
|
|||||||
<-frameRecv
|
<-frameRecv
|
||||||
conn.Close()
|
conn.Close()
|
||||||
<-done
|
<-done
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientDialReadAutomaticProtocol(t *testing.T) {
|
func TestClientDialReadAutomaticProtocol(t *testing.T) {
|
||||||
|
@@ -575,21 +575,25 @@ func (c *ClientConn) Setup(mode headers.TransportMode, track *Track,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if proto == StreamProtocolUDP {
|
if proto == StreamProtocolUDP {
|
||||||
if thRes.ServerPorts == nil {
|
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) ||
|
if (thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] != 0) ||
|
||||||
(thRes.ServerPorts[0] != 0 && thRes.ServerPorts[1] == 0) {
|
(thRes.ServerPorts[0] != 0 && thRes.ServerPorts[1] == 0) {
|
||||||
rtpListener.close()
|
rtpListener.close()
|
||||||
rtcpListener.close()
|
rtcpListener.close()
|
||||||
return nil, fmt.Errorf("server ports must be both zero or both not zero")
|
return nil, fmt.Errorf("server ports must be both zero or both not zero")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !c.conf.AnyPortEnable {
|
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 {
|
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")
|
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 {
|
if proto == StreamProtocolUDP {
|
||||||
rtpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
rtpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||||
rtpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
rtpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
||||||
|
if thRes.ServerPorts != nil {
|
||||||
rtpListener.remotePort = (*thRes.ServerPorts)[0]
|
rtpListener.remotePort = (*thRes.ServerPorts)[0]
|
||||||
|
}
|
||||||
rtpListener.trackID = track.ID
|
rtpListener.trackID = track.ID
|
||||||
rtpListener.streamType = StreamTypeRTP
|
rtpListener.streamType = StreamTypeRTP
|
||||||
c.udpRTPListeners[track.ID] = rtpListener
|
c.udpRTPListeners[track.ID] = rtpListener
|
||||||
|
|
||||||
rtcpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
rtcpListener.remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||||
rtcpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
rtcpListener.remoteZone = c.nconn.RemoteAddr().(*net.TCPAddr).Zone
|
||||||
|
if thRes.ServerPorts != nil {
|
||||||
rtcpListener.remotePort = (*thRes.ServerPorts)[1]
|
rtcpListener.remotePort = (*thRes.ServerPorts)[1]
|
||||||
|
}
|
||||||
rtcpListener.trackID = track.ID
|
rtcpListener.trackID = track.ID
|
||||||
rtcpListener.streamType = StreamTypeRTCP
|
rtcpListener.streamType = StreamTypeRTCP
|
||||||
c.udpRTCPListeners[track.ID] = rtcpListener
|
c.udpRTCPListeners[track.ID] = rtcpListener
|
||||||
|
Reference in New Issue
Block a user