Fix backchannel option for Dahua VTO2111D
This commit is contained in:
+38
-21
@@ -61,10 +61,10 @@ type Conn struct {
|
|||||||
|
|
||||||
auth *tcp.Auth
|
auth *tcp.Auth
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
mode Mode
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
sequence int
|
sequence int
|
||||||
|
uri string
|
||||||
mode Mode
|
|
||||||
|
|
||||||
tracks []*streamer.Track
|
tracks []*streamer.Track
|
||||||
channels map[byte]*streamer.Track
|
channels map[byte]*streamer.Track
|
||||||
@@ -76,24 +76,10 @@ type Conn struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(uri string) (*Conn, error) {
|
func NewClient(uri string) (*Conn, error) {
|
||||||
var err error
|
|
||||||
|
|
||||||
c := new(Conn)
|
c := new(Conn)
|
||||||
c.URL, err = url.Parse(uri)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.IndexByte(c.URL.Host, ':') < 0 {
|
|
||||||
c.URL.Host += ":554"
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove UserInfo from URL
|
|
||||||
c.auth = tcp.NewAuth(c.URL.User)
|
|
||||||
c.mode = ModeClientProducer
|
c.mode = ModeClientProducer
|
||||||
c.URL.User = nil
|
c.uri = uri
|
||||||
|
return c, c.parseURI()
|
||||||
return c, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(conn net.Conn) *Conn {
|
func NewServer(conn net.Conn) *Conn {
|
||||||
@@ -104,12 +90,29 @@ func NewServer(conn net.Conn) *Conn {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Conn) parseURI() (err error) {
|
||||||
|
c.URL, err = url.Parse(c.uri)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.IndexByte(c.URL.Host, ':') < 0 {
|
||||||
|
c.URL.Host += ":554"
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove UserInfo from URL
|
||||||
|
c.auth = tcp.NewAuth(c.URL.User)
|
||||||
|
c.URL.User = nil
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Conn) Dial() (err error) {
|
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 {
|
if c.conn != nil {
|
||||||
c.auth.Reset()
|
_ = c.parseURI()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.conn, err = net.DialTimeout(
|
c.conn, err = net.DialTimeout(
|
||||||
@@ -359,7 +362,21 @@ func (c *Conn) SetupMedia(
|
|||||||
var res *tcp.Response
|
var res *tcp.Response
|
||||||
res, err = c.Do(req)
|
res, err = c.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
// Dahua VTO2111D fail on this step because of backchannel
|
||||||
|
if c.Backchannel {
|
||||||
|
if err = c.Dial(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.Backchannel = false
|
||||||
|
if err = c.Describe(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res, err = c.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Session == "" {
|
if c.Session == "" {
|
||||||
|
|||||||
@@ -80,12 +80,6 @@ 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