implement rtcp sender reports

This commit is contained in:
aler9
2020-11-21 23:54:32 +01:00
parent a21bced1dd
commit 2eebf48fca
8 changed files with 233 additions and 42 deletions

View File

@@ -13,6 +13,7 @@ import (
// RtcpReceiver allows to generate RTCP receiver reports.
type RtcpReceiver struct {
mutex sync.Mutex
firstRtpReceived bool
senderSSRC uint32
receiverSSRC uint32
sequenceNumberCycles uint16
@@ -21,7 +22,6 @@ type RtcpReceiver struct {
totalLost uint32
totalLostSinceRR uint32
totalSinceRR uint32
firstRtpReceived bool
}
// New allocates a RtcpReceiver.
@@ -36,7 +36,7 @@ func New(receiverSSRC *uint32) *RtcpReceiver {
}
}
// OnFrame processes a RTP or RTCP frame and extract the data needed by RTCP receiver reports.
// OnFrame processes a RTP or RTCP frame and extract the needed data.
func (rr *RtcpReceiver) OnFrame(streamType base.StreamType, buf []byte) {
rr.mutex.Lock()
defer rr.mutex.Unlock()
@@ -46,11 +46,13 @@ func (rr *RtcpReceiver) OnFrame(streamType base.StreamType, buf []byte) {
// extract the sequence number of the first frame
sequenceNumber := uint16(buf[2])<<8 | uint16(buf[3])
// first frame
if !rr.firstRtpReceived {
rr.firstRtpReceived = true
rr.totalSinceRR = 1
rr.lastSequenceNumber = sequenceNumber
// subsequent frames
} else {
diff := (sequenceNumber - rr.lastSequenceNumber)