mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
client: deprecate RedirectDisable (#324)
This commit is contained in:
80
client.go
80
client.go
@@ -199,11 +199,8 @@ type Client struct {
|
|||||||
// a TLS configuration to connect to TLS (RTSPS) servers.
|
// a TLS configuration to connect to TLS (RTSPS) servers.
|
||||||
// It defaults to nil.
|
// It defaults to nil.
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
// disable being redirected to other servers, that can happen during Describe().
|
// enable communication with servers which don't provide UDP server ports
|
||||||
// It defaults to false.
|
// or use different server ports than the announced ones.
|
||||||
RedirectDisable bool
|
|
||||||
// enable communication with servers which don't provide server ports or use
|
|
||||||
// different server ports than the ones announced.
|
|
||||||
// This can be a security issue.
|
// This can be a security issue.
|
||||||
// It defaults to false.
|
// It defaults to false.
|
||||||
AnyPortEnable bool
|
AnyPortEnable bool
|
||||||
@@ -224,7 +221,7 @@ type Client struct {
|
|||||||
// It allows to queue packets before sending them.
|
// It allows to queue packets before sending them.
|
||||||
// It defaults to 256.
|
// It defaults to 256.
|
||||||
WriteBufferCount int
|
WriteBufferCount int
|
||||||
// user agent header
|
// user agent header.
|
||||||
// It defaults to "gortsplib"
|
// It defaults to "gortsplib"
|
||||||
UserAgent string
|
UserAgent string
|
||||||
// disable automatic RTCP sender reports.
|
// disable automatic RTCP sender reports.
|
||||||
@@ -233,6 +230,8 @@ type Client struct {
|
|||||||
BytesReceived *uint64
|
BytesReceived *uint64
|
||||||
// pointer to a variable that stores sent bytes.
|
// pointer to a variable that stores sent bytes.
|
||||||
BytesSent *uint64
|
BytesSent *uint64
|
||||||
|
// Deprecated: disabling redirects doesn't improve security.
|
||||||
|
RedirectDisable bool
|
||||||
|
|
||||||
//
|
//
|
||||||
// system functions (all optional)
|
// system functions (all optional)
|
||||||
@@ -538,7 +537,7 @@ func (c *Client) runInner() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doClose() {
|
func (c *Client) doClose() {
|
||||||
if c.state != clientStatePlay && c.state != clientStateRecord && c.conn != nil {
|
if c.connCloser != nil {
|
||||||
c.connCloser.close()
|
c.connCloser.close()
|
||||||
c.connCloser = nil
|
c.connCloser = nil
|
||||||
}
|
}
|
||||||
@@ -1132,39 +1131,37 @@ func (c *Client) doSetup(
|
|||||||
return nil, liberrors.ErrClientCannotSetupMediasDifferentURLs{}
|
return nil, liberrors.ErrClientCannotSetupMediasDifferentURLs{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// always use TCP if encrypted
|
|
||||||
if c.connURL.Scheme == "rtsps" {
|
|
||||||
v := TransportTCP
|
|
||||||
c.effectiveTransport = &v
|
|
||||||
}
|
|
||||||
|
|
||||||
requestedTransport := func() Transport {
|
|
||||||
// transport set by previous Setup() or trySwitchingProtocol()
|
|
||||||
if c.effectiveTransport != nil {
|
|
||||||
return *c.effectiveTransport
|
|
||||||
}
|
|
||||||
|
|
||||||
// transport set by conf
|
|
||||||
if c.Transport != nil {
|
|
||||||
return *c.Transport
|
|
||||||
}
|
|
||||||
|
|
||||||
// try UDP
|
|
||||||
return TransportUDP
|
|
||||||
}()
|
|
||||||
|
|
||||||
mode := headers.TransportModePlay
|
|
||||||
if c.state == clientStatePreRecord {
|
|
||||||
mode = headers.TransportModeRecord
|
|
||||||
}
|
|
||||||
|
|
||||||
th := headers.Transport{
|
th := headers.Transport{
|
||||||
Mode: &mode,
|
Mode: func() *headers.TransportMode {
|
||||||
|
if c.state == clientStatePreRecord {
|
||||||
|
v := headers.TransportModeRecord
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
v := headers.TransportModePlay
|
||||||
|
return &v
|
||||||
|
}(),
|
||||||
}
|
}
|
||||||
|
|
||||||
cm := newClientMedia(c)
|
cm := newClientMedia(c)
|
||||||
|
|
||||||
switch requestedTransport {
|
if c.effectiveTransport == nil {
|
||||||
|
if c.connURL.Scheme == "rtsps" { // always use TCP if encrypted
|
||||||
|
v := TransportTCP
|
||||||
|
c.effectiveTransport = &v
|
||||||
|
} else if c.Transport != nil { // take transport from config
|
||||||
|
c.effectiveTransport = c.Transport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var desiredTransport Transport
|
||||||
|
if c.effectiveTransport != nil {
|
||||||
|
desiredTransport = *c.effectiveTransport
|
||||||
|
} else {
|
||||||
|
desiredTransport = TransportUDP
|
||||||
|
}
|
||||||
|
|
||||||
|
switch desiredTransport {
|
||||||
case TransportUDP:
|
case TransportUDP:
|
||||||
if (rtpPort == 0 && rtcpPort != 0) ||
|
if (rtpPort == 0 && rtcpPort != 0) ||
|
||||||
(rtpPort != 0 && rtcpPort == 0) {
|
(rtpPort != 0 && rtcpPort == 0) {
|
||||||
@@ -1225,8 +1222,7 @@ func (c *Client) doSetup(
|
|||||||
|
|
||||||
// switch transport automatically
|
// switch transport automatically
|
||||||
if res.StatusCode == base.StatusUnsupportedTransport &&
|
if res.StatusCode == base.StatusUnsupportedTransport &&
|
||||||
c.effectiveTransport == nil &&
|
c.effectiveTransport == nil {
|
||||||
c.Transport == nil {
|
|
||||||
c.OnTransportSwitch(fmt.Errorf("switching to TCP because server requested it"))
|
c.OnTransportSwitch(fmt.Errorf("switching to TCP because server requested it"))
|
||||||
v := TransportTCP
|
v := TransportTCP
|
||||||
c.effectiveTransport = &v
|
c.effectiveTransport = &v
|
||||||
@@ -1243,7 +1239,7 @@ func (c *Client) doSetup(
|
|||||||
return nil, liberrors.ErrClientTransportHeaderInvalid{Err: err}
|
return nil, liberrors.ErrClientTransportHeaderInvalid{Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch requestedTransport {
|
switch desiredTransport {
|
||||||
case TransportUDP, TransportUDPMulticast:
|
case TransportUDP, TransportUDPMulticast:
|
||||||
if thRes.Protocol == headers.TransportProtocolTCP {
|
if thRes.Protocol == headers.TransportProtocolTCP {
|
||||||
cm.close()
|
cm.close()
|
||||||
@@ -1259,7 +1255,7 @@ func (c *Client) doSetup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch requestedTransport {
|
switch desiredTransport {
|
||||||
case TransportUDP:
|
case TransportUDP:
|
||||||
if thRes.Delivery != nil && *thRes.Delivery != headers.TransportDeliveryUnicast {
|
if thRes.Delivery != nil && *thRes.Delivery != headers.TransportDeliveryUnicast {
|
||||||
cm.close()
|
cm.close()
|
||||||
@@ -1377,12 +1373,10 @@ func (c *Client) doSetup(
|
|||||||
cm.setMedia(medi)
|
cm.setMedia(medi)
|
||||||
|
|
||||||
c.baseURL = baseURL
|
c.baseURL = baseURL
|
||||||
c.effectiveTransport = &requestedTransport
|
c.effectiveTransport = &desiredTransport
|
||||||
|
|
||||||
if mode == headers.TransportModePlay {
|
if c.state == clientStateInitial {
|
||||||
c.state = clientStatePrePlay
|
c.state = clientStatePrePlay
|
||||||
} else {
|
|
||||||
c.state = clientStatePreRecord
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Reference in New Issue
Block a user