simplify Track.Url()

This commit is contained in:
aler9
2020-11-30 21:48:39 +01:00
parent 6b4fe73270
commit 20fd1459fc
3 changed files with 11 additions and 10 deletions

View File

@@ -460,7 +460,7 @@ func (c *ConnClient) Setup(mode headers.TransportMode, track *Track,
transport.InterleavedIds = &[2]int{(track.Id * 2), (track.Id * 2) + 1} transport.InterleavedIds = &[2]int{(track.Id * 2), (track.Id * 2) + 1}
} }
trackUrl, err := track.Url(mode) trackUrl, err := track.Url()
if err != nil { if err != nil {
if proto == StreamProtocolUDP { if proto == StreamProtocolUDP {
rtpListener.close() rtpListener.close()

View File

@@ -2,8 +2,11 @@ package gortsplib
import ( import (
"fmt" "fmt"
"strconv"
"time" "time"
psdp "github.com/pion/sdp/v3"
"github.com/aler9/gortsplib/pkg/base" "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 return nil, err
} }
// fill id and base url // set id, base url and control attribute on tracks
for i, t := range tracks { for i, t := range tracks {
t.Id = i t.Id = i
t.BaseUrl = u 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{ res, err := c.Do(&base.Request{

View File

@@ -11,7 +11,6 @@ import (
psdp "github.com/pion/sdp/v3" psdp "github.com/pion/sdp/v3"
"github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/gortsplib/pkg/sdp" "github.com/aler9/gortsplib/pkg/sdp"
) )
@@ -163,18 +162,12 @@ func (t *Track) ClockRate() (int, error) {
} }
// Url returns the track url. // 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 { if t.BaseUrl == nil {
return nil, fmt.Errorf("empty base url") return nil, fmt.Errorf("empty base url")
} }
control := func() string { 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 { for _, attr := range t.Media.Attributes {
if attr.Key == "control" { if attr.Key == "control" {
return attr.Value return attr.Value