ConnClient: override control attribute of tracks when publishing

This commit is contained in:
aler9
2020-10-04 15:30:40 +02:00
parent 5ca9c545f3
commit a36d16b015
2 changed files with 11 additions and 14 deletions

View File

@@ -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 // build an URL by merging baseUrl with the control attribute from track.Media
func (c *ConnClient) urlForTrack(baseUrl *url.URL, track *Track) *url.URL { func (c *ConnClient) urlForTrack(baseUrl *url.URL, mode SetupMode, track *Track) *url.URL {
// get control attribute
control := func() string { 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 { for _, attr := range track.Media.Attributes {
if attr.Key == "control" { if attr.Key == "control" {
return attr.Value return attr.Value
@@ -446,10 +451,10 @@ func (c *ConnClient) urlForTrack(baseUrl *url.URL, track *Track) *url.URL {
return u 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{ res, err := c.Do(&Request{
Method: SETUP, Method: SETUP,
Url: c.urlForTrack(u, track), Url: c.urlForTrack(u, mode, track),
Header: Header{ Header: Header{
"Transport": ht.Write(), "Transport": ht.Write(),
}, },
@@ -531,7 +536,7 @@ func (c *ConnClient) SetupUDP(u *url.URL, mode SetupMode, track *Track, rtpPort
return nil, err return nil, err
} }
res, err := c.setup(u, track, &HeaderTransport{ res, err := c.setup(u, mode, track, &HeaderTransport{
Protocol: StreamProtocolUDP, Protocol: StreamProtocolUDP,
Cast: func() *StreamCast { Cast: func() *StreamCast {
ret := StreamUnicast 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} 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, Protocol: StreamProtocolTCP,
Cast: func() *StreamCast { Cast: func() *StreamCast {
ret := StreamUnicast ret := StreamUnicast

View File

@@ -47,10 +47,6 @@ func NewTrackH264(id int, sps []byte, pps []byte) (*Track, error) {
"sprop-parameter-sets=" + spropParameterSets + "; " + "sprop-parameter-sets=" + spropParameterSets + "; " +
"profile-level-id=" + profileLevelId, "profile-level-id=" + profileLevelId,
}, },
{
Key: "control",
Value: "trackID=" + strconv.FormatInt(int64(id), 10),
},
}, },
}, },
}, nil }, nil
@@ -103,10 +99,6 @@ func NewTrackAac(id int, config []byte) (*Track, error) {
"indexdeltalength=3; " + "indexdeltalength=3; " +
"config=" + hex.EncodeToString(config), "config=" + hex.EncodeToString(config),
}, },
{
Key: "control",
Value: "trackID=" + strconv.FormatInt(int64(id), 10),
},
}, },
}, },
}, nil }, nil