diff --git a/connclient.go b/connclient.go index a74e7ddc..da4c2484 100644 --- a/connclient.go +++ b/connclient.go @@ -460,7 +460,7 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track, transport.InterleavedIds = &[2]int{(track.Id * 2), (track.Id * 2) + 1} } - trackUrl, err := track.Url(mode) + trackUrl, err := track.Url() if err != nil { if proto == StreamProtocolUDP { rtpListener.close() diff --git a/connclientpublish.go b/connclientpublish.go index 4c3361e1..94815632 100644 --- a/connclientpublish.go +++ b/connclientpublish.go @@ -2,8 +2,11 @@ package gortsplib import ( "fmt" + "strconv" "time" + psdp "github.com/pion/sdp/v3" + "github.com/aler9/gortsplib/pkg/base" ) @@ -16,10 +19,15 @@ func (c *ConnClient) Announce(u *base.URL, tracks Tracks) (*base.Response, error return nil, err } - // fill id and base url + // set id, base url and control attribute on tracks for i, t := range tracks { t.Id = i t.BaseUrl = u + + t.Media.Attributes = append(t.Media.Attributes, psdp.Attribute{ + Key: "control", + Value: "trackID=" + strconv.FormatInt(int64(i), 10), + }) } res, err := c.Do(&base.Request{ diff --git a/track.go b/track.go index 263da335..2f0d4f7f 100644 --- a/track.go +++ b/track.go @@ -11,7 +11,6 @@ import ( psdp "github.com/pion/sdp/v3" "github.com/aler9/gortsplib/pkg/base" - "github.com/aler9/gortsplib/pkg/headers" "github.com/aler9/gortsplib/pkg/sdp" ) @@ -163,18 +162,12 @@ func (t *Track) ClockRate() (int, error) { } // Url returns the track url. -func (t *Track) Url(mode headers.TransportMode) (*base.URL, error) { +func (t *Track) Url() (*base.URL, error) { if t.BaseUrl == nil { return nil, fmt.Errorf("empty base url") } control := func() string { - // if we're publishing, get control from track ID - if mode == headers.TransportModeRecord { - return "trackID=" + strconv.FormatInt(int64(t.Id), 10) - } - - // otherwise, get from media attributes for _, attr := range t.Media.Attributes { if attr.Key == "control" { return attr.Value