diff --git a/client/client.go b/client/client.go index 146e7111..dd0b09c0 100644 --- a/client/client.go +++ b/client/client.go @@ -373,7 +373,7 @@ func (c *Client) handleRequest(req *base.Request) error { return errRunTerminate } - basePath, ok := base.URLGetBasePath(req.URL) + basePath, ok := req.URL.BasePath() if !ok { c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL)) return errRunTerminate @@ -432,7 +432,7 @@ func (c *Client) handleRequest(req *base.Request) error { return errRunTerminate } - basePath, ok := base.URLGetBasePath(req.URL) + basePath, ok := req.URL.BasePath() if !ok { c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL)) return errRunTerminate @@ -478,7 +478,7 @@ func (c *Client) handleRequest(req *base.Request) error { return errRunTerminate } - basePath, controlPath, ok := base.URLGetBaseControlPath(req.URL) + basePath, controlPath, ok := req.URL.BaseControlPath() if !ok { c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find control path (%s)", req.URL)) return errRunTerminate @@ -757,7 +757,7 @@ func (c *Client) handleRequest(req *base.Request) error { return errRunTerminate } - basePath, ok := base.URLGetBasePath(req.URL) + basePath, ok := req.URL.BasePath() if !ok { c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL)) return errRunTerminate @@ -796,7 +796,7 @@ func (c *Client) handleRequest(req *base.Request) error { return errRunTerminate } - basePath, ok := base.URLGetBasePath(req.URL) + basePath, ok := req.URL.BasePath() if !ok { c.writeResError(cseq, base.StatusBadRequest, fmt.Errorf("unable to find base path (%s)", req.URL)) return errRunTerminate diff --git a/conf/pathconf.go b/conf/pathconf.go index 5efa8f37..df522188 100644 --- a/conf/pathconf.go +++ b/conf/pathconf.go @@ -9,6 +9,7 @@ import ( "time" "github.com/aler9/gortsplib" + "github.com/aler9/gortsplib/base" ) var reUserPass = regexp.MustCompile("^[a-zA-Z0-9!\\$\\(\\)\\*\\+\\.;<=>\\[\\]\\^_\\-\\{\\}]+$") @@ -77,14 +78,14 @@ func (pconf *PathConf) fillAndCheck(name string) error { return fmt.Errorf("a path with a regular expression (or path 'all') cannot have a RTSP source; use another path") } - u, err := url.Parse(pconf.Source) + u, err := base.ParseURL(pconf.Source) if err != nil { return fmt.Errorf("'%s' is not a valid rtsp url", pconf.Source) } - if u.User != nil { - pass, _ := u.User.Password() - user := u.User.Username() + if u.User() != nil { + pass, _ := u.User().Password() + user := u.User().Username() if user != "" && pass == "" || user == "" && pass != "" { fmt.Errorf("username and password must be both provided") @@ -115,6 +116,9 @@ func (pconf *PathConf) fillAndCheck(name string) error { if err != nil { return fmt.Errorf("'%s' is not a valid rtmp url", pconf.Source) } + if u.Scheme != "rtmp" { + return fmt.Errorf("'%s' is not a valid rtmp url", pconf.Source) + } if u.User != nil { pass, _ := u.User.Password() @@ -130,15 +134,11 @@ func (pconf *PathConf) fillAndCheck(name string) error { return fmt.Errorf("source redirect must be filled") } - u, err := url.Parse(pconf.SourceRedirect) + _, err := base.ParseURL(pconf.SourceRedirect) if err != nil { return fmt.Errorf("'%s' is not a valid rtsp url", pconf.SourceRedirect) } - if u.Scheme != "rtsp" { - return fmt.Errorf("'%s' is not a valid rtsp url", pconf.SourceRedirect) - } - } else { return fmt.Errorf("invalid source: '%s'", pconf.Source) } @@ -152,14 +152,10 @@ func (pconf *PathConf) fillAndCheck(name string) error { } if pconf.Fallback != "" { - u, err := url.Parse(pconf.Fallback) + _, err := base.ParseURL(pconf.Fallback) if err != nil { return fmt.Errorf("'%s' is not a valid rtsp url", pconf.Fallback) } - - if u.Scheme != "rtsp" { - return fmt.Errorf("'%s' is not a valid rtsp url", pconf.Fallback) - } } if pconf.PublishUser != "" { diff --git a/go.mod b/go.mod index 9113fafe..c5d96a3e 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/aler9/gortsplib v0.0.0-20201031143942-e4e66789e9fe + github.com/aler9/gortsplib v0.0.0-20201101180005-b2de7dd8995d github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.4.9 github.com/notedit/rtmp v0.0.2 diff --git a/go.sum b/go.sum index 134b2dc1..a59412ff 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/aler9/gortsplib v0.0.0-20201031143942-e4e66789e9fe h1:iuI/+O8cu9ts0s5kHddFVEMc+oD06MMDWGN59oxUWTI= -github.com/aler9/gortsplib v0.0.0-20201031143942-e4e66789e9fe/go.mod h1:8mpBfMEJIZn2C5fMM6vRYHgGH49WX0EH8gP1SDxv0Uw= +github.com/aler9/gortsplib v0.0.0-20201101180005-b2de7dd8995d h1:jc+kNiLQ36/crZ0y/I6icgv2/ZKDa/DS4DtWPcJ6Duo= +github.com/aler9/gortsplib v0.0.0-20201101180005-b2de7dd8995d/go.mod h1:8mpBfMEJIZn2C5fMM6vRYHgGH49WX0EH8gP1SDxv0Uw= github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625 h1:A3upkpYzceQTuBPvVleu1zd6R8jInhg5ifimSO7ku/o= github.com/aler9/sdp-dirty/v3 v3.0.0-20200919115950-f1abc664f625/go.mod h1:5bO/aUQr9m3OasDatNNcVqKAgs7r5hgGXmszWHaC6mI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= diff --git a/rtsp-simple-server.yml b/rtsp-simple-server.yml index 58c8165d..ee6e028c 100644 --- a/rtsp-simple-server.yml +++ b/rtsp-simple-server.yml @@ -66,7 +66,7 @@ paths: # redirected to. sourceRedirect: - # fallback url to redirect clients to when nobody is publishing to this path + # fallback url to redirect clients to when nobody is publishing to this path. fallback: # username required to publish. diff --git a/sourcertsp/source.go b/sourcertsp/source.go index 2310f1cb..4d7cd3bf 100644 --- a/sourcertsp/source.go +++ b/sourcertsp/source.go @@ -1,12 +1,12 @@ package sourcertsp import ( - "net/url" "sync" "sync/atomic" "time" "github.com/aler9/gortsplib" + "github.com/aler9/gortsplib/base" "github.com/aler9/rtsp-simple-server/stats" ) @@ -103,7 +103,7 @@ func (s *Source) run() { func (s *Source) runInner() bool { s.parent.Log("connecting to rtsp source") - u, _ := url.Parse(s.ur) + u, _ := base.ParseURL(s.ur) var conn *gortsplib.ConnClient var err error @@ -111,7 +111,7 @@ func (s *Source) runInner() bool { go func() { defer close(dialDone) conn, err = gortsplib.NewConnClient(gortsplib.ConnClientConf{ - Host: u.Host, + Host: u.Host(), ReadTimeout: s.readTimeout, WriteTimeout: s.writeTimeout, ReadBufferCount: 2, @@ -150,7 +150,7 @@ func (s *Source) runInner() bool { } } -func (s *Source) runUDP(u *url.URL, conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool { +func (s *Source) runUDP(u *base.URL, conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool { for _, track := range tracks { _, err := conn.SetupUDP(u, gortsplib.TransportModePlay, track, 0, 0) if err != nil { @@ -237,7 +237,7 @@ outer: return ret } -func (s *Source) runTCP(u *url.URL, conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool { +func (s *Source) runTCP(u *base.URL, conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool { for _, track := range tracks { _, err := conn.SetupTCP(u, gortsplib.TransportModePlay, track) if err != nil {