-
Notifications
You must be signed in to change notification settings - Fork 119
/
incomingstreamtrackmirrored.go
150 lines (88 loc) · 2.53 KB
/
incomingstreamtrackmirrored.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package mediaserver
import (
"github.com/notedit/media-server-go/wrapper"
"github.com/notedit/sdp"
)
type mirrorEncoding struct {
id string
source native.RTPIncomingMediaStreamMultiplexer
depacketizer native.StreamTrackDepacketizer
}
type IncomingStreamTrackMirrored struct {
track *IncomingStreamTrack
receiver native.RTPReceiverFacade
counter int
encodings []*mirrorEncoding
}
func NewMirrorIncomingTrack(track *IncomingStreamTrack, timeService native.TimeService) *IncomingStreamTrackMirrored {
mirror := &IncomingStreamTrackMirrored{}
mirror.track = track
mirror.receiver = track.receiver
mirror.counter = 0
mirror.encodings = []*mirrorEncoding{}
for _,encoding := range track.GetEncodings() {
source := native.NewRTPIncomingMediaStreamMultiplexer(encoding.source.GetMedia().GetSsrc(), timeService)
encoding.source.AddListener(source)
newEncoding := &mirrorEncoding{
id: encoding.id,
source: source,
depacketizer: native.NewStreamTrackDepacketizer(source.SwigGetRTPIncomingMediaStream()),
}
mirror.encodings = append(mirror.encodings, newEncoding)
}
mirror.track.Attached()
return mirror
}
func (t *IncomingStreamTrackMirrored) GetStats() map[string]*IncomingAllStats {
return t.track.GetStats()
}
func (t *IncomingStreamTrackMirrored) GetActiveLayers() *ActiveLayersInfo {
return t.track.GetActiveLayers()
}
func (t *IncomingStreamTrackMirrored) GetID() string {
return t.track.GetID()
}
func (t *IncomingStreamTrackMirrored) GetTrackInfo() *sdp.TrackInfo {
return t.GetTrackInfo()
}
func (t *IncomingStreamTrackMirrored) GetSSRCs() {
}
func (t *IncomingStreamTrackMirrored) GetMedia() string {
return t.track.GetMedia()
}
func (t *IncomingStreamTrackMirrored) Attached() bool {
t.counter += 1
if t.counter == 1 {
return true
}
return false
}
func (t *IncomingStreamTrackMirrored) Refresh() {
t.track.Refresh()
}
func (t *IncomingStreamTrackMirrored) Detached() bool {
if t.counter == 0 {
return true
}
t.counter -= 1
if t.counter == 0 {
return true
}
return false
}
func (t *IncomingStreamTrackMirrored) Stop() {
if t.track == nil {
return
}
for i,encoding := range t.track.GetEncodings() {
mencoding := t.encodings[i]
encoding.GetSource().RemoveListener(mencoding.source)
native.DeleteRTPIncomingMediaStreamMultiplexer(t.encodings[i].source)
mencoding.depacketizer.Stop()
native.DeleteStreamTrackDepacketizer(mencoding.depacketizer)
}
t.track.Detached()
t.encodings = nil
t.track = nil
t.receiver = nil
}