-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathserver_stream_media.go
76 lines (62 loc) · 1.48 KB
/
server_stream_media.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
package gortsplib
import (
"sync/atomic"
"github.com/bluenviron/gortsplib/v4/pkg/description"
)
type serverStreamMedia struct {
st *ServerStream
media *description.Media
trackID int
formats map[uint8]*serverStreamFormat
multicastWriter *serverMulticastWriter
bytesSent *uint64
rtcpPacketsSent *uint64
}
func (sm *serverStreamMedia) initialize() {
sm.bytesSent = new(uint64)
sm.rtcpPacketsSent = new(uint64)
sm.formats = make(map[uint8]*serverStreamFormat)
for _, forma := range sm.media.Formats {
sf := &serverStreamFormat{
sm: sm,
format: forma,
}
sf.initialize()
sm.formats[forma.PayloadType()] = sf
}
}
func (sm *serverStreamMedia) close() {
for _, tr := range sm.formats {
if tr.rtcpSender != nil {
tr.rtcpSender.Close()
}
}
if sm.multicastWriter != nil {
sm.multicastWriter.close()
}
}
func (sm *serverStreamMedia) writePacketRTCP(byts []byte) error {
le := len(byts)
// send unicast
for r := range sm.st.activeUnicastReaders {
if _, ok := r.setuppedMedias[sm.media]; ok {
err := r.writePacketRTCP(sm.media, byts)
if err != nil {
r.onStreamWriteError(err)
continue
}
atomic.AddUint64(sm.bytesSent, uint64(le))
atomic.AddUint64(sm.rtcpPacketsSent, 1)
}
}
// send multicast
if sm.multicastWriter != nil {
err := sm.multicastWriter.writePacketRTCP(byts)
if err != nil {
return err
}
atomic.AddUint64(sm.bytesSent, uint64(le))
atomic.AddUint64(sm.rtcpPacketsSent, 1)
}
return nil
}