-
Notifications
You must be signed in to change notification settings - Fork 197
/
server_multicast_writer.go
87 lines (70 loc) · 1.47 KB
/
server_multicast_writer.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
package gortsplib
import (
"net"
"github.com/bluenviron/gortsplib/v4/pkg/liberrors"
)
type serverMulticastWriter struct {
s *Server
rtpl *serverUDPListener
rtcpl *serverUDPListener
writer asyncProcessor
rtpAddr *net.UDPAddr
rtcpAddr *net.UDPAddr
}
func (h *serverMulticastWriter) initialize() error {
ip, err := h.s.getMulticastIP()
if err != nil {
return err
}
rtpl, rtcpl, err := allocateUDPListenerMulticastPair(
h.s.ListenPacket,
h.s.WriteTimeout,
h.s.MulticastRTPPort,
h.s.MulticastRTCPPort,
ip,
)
if err != nil {
return err
}
rtpAddr := &net.UDPAddr{
IP: rtpl.ip(),
Port: rtpl.port(),
}
rtcpAddr := &net.UDPAddr{
IP: rtcpl.ip(),
Port: rtcpl.port(),
}
h.rtpl = rtpl
h.rtcpl = rtcpl
h.rtpAddr = rtpAddr
h.rtcpAddr = rtcpAddr
h.writer.allocateBuffer(h.s.WriteQueueSize)
h.writer.start()
return nil
}
func (h *serverMulticastWriter) close() {
h.rtpl.close()
h.rtcpl.close()
h.writer.stop()
}
func (h *serverMulticastWriter) ip() net.IP {
return h.rtpl.ip()
}
func (h *serverMulticastWriter) writePacketRTP(payload []byte) error {
ok := h.writer.push(func() {
h.rtpl.write(payload, h.rtpAddr) //nolint:errcheck
})
if !ok {
return liberrors.ErrServerWriteQueueFull{}
}
return nil
}
func (h *serverMulticastWriter) writePacketRTCP(payload []byte) error {
ok := h.writer.push(func() {
h.rtcpl.write(payload, h.rtcpAddr) //nolint:errcheck
})
if !ok {
return liberrors.ErrServerWriteQueueFull{}
}
return nil
}