forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_session_format.go
67 lines (57 loc) · 1.66 KB
/
server_session_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
63
64
65
66
67
package gortsplib
import (
"fmt"
"time"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/aler9/gortsplib/v2/pkg/format"
"github.com/aler9/gortsplib/v2/pkg/rtcpreceiver"
"github.com/aler9/gortsplib/v2/pkg/rtpreorderer"
)
type serverSessionFormat struct {
sm *serverSessionMedia
format format.Format
udpReorderer *rtpreorderer.Reorderer
udpRTCPReceiver *rtcpreceiver.RTCPReceiver
onPacketRTP func(*rtp.Packet)
}
func newServerSessionFormat(sm *serverSessionMedia, forma format.Format) *serverSessionFormat {
return &serverSessionFormat{
sm: sm,
format: forma,
onPacketRTP: func(*rtp.Packet) {},
}
}
func (sf *serverSessionFormat) start() {
if (*sf.sm.ss.setuppedTransport == TransportUDP || *sf.sm.ss.setuppedTransport == TransportUDPMulticast) &&
sf.sm.ss.state != ServerSessionStatePlay {
sf.udpReorderer = rtpreorderer.New()
sf.udpRTCPReceiver = rtcpreceiver.New(
sf.sm.ss.s.udpReceiverReportPeriod,
nil,
sf.format.ClockRate(),
func(pkt rtcp.Packet) {
sf.sm.ss.WritePacketRTCP(sf.sm.media, pkt)
})
}
}
func (sf *serverSessionFormat) stop() {
if sf.udpRTCPReceiver != nil {
sf.udpRTCPReceiver.Close()
sf.udpRTCPReceiver = nil
}
}
func (sf *serverSessionFormat) readRTPUDP(pkt *rtp.Packet, now time.Time) {
packets, missing := sf.udpReorderer.Process(pkt)
if missing != 0 {
onWarning(sf.sm.ss, fmt.Errorf("%d RTP packet(s) lost", missing))
// do not return
}
for _, pkt := range packets {
sf.udpRTCPReceiver.ProcessPacket(pkt, now, sf.format.PTSEqualsDTS(pkt))
sf.onPacketRTP(pkt)
}
}
func (sf *serverSessionFormat) readRTPTCP(pkt *rtp.Packet) {
sf.onPacketRTP(pkt)
}