diff --git a/connclient.go b/connclient.go index dd3baf48..18dd4236 100644 --- a/connclient.go +++ b/connclient.go @@ -391,9 +391,14 @@ func (c *ConnClient) Describe(u *url.URL) (Tracks, *Response, error) { } // build an URL by merging baseUrl with the control attribute from track.Media -func (c *ConnClient) urlForTrack(baseUrl *url.URL, track *Track) *url.URL { - // get control attribute +func (c *ConnClient) urlForTrack(baseUrl *url.URL, mode SetupMode, track *Track) *url.URL { control := func() string { + // if we're recording, get control from track ID + if mode == SetupModeRecord { + return "trackID=" + strconv.FormatInt(int64(track.Id), 10) + } + + // otherwise, get from media attributes for _, attr := range track.Media.Attributes { if attr.Key == "control" { return attr.Value @@ -446,10 +451,10 @@ func (c *ConnClient) urlForTrack(baseUrl *url.URL, track *Track) *url.URL { return u } -func (c *ConnClient) setup(u *url.URL, track *Track, ht *HeaderTransport) (*Response, error) { +func (c *ConnClient) setup(u *url.URL, mode SetupMode, track *Track, ht *HeaderTransport) (*Response, error) { res, err := c.Do(&Request{ Method: SETUP, - Url: c.urlForTrack(u, track), + Url: c.urlForTrack(u, mode, track), Header: Header{ "Transport": ht.Write(), }, @@ -531,7 +536,7 @@ func (c *ConnClient) SetupUDP(u *url.URL, mode SetupMode, track *Track, rtpPort return nil, err } - res, err := c.setup(u, track, &HeaderTransport{ + res, err := c.setup(u, mode, track, &HeaderTransport{ Protocol: StreamProtocolUDP, Cast: func() *StreamCast { ret := StreamUnicast @@ -606,7 +611,7 @@ func (c *ConnClient) SetupTCP(u *url.URL, mode SetupMode, track *Track) (*Respon } interleavedIds := [2]int{(track.Id * 2), (track.Id * 2) + 1} - res, err := c.setup(u, track, &HeaderTransport{ + res, err := c.setup(u, mode, track, &HeaderTransport{ Protocol: StreamProtocolTCP, Cast: func() *StreamCast { ret := StreamUnicast diff --git a/track.go b/track.go index 1b73202b..8bbd9d7b 100644 --- a/track.go +++ b/track.go @@ -47,10 +47,6 @@ func NewTrackH264(id int, sps []byte, pps []byte) (*Track, error) { "sprop-parameter-sets=" + spropParameterSets + "; " + "profile-level-id=" + profileLevelId, }, - { - Key: "control", - Value: "trackID=" + strconv.FormatInt(int64(id), 10), - }, }, }, }, nil @@ -103,10 +99,6 @@ func NewTrackAac(id int, config []byte) (*Track, error) { "indexdeltalength=3; " + "config=" + hex.EncodeToString(config), }, - { - Key: "control", - Value: "trackID=" + strconv.FormatInt(int64(id), 10), - }, }, }, }, nil