-
Notifications
You must be signed in to change notification settings - Fork 18
/
streaminfo.go
92 lines (70 loc) · 1.51 KB
/
streaminfo.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
82
83
84
85
86
87
88
89
90
91
92
package sdp
import (
"strings"
)
type StreamInfo struct {
id string
tracks []*TrackInfo
}
func NewStreamInfo(streamID string) *StreamInfo {
return &StreamInfo{
id: streamID,
tracks: make([]*TrackInfo, 0),
}
}
func (s *StreamInfo) Clone() *StreamInfo {
stream := &StreamInfo{
id: s.id,
tracks: make([]*TrackInfo, 0),
}
for k, v := range s.tracks {
stream.tracks[k] = v.Clone()
}
return stream
}
func (s *StreamInfo) GetID() string {
return s.id
}
func (s *StreamInfo) AddTrack(track *TrackInfo) {
s.tracks = append(s.tracks, track)
}
func (s *StreamInfo) RemoveTrack(track *TrackInfo) {
tracks := make([]*TrackInfo,0)
for _,temtrack := range s.tracks {
if temtrack.GetID() != track.GetID() {
tracks = append(tracks,temtrack)
}
}
s.tracks = tracks
}
func (s *StreamInfo) RemoveTrackById(trackId string) {
tracks := make([]*TrackInfo,0)
for _,temtrack := range s.tracks {
if temtrack.GetID() != trackId {
tracks = append(tracks,temtrack)
}
}
s.tracks = tracks
}
func (s *StreamInfo) GetFirstTrack(mediaType string) *TrackInfo {
for _, trak := range s.tracks {
if strings.ToLower(trak.GetMediaType()) == strings.ToLower(mediaType) {
return trak
}
}
return nil
}
func (s *StreamInfo) GetTracks() []*TrackInfo {
return s.tracks
}
func (s *StreamInfo) RemoveAllTracks() {
s.tracks = make([]*TrackInfo,0)
}
func (s *StreamInfo) GetTrack(trackID string) *TrackInfo {
for _,track := range s.tracks {
if track.GetID() == trackID {
return track
}
}
return nil
}