From ed00146937086ebf32e5b48a5b1c39937f6ed516 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Sat, 19 Mar 2022 01:06:52 +0530 Subject: [PATCH] Fix packets/packetRate mismatch (#534) This still does not address root cause of large loss, but at least does not display crazy thing like packets = 0, but packet rate is 45/s. Also, RLock in ToString() as there are bits of structure used in stringification. --- pkg/sfu/buffer/rtpstats.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/sfu/buffer/rtpstats.go b/pkg/sfu/buffer/rtpstats.go index ed943a19..3f48e6c7 100644 --- a/pkg/sfu/buffer/rtpstats.go +++ b/pkg/sfu/buffer/rtpstats.go @@ -619,6 +619,9 @@ func (r *RTPStats) ToString() string { return "" } + r.lock.RLock() + defer r.lock.RUnlock() + expectedPackets := p.Packets + p.PacketsLost expectedPacketRate := float64(expectedPackets) / p.Duration @@ -695,11 +698,7 @@ func (r *RTPStats) ToProto() *livekit.RTPStats { } packetsExpected := r.getExtHighestSN() - r.extStartSN + 1 - - packets := packetsExpected - if r.packetsLost < packets { - packets -= r.packetsLost - } + packets := r.getNumPacketsSeen() packetRate := float64(packets) / elapsed bitrate := float64(r.bytes) * 8.0 / elapsed @@ -731,7 +730,7 @@ func (r *RTPStats) ToProto() *livekit.RTPStats { StartTime: timestamppb.New(r.startTime), EndTime: timestamppb.New(endTime), Duration: elapsed, - Packets: r.getNumPacketsSeen(), + Packets: packets, PacketRate: packetRate, Bytes: r.bytes, Bitrate: bitrate,