mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
client: move base URL logic into dedicated function
This commit is contained in:
71
client.go
71
client.go
@@ -31,12 +31,48 @@ import (
|
|||||||
"github.com/aler9/gortsplib/pkg/rtcpreceiver"
|
"github.com/aler9/gortsplib/pkg/rtcpreceiver"
|
||||||
"github.com/aler9/gortsplib/pkg/rtcpsender"
|
"github.com/aler9/gortsplib/pkg/rtcpsender"
|
||||||
"github.com/aler9/gortsplib/pkg/rtph264"
|
"github.com/aler9/gortsplib/pkg/rtph264"
|
||||||
|
"github.com/aler9/gortsplib/pkg/sdp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isAnyPort(p int) bool {
|
func isAnyPort(p int) bool {
|
||||||
return p == 0 || p == 1
|
return p == 0 || p == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findBaseURL(sd *sdp.SessionDescription, res *base.Response, u *base.URL) (*base.URL, error) {
|
||||||
|
// use global control attribute
|
||||||
|
if control, ok := sd.Attribute("control"); ok && control != "*" {
|
||||||
|
ret, err := base.ParseURL(control)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid control attribute: '%v'", control)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add credentials
|
||||||
|
ret.User = u.User
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// use Content-Base
|
||||||
|
if cb, ok := res.Header["Content-Base"]; ok {
|
||||||
|
if len(cb) != 1 {
|
||||||
|
return nil, fmt.Errorf("invalid Content-Base: '%v'", cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, err := base.ParseURL(cb[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid Content-Base: '%v'", cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add credentials
|
||||||
|
ret.User = u.User
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// use URL of request
|
||||||
|
return u, nil
|
||||||
|
}
|
||||||
|
|
||||||
type clientState int
|
type clientState int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -1246,40 +1282,7 @@ func (c *Client) doDescribe(u *base.URL) (Tracks, *base.URL, *base.Response, err
|
|||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
baseURL, err := func() (*base.URL, error) {
|
baseURL, err := findBaseURL(sd, res, u)
|
||||||
// use global control attribute
|
|
||||||
if control, ok := sd.Attribute("control"); ok && control != "*" {
|
|
||||||
ret, err := base.ParseURL(control)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid control attribute: '%v'", control)
|
|
||||||
}
|
|
||||||
|
|
||||||
// add credentials
|
|
||||||
ret.User = u.User
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// use Content-Base
|
|
||||||
if cb, ok := res.Header["Content-Base"]; ok {
|
|
||||||
if len(cb) != 1 {
|
|
||||||
return nil, fmt.Errorf("invalid Content-Base: '%v'", cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret, err := base.ParseURL(cb[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid Content-Base: '%v'", cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
// add credentials
|
|
||||||
ret.User = u.User
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// use URL of request
|
|
||||||
return u, nil
|
|
||||||
}()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user