Consolidating PLI throttle (#419)

* 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

* readability improvement
This commit is contained in:
Raja Subramanian
2022-02-08 22:50:43 +05:30
committed by GitHub
parent fee3009853
commit 3117547d60
7 changed files with 62 additions and 117 deletions
+21 -1
View File
@@ -72,6 +72,9 @@ type Buffer struct {
lastSRRecv int64 // Represents wall clock of the most recent sender report arrival
lastTransit uint32
pliThrottle int64
lastPli int64
started bool
stats StreamStats
rrSnapshot *receiverReportSnapshot
@@ -109,6 +112,7 @@ func NewBuffer(ssrc uint32, vp, ap *sync.Pool) *Buffer {
mediaSSRC: ssrc,
videoPool: vp,
audioPool: ap,
pliThrottle: int64(500 * time.Millisecond),
logger: logger.Logger(logger.GetLogger()), // will be reset with correct context via SetLogger
callbackOps: make(chan func(), 50),
}
@@ -278,11 +282,27 @@ func (b *Buffer) OnClose(fn func()) {
b.onClose = fn
}
func (b *Buffer) SendPLI() {
func (b *Buffer) SetPLIThrottle(duration int64) {
b.Lock()
defer b.Unlock()
b.pliThrottle = duration
}
func (b *Buffer) SendPLI() {
now := time.Now().UnixNano()
b.Lock()
throttled := now-b.lastPli < b.pliThrottle
if throttled {
b.Unlock()
return
}
b.lastPli = now
b.stats.TotalPLIs++
b.Unlock()
b.logger.Debugw("send pli", "ssrc", b.mediaSSRC)
pli := []rtcp.Packet{
&rtcp.PictureLossIndication{SenderSSRC: rand.Uint32(), MediaSSRC: b.mediaSSRC},
}