-
Notifications
You must be signed in to change notification settings - Fork 199
/
server_stream_format.go
62 lines (51 loc) · 1.27 KB
/
server_stream_format.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
package gortsplib
import (
"sync/atomic"
"time"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/rtcpsender"
)
type serverStreamFormat struct {
sm *serverStreamMedia
format format.Format
rtcpSender *rtcpsender.RTCPSender
}
func (sf *serverStreamFormat) initialize() {
sf.rtcpSender = rtcpsender.New(
sf.format.ClockRate(),
sf.sm.st.s.senderReportPeriod,
sf.sm.st.s.timeNow,
func(pkt rtcp.Packet) {
if !sf.sm.st.s.DisableRTCPSenderReports {
sf.sm.st.WritePacketRTCP(sf.sm.media, pkt) //nolint:errcheck
}
},
)
}
func (sf *serverStreamFormat) writePacketRTP(byts []byte, pkt *rtp.Packet, ntp time.Time) error {
sf.rtcpSender.ProcessPacket(pkt, ntp, sf.format.PTSEqualsDTS(pkt))
le := uint64(len(byts))
// send unicast
for r := range sf.sm.st.activeUnicastReaders {
sm, ok := r.setuppedMedias[sf.sm.media]
if ok {
err := sm.writePacketRTP(byts)
if err != nil {
r.onStreamWriteError(err)
} else {
atomic.AddUint64(sf.sm.st.bytesSent, le)
}
}
}
// send multicast
if sf.sm.multicastWriter != nil {
err := sf.sm.multicastWriter.writePacketRTP(byts)
if err != nil {
return err
}
atomic.AddUint64(sf.sm.st.bytesSent, le)
}
return nil
}