mirror of
https://github.com/aler9/gortsplib
synced 2025-10-31 02:26:57 +08:00
simplify Track.Url()
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
@@ -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{
|
||||||
|
|||||||
9
track.go
9
track.go
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user