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) {
|
func TestClientReadAnyPort(t *testing.T) {
|
||||||
for _, ca := range []string{
|
for _, ca := range []string{
|
||||||
"zero",
|
"zero",
|
||||||
|
"zero_one",
|
||||||
"no",
|
"no",
|
||||||
} {
|
} {
|
||||||
t.Run(ca, func(t *testing.T) {
|
t.Run(ca, func(t *testing.T) {
|
||||||
@@ -556,8 +557,12 @@ func TestClientReadAnyPort(t *testing.T) {
|
|||||||
}(),
|
}(),
|
||||||
ClientPorts: th.ClientPorts,
|
ClientPorts: th.ClientPorts,
|
||||||
ServerPorts: func() *[2]int {
|
ServerPorts: func() *[2]int {
|
||||||
if ca == "zero" {
|
switch ca {
|
||||||
|
case "zero":
|
||||||
return &[2]int{0, 0}
|
return &[2]int{0, 0}
|
||||||
|
|
||||||
|
case "zero_one":
|
||||||
|
return &[2]int{0, 1}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}(),
|
}(),
|
||||||
|
@@ -37,6 +37,10 @@ func isErrNOUDPPacketsReceivedRecently(err error) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAnyPort(p int) bool {
|
||||||
|
return p == 0 || p == 1
|
||||||
|
}
|
||||||
|
|
||||||
type clientConnState int
|
type clientConnState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -1304,23 +1308,13 @@ func (cc *ClientConn) doSetup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if proto == StreamProtocolUDP {
|
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 !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()
|
rtpListener.close()
|
||||||
rtcpListener.close()
|
rtcpListener.close()
|
||||||
return nil, liberrors.ErrClientServerPortsNotProvided{}
|
return nil, liberrors.ErrClientServerPortsNotProvided{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if thRes.InterleavedIDs == nil {
|
if thRes.InterleavedIDs == nil {
|
||||||
return nil, liberrors.ErrClientTransportHeaderNoInterleavedIDs{}
|
return nil, liberrors.ErrClientTransportHeaderNoInterleavedIDs{}
|
||||||
|
@@ -85,7 +85,7 @@ func (l *clientConnUDPListener) run() {
|
|||||||
|
|
||||||
uaddr := addr.(*net.UDPAddr)
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ func (l *clientConnUDPListener) run() {
|
|||||||
|
|
||||||
uaddr := addr.(*net.UDPAddr)
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -97,14 +97,6 @@ func (e ErrClientUDPPortsNotConsecutive) Error() string {
|
|||||||
return "rtcpPort must be rtpPort + 1"
|
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.
|
// ErrClientServerPortsNotProvided is an error that can be returned by a client.
|
||||||
type ErrClientServerPortsNotProvided struct{}
|
type ErrClientServerPortsNotProvided struct{}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user