-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
track.go
81 lines (63 loc) · 1.23 KB
/
track.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package moqt
import (
"log/slog"
"time"
)
type Track struct {
/*
* Required
*/
TrackPath string
/*
* Optional
*/
TrackPriority TrackPriority
GroupOrder GroupOrder
GroupExpires time.Duration
// Parameters
AuthorizationInfo string
DeliveryTimeout time.Duration //TODO
AnnounceParameters Parameters
/*
* Internal
*/
latestGroupSequence GroupSequence
}
func (t *Track) Info() Info {
return Info{
TrackPriority: t.TrackPriority,
LatestGroupSequence: t.latestGroupSequence,
GroupOrder: t.GroupOrder,
GroupExpires: t.GroupExpires,
}
}
func NewTracks(ts []Track) Tracks {
tracks := make(Tracks, len(ts))
for _, t := range ts {
err := tracks.Add(t.TrackPath, t)
if err != nil {
slog.Error("failed to add a track", slog.String("error", err.Error()))
return nil
}
}
return tracks
}
type Tracks map[string]Track
func (t Tracks) Get(trackPath string) (Track, bool) {
track, ok := t[trackPath]
return track, ok
}
func (t Tracks) Add(trackPath string, track Track) error {
if t == nil {
t = make(Tracks)
}
_, ok := t[trackPath]
if ok {
return ErrDuplicatedTrack
}
t[trackPath] = track
return nil
}
func (t Tracks) Delete(trackPath string) {
delete(t, trackPath)
}