dont fallback to tcp if udp failes
This commit is contained in:
+6
-9
@@ -52,10 +52,8 @@ func (c *Conn) Dial() (err error) {
|
||||
|
||||
if c.Transport != "udp" {
|
||||
c.Protocol = "rtsp+tcp"
|
||||
c.transportMode = TransportTCP
|
||||
} else {
|
||||
c.Protocol = "rtsp+udp"
|
||||
c.transportMode = TransportUDP
|
||||
}
|
||||
} else {
|
||||
conn, err = websocket.Dial(c.Transport)
|
||||
@@ -245,14 +243,13 @@ func (c *Conn) SetupMedia(media *core.Media) (byte, error) {
|
||||
return 0, fmt.Errorf("wrong media: %v", media)
|
||||
}
|
||||
|
||||
if c.transportMode == TransportUDP {
|
||||
if c.Transport == "udp" {
|
||||
transport, err := c.setupUDPTransport()
|
||||
if err == nil {
|
||||
return c.sendSetupRequest(media, transport)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Fall back to TCP if UDP fails
|
||||
c.closeUDP()
|
||||
c.transportMode = TransportTCP
|
||||
|
||||
return c.sendSetupRequest(media, transport)
|
||||
}
|
||||
|
||||
transport = c.setupTCPTransport(mediaIndex)
|
||||
@@ -344,7 +341,7 @@ func (c *Conn) sendSetupRequest(media *core.Media, transport string) (byte, erro
|
||||
// Parse server response
|
||||
responseTransport := res.Header.Get("Transport")
|
||||
|
||||
if c.transportMode == TransportUDP {
|
||||
if c.Transport == "udp" {
|
||||
// Parse UDP response: client_ports=1234-1235;server_port=1234-1235
|
||||
var clientPorts []int
|
||||
var serverPorts []int
|
||||
|
||||
+1
-5
@@ -49,8 +49,6 @@ type Conn struct {
|
||||
state State
|
||||
stateMu sync.Mutex
|
||||
|
||||
transportMode TransportMode
|
||||
|
||||
// UDP
|
||||
|
||||
udpRtpConns map[byte]*UDPConnection
|
||||
@@ -69,8 +67,6 @@ type UDPConnection struct {
|
||||
type TransportMode int
|
||||
|
||||
const (
|
||||
TransportTCP TransportMode = iota
|
||||
TransportUDP
|
||||
ReceiveMTU = 1500
|
||||
)
|
||||
|
||||
@@ -161,7 +157,7 @@ func (c *Conn) Handle() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.transportMode == TransportUDP {
|
||||
if c.Transport == "udp" {
|
||||
if err = c.handleUDPClientData(time); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (c *Conn) packetWriter(codec *core.Codec, channel, payloadType uint8) core.
|
||||
flushBuf := func() {
|
||||
//log.Printf("[rtsp] channel:%2d write_size:%6d buffer_size:%6d", channel, n, len(buf))
|
||||
|
||||
if c.transportMode == TransportUDP {
|
||||
if c.Transport == "udp" {
|
||||
if err := c.sendUDPRtpPacket(buf[:n]); err == nil {
|
||||
c.Send += n
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user