-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmediastream.go
55 lines (46 loc) · 1.42 KB
/
mediastream.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
package peer
import (
"github.com/pion/webrtc/v3"
)
//MediaStreamTrack interaface that wraps together TrackLocal and TrackRemote
type MediaStreamTrack interface {
// ID is the unique identifier for this Track. This should be unique for the
// stream, but doesn't have to globally unique. A common example would be 'audio' or 'video'
// and StreamID would be 'desktop' or 'webcam'
ID() string
// StreamID is the group this track belongs too. This must be unique
StreamID() string
// Kind controls if this TrackLocal is audio or video
Kind() webrtc.RTPCodecType
}
// NewMediaStreamWithTrack create a mediastream with tracks
func NewMediaStreamWithTrack(tracks []MediaStreamTrack) *MediaStream {
m := new(MediaStream)
m.tracks = tracks
return m
}
// MediaStream A stream of media content. A stream consists of several tracks
// such as video or audio tracks. Each track is specified as an instance
// of MediaStreamTrack.
type MediaStream struct {
tracks []MediaStreamTrack
}
// GetTracks returns a list of tracks
func (m *MediaStream) GetTracks() []MediaStreamTrack {
return m.tracks
}
// AddTrack add a track
func (m *MediaStream) AddTrack(t MediaStreamTrack) {
m.tracks = append(m.tracks, t)
}
// RemoveTrack remove a track
func (m *MediaStream) RemoveTrack(t MediaStreamTrack) {
tracks := []MediaStreamTrack{}
for i, t1 := range m.tracks {
if t1 == t {
m.tracks[i] = nil
continue
}
tracks = append(tracks, t1)
}
}