client: use slice instead of map as track storage

This commit is contained in:
aler9
2022-04-07 19:28:29 +02:00
parent 9d12c345f8
commit ccecbf56be

View File

@@ -14,7 +14,6 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net" "net"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -213,7 +212,7 @@ type Client struct {
lastDescribeURL *base.URL lastDescribeURL *base.URL
streamBaseURL *base.URL streamBaseURL *base.URL
effectiveTransport *Transport effectiveTransport *Transport
tracks map[int]*clientTrack tracks []*clientTrack
tracksByChannel map[int]int tracksByChannel map[int]int
lastRange *headers.Range lastRange *headers.Range
writeMutex sync.RWMutex // publish writeMutex sync.RWMutex // publish
@@ -408,19 +407,9 @@ func (c *Client) Wait() error {
// Tracks returns all the tracks that the client is reading or publishing. // Tracks returns all the tracks that the client is reading or publishing.
func (c *Client) Tracks() Tracks { func (c *Client) Tracks() Tracks {
ids := make([]int, len(c.tracks)) ret := make(Tracks, len(c.tracks))
pos := 0 for i, track := range c.tracks {
for id := range c.tracks { ret[i] = track.track
ids[pos] = id
pos++
}
sort.Slice(ids, func(a, b int) bool {
return ids[a] < ids[b]
})
var ret Tracks
for _, id := range ids {
ret = append(ret, c.tracks[id].track)
} }
return ret return ret
} }
@@ -1562,11 +1551,7 @@ func (c *Client) doSetup(
cct.tcpChannel = thRes.InterleavedIDs[0] cct.tcpChannel = thRes.InterleavedIDs[0]
} }
if c.tracks == nil { c.tracks = append(c.tracks, cct)
c.tracks = make(map[int]*clientTrack)
}
c.tracks[trackID] = cct
return res, nil return res, nil
} }