mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
client: support server_port=0-1 (https://github.com/aler9/rtsp-simple-server/issues/407)
This commit is contained in:
@@ -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
|
||||
}(),
|
||||
|
@@ -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{}
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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{}
|
||||
|
||||
|
Reference in New Issue
Block a user