diff --git a/format/rtspv2/client.go b/format/rtspv2/client.go index e244a39..9ca70ab 100644 --- a/format/rtspv2/client.go +++ b/format/rtspv2/client.go @@ -106,6 +106,21 @@ type RTSPClientOptions struct { } func Dial(options RTSPClientOptions) (*RTSPClient, error) { + u, err := url.Parse(options.URL) + if err != nil { + return nil, err + } + if u.Port() == "" { + u.Host = fmt.Sprintf("%s:%s", u.Host, "554") + } + conn, err := net.DialTimeout("tcp", u.Host, options.DialTimeout) + if err != nil { + return nil, err + } + return DialWithConn(options, conn) +} + +func DialWithConn(options RTSPClientOptions, conn net.Conn) (*RTSPClient, error) { client := &RTSPClient{ headers: make(map[string]string), Signals: make(chan int, 100), @@ -124,10 +139,6 @@ func Dial(options RTSPClientOptions) (*RTSPClient, error) { if err != nil { return nil, err } - conn, err := net.DialTimeout("tcp", client.pURL.Host, client.options.DialTimeout) - if err != nil { - return nil, err - } err = conn.SetDeadline(time.Now().Add(client.options.ReadWriteTimeout)) if err != nil { return nil, err