mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-16 13:20:51 +08:00
Fix busy RTSP backchannel
This commit is contained in:
@@ -65,8 +65,17 @@ func rtspHandler(url string) (streamer.Producer, error) {
|
|||||||
if err = conn.Dial(); err != nil {
|
if err = conn.Dial(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn.Backchannel = true
|
||||||
if err = conn.Describe(); err != nil {
|
if err = conn.Describe(); err != nil {
|
||||||
return nil, err
|
// second try without backchannel, we need to reconnect
|
||||||
|
if err = conn.Dial(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn.Backchannel = false
|
||||||
|
if err = conn.Describe(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
@@ -50,6 +50,8 @@ type Conn struct {
|
|||||||
|
|
||||||
// public
|
// public
|
||||||
|
|
||||||
|
Backchannel bool
|
||||||
|
|
||||||
Medias []*streamer.Media
|
Medias []*streamer.Media
|
||||||
Session string
|
Session string
|
||||||
UserAgent string
|
UserAgent string
|
||||||
@@ -106,6 +108,9 @@ func (c *Conn) Dial() (err error) {
|
|||||||
//if c.state != StateClientInit {
|
//if c.state != StateClientInit {
|
||||||
// panic("wrong state")
|
// panic("wrong state")
|
||||||
//}
|
//}
|
||||||
|
if c.conn != nil && c.auth != nil {
|
||||||
|
c.auth.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
c.conn, err = net.DialTimeout(
|
c.conn, err = net.DialTimeout(
|
||||||
"tcp", c.URL.Host, 10*time.Second,
|
"tcp", c.URL.Host, 10*time.Second,
|
||||||
@@ -258,21 +263,17 @@ func (c *Conn) Describe() error {
|
|||||||
Method: MethodDescribe,
|
Method: MethodDescribe,
|
||||||
URL: c.URL,
|
URL: c.URL,
|
||||||
Header: map[string][]string{
|
Header: map[string][]string{
|
||||||
"Accept": {"application/sdp"},
|
"Accept": {"application/sdp"},
|
||||||
"Require": {"www.onvif.org/ver20/backchannel"},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Backchannel {
|
||||||
|
req.Header.Set("Require", "www.onvif.org/ver20/backchannel")
|
||||||
|
}
|
||||||
|
|
||||||
res, err := c.Do(req)
|
res, err := c.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if res != nil {
|
return err
|
||||||
// if we have answer - give second chanse without onvif header
|
|
||||||
req.Header.Del("Require")
|
|
||||||
res, err = c.Do(req)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := res.Header.Get("Content-Base"); val != "" {
|
if val := res.Header.Get("Content-Base"); val != "" {
|
||||||
|
@@ -80,6 +80,12 @@ func (a *Auth) Write(req *Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Auth) Reset() {
|
||||||
|
if a.Method == AuthDigest {
|
||||||
|
a.Method = AuthUnknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Between(s, sub1, sub2 string) string {
|
func Between(s, sub1, sub2 string) string {
|
||||||
i := strings.Index(s, sub1)
|
i := strings.Index(s, sub1)
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
|
Reference in New Issue
Block a user