diff --git a/client_read_test.go b/client_read_test.go index af77e7d3..3a917d90 100644 --- a/client_read_test.go +++ b/client_read_test.go @@ -487,6 +487,7 @@ func TestClientReadNoContentBase(t *testing.T) { func TestClientReadAnyPort(t *testing.T) { for _, ca := range []string{ "zero", + "zero_one", "no", } { t.Run(ca, func(t *testing.T) { @@ -556,8 +557,12 @@ func TestClientReadAnyPort(t *testing.T) { }(), ClientPorts: th.ClientPorts, ServerPorts: func() *[2]int { - if ca == "zero" { + switch ca { + case "zero": return &[2]int{0, 0} + + case "zero_one": + return &[2]int{0, 1} } return nil }(), diff --git a/clientconn.go b/clientconn.go index 4b48de19..0aab449c 100644 --- a/clientconn.go +++ b/clientconn.go @@ -37,6 +37,10 @@ func isErrNOUDPPacketsReceivedRecently(err error) bool { return ok } +func isAnyPort(p int) bool { + return p == 0 || p == 1 +} + type clientConnState int const ( @@ -1304,23 +1308,13 @@ func (cc *ClientConn) doSetup( } if proto == StreamProtocolUDP { - 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, liberrors.ErrClientServerPortsZero{} - } - } - if !cc.c.AnyPortEnable { - if thRes.ServerPorts == nil || (thRes.ServerPorts[0] == 0 && thRes.ServerPorts[1] == 0) { + if thRes.ServerPorts == nil || isAnyPort(thRes.ServerPorts[0]) || isAnyPort(thRes.ServerPorts[1]) { rtpListener.close() rtcpListener.close() return nil, liberrors.ErrClientServerPortsNotProvided{} } } - } else { if thRes.InterleavedIDs == nil { return nil, liberrors.ErrClientTransportHeaderNoInterleavedIDs{} diff --git a/clientconnudpl.go b/clientconnudpl.go index 63fcf90b..78625d05 100644 --- a/clientconnudpl.go +++ b/clientconnudpl.go @@ -85,7 +85,7 @@ func (l *clientConnUDPListener) run() { uaddr := addr.(*net.UDPAddr) - if !l.remoteIP.Equal(uaddr.IP) || (l.remotePort != 0 && l.remotePort != uaddr.Port) { + if !l.remoteIP.Equal(uaddr.IP) || (!isAnyPort(l.remotePort) && l.remotePort != uaddr.Port) { continue } @@ -104,7 +104,7 @@ func (l *clientConnUDPListener) run() { uaddr := addr.(*net.UDPAddr) - if !l.remoteIP.Equal(uaddr.IP) || (l.remotePort != 0 && l.remotePort != uaddr.Port) { + if !l.remoteIP.Equal(uaddr.IP) || (!isAnyPort(l.remotePort) && l.remotePort != uaddr.Port) { continue } diff --git a/pkg/liberrors/client.go b/pkg/liberrors/client.go index 6445e3e5..1807805d 100644 --- a/pkg/liberrors/client.go +++ b/pkg/liberrors/client.go @@ -97,14 +97,6 @@ func (e ErrClientUDPPortsNotConsecutive) Error() string { return "rtcpPort must be rtpPort + 1" } -// ErrClientServerPortsZero is an error that can be returned by a client. -type ErrClientServerPortsZero struct{} - -// Error implements the error interface. -func (e ErrClientServerPortsZero) Error() string { - return "server ports must be both zero or both not zero" -} - // ErrClientServerPortsNotProvided is an error that can be returned by a client. type ErrClientServerPortsNotProvided struct{}