Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/stats/stats_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ func (r *recorder) recordOutgoingRTP(latestStats internalStats, v *outgoingRTP)
return latestStats
}

func (r *recorder) recordIncomingRR(latestStats internalStats, pkt *rtcp.ReceiverReport, ts time.Time) internalStats {
for _, report := range pkt.Reports {
func (r *recorder) recordIncomingRR(
latestStats internalStats,
reports []rtcp.ReceptionReport,
ts time.Time,
) internalStats {
for _, report := range reports {
Comment on lines +239 to +244

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question should we check if the report.ssrc matches the recorder ssrc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we probably should. I think this is also relevant for the other RTCP packet types, though. I will create a separate issue.

if latestStats.remoteInboundFirstSequenceNumberInitialized {
cycles := uint64(report.LastSequenceNumber&0xFFFF0000) >> 16
nr := uint64(report.LastSequenceNumber & 0x0000FFFF)
Expand Down Expand Up @@ -312,12 +316,13 @@ func (r *recorder) recordIncomingRTCP(latestStats internalStats, incoming *incom
case *rtcp.PictureLossIndication:
latestStats.OutboundRTPStreamStats.PLICount++
case *rtcp.ReceiverReport:
latestStats = r.recordIncomingRR(latestStats, pkt, incoming.ts)
latestStats = r.recordIncomingRR(latestStats, pkt.Reports, incoming.ts)
case *rtcp.SenderReport:
latestStats.RemoteOutboundRTPStreamStats.PacketsSent = uint64(pkt.PacketCount)
latestStats.RemoteOutboundRTPStreamStats.BytesSent = uint64(pkt.OctetCount)
latestStats.RemoteTimeStamp = ntp.ToTime(pkt.NTPTime)
latestStats.ReportsSent++
latestStats = r.recordIncomingRR(latestStats, pkt.Reports, incoming.ts)

case *rtcp.ExtendedReport:
return r.recordIncomingXR(latestStats, pkt, incoming.ts)
Expand Down
62 changes: 62 additions & 0 deletions pkg/stats/stats_recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,68 @@ func TestStatsRecorder(t *testing.T) {
},
},
},
{
// Copy of basicOutgoingRTP but with RR embedded in a SR
name: "readRRinSR",
records: []record{
{
ts: now,
content: outgoingRTP{
header: rtp.Header{
SequenceNumber: 1,
},
},
},
{
ts: now,
content: outgoingRTP{
header: rtp.Header{
SequenceNumber: 3,
},
},
},
{
ts: now,
content: incomingRTCP{
pkts: []rtcp.Packet{
&rtcp.SenderReport{
SSRC: 0,
NTPTime: ntp.ToNTP(now),
Reports: []rtcp.ReceptionReport{
{
SSRC: 0,
FractionLost: 85,
TotalLost: 1,
LastSequenceNumber: 3,
Jitter: 45000,
},
},
},
cname,
},
},
},
},
expectedOutboundRTPStreamStats: OutboundRTPStreamStats{
SentRTPStreamStats: SentRTPStreamStats{
PacketsSent: 2,
BytesSent: 24,
},
HeaderBytesSent: 24,
},
expectedRemoteInboundRTPStreamStats: RemoteInboundRTPStreamStats{
ReceivedRTPStreamStats: ReceivedRTPStreamStats{
PacketsReceived: 2,
PacketsLost: 1,
Jitter: 0.5,
},
FractionLost: 0.33203125,
},
expectedRemoteOutboundRTPStreamStats: RemoteOutboundRTPStreamStats{
RemoteTimeStamp: ntp.ToTime(ntp.ToNTP(now)),
ReportsSent: 1,
},
},
} {
t.Run(fmt.Sprintf("%v:%v", i, cc.name), func(t *testing.T) {
recorder := newRecorder(0, 90_000, logging.NewDefaultLoggerFactory())
Expand Down
Loading