From 6ba5315a4815b3edad423d9fdb8ff4ac5c48608c Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 29 Apr 2020 18:49:09 +0200 Subject: [PATCH] Don't mute clients unless they are suffering packet loss. Otherwise we never recover from low throughput. --- client.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 84eb049..5d03480 100644 --- a/client.go +++ b/client.go @@ -662,15 +662,33 @@ func updateUpBitrate(up *upConnection) { for _, l := range local { ms := atomic.LoadUint64(&l.maxBitrate.timestamp) bitrate := atomic.LoadUint64(&l.maxBitrate.bitrate) + loss := atomic.LoadUint32(&l.loss) if now < ms || now > ms+5000 || bitrate == 0 { + // no rate information l.setMuted(false) continue } - if bitrate < 9600 || - (l.track.Kind() == webrtc.RTPCodecTypeVideo && - bitrate < 128000) { - l.setMuted(true) - continue + + isvideo := l.track.Kind() == webrtc.RTPCodecTypeVideo + minrate1 := uint64(9600) + minrate2 := uint64(19200) + if isvideo { + minrate1 = 256000 + minrate2 = 512000 + } + if bitrate < minrate2 { + if loss <= 13 { + // less than 10% loss, go ahead + bitrate = minrate2 + } else if loss <= 64 || !isvideo { + if bitrate < minrate1 { + bitrate = minrate1 + } + } else { + // video track with dramatic loss + l.setMuted(true) + continue + } } l.setMuted(false) if track.maxBitrate > bitrate {