* Consolidating PLI throttle

Use the throttler in `sfu.WebRTCReceiver`.

Does change shape of config object.

* Move PLIThrottleConfig to sfu.WebRTCReceiver

* fix test compile

* Cleaning up unused stuff

* improve readability

* RTT

- Calculate down track RTT using RTCP Receiver report
- Surface it back to the participant
- Participant updates all its published trackes
  (throttled to limit update to once in 5 seconds)
- That propagates to all the upstream sfu.Buffer and the nacker.
  So, we will have RTT throttled NACKs.

* rtt callback
This commit is contained in:
Raja Subramanian
2022-02-09 09:34:40 +05:30
committed by GitHub
parent 562546829b
commit 222b02aa73
10 changed files with 156 additions and 108 deletions
+21 -2
View File
@@ -125,6 +125,9 @@ type DownTrack struct {
// when max subscribed layer changes
onMaxLayerChanged func(dt *DownTrack, layer int32)
// update rtt
onRttUpdate func(dt *DownTrack, rtt uint32)
}
// NewDownTrack returns a DownTrack.
@@ -588,6 +591,10 @@ func (d *DownTrack) OnStatsUpdate(fn func(dt *DownTrack, stat *livekit.Analytics
d.onStatsUpdate = fn
}
func (d *DownTrack) OnRttUpdate(fn func(dt *DownTrack, rtt uint32)) {
d.onRttUpdate = fn
}
func (d *DownTrack) OnMaxLayerChanged(fn func(dt *DownTrack, layer int32)) {
d.onMaxLayerChanged = fn
@@ -850,6 +857,8 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
}
}
rttToReport := uint32(0)
var numNACKs uint32
var numPLIs uint32
var numFIRs uint32
@@ -882,10 +891,16 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
d.statsLock.Lock()
d.stats.TotalPacketsLost = r.TotalLost
// RAJA-TODO - calculate RTT and update
rtt := getRttMs(&r)
if rtt != d.stats.RTT {
rttToReport = rtt
}
d.stats.RTT = rtt
d.stats.Jitter = float64(r.Jitter)
d.connectionStats.UpdateWindow(r.SSRC, r.LastSequenceNumber, r.TotalLost, 0, r.Jitter)
d.connectionStats.UpdateWindow(r.SSRC, r.LastSequenceNumber, r.TotalLost, rtt, r.Jitter)
d.statsLock.Unlock()
}
if len(rr.Reports) > 0 {
@@ -916,6 +931,10 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
d.stats.TotalPLIs += numPLIs
d.stats.TotalFIRs += numFIRs
d.statsLock.Unlock()
if rttToReport != 0 && d.onRttUpdate != nil {
d.onRttUpdate(d, rttToReport)
}
}
func (d *DownTrack) retransmitPackets(nackedPackets []packetMeta) {
+15
View File
@@ -1,9 +1,11 @@
package sfu
import (
"math"
"strings"
"time"
"github.com/pion/rtcp"
"github.com/pion/webrtc/v3"
)
@@ -64,3 +66,16 @@ func toNtpTime(t time.Time) ntpTime {
}
return ntpTime(sec<<32 | frac)
}
func getRttMs(report *rtcp.ReceptionReport) uint32 {
if report.LastSenderReport == 0 {
return 0
}
// RTT calculation reference: https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1
// middle 32-bits of current NTP time
now := uint32(toNtpTime(time.Now()) >> 16)
ntpDiff := now - report.LastSenderReport - report.Delay
return uint32(math.Ceil(float64(ntpDiff) * 1000.0 / 65536.0))
}
+4
View File
@@ -191,6 +191,10 @@ func (w *WebRTCReceiver) SetRTT(rtt uint32) {
w.bufferMu.RLock()
for _, buffer := range w.buffers {
if buffer == nil {
continue
}
buffer.SetRTT(rtt)
}
w.bufferMu.RUnlock()