From 100f72e76cfeeefce86ee69f76322aa8418fe25b Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 1 May 2020 04:08:26 +0200 Subject: [PATCH] Don't count NACK recovery as properly received packets. --- client.go | 7 ++++++- packetcache/packetcache.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 0ed4828..44c6ba4 100644 --- a/client.go +++ b/client.go @@ -10,6 +10,7 @@ import ( "errors" "io" "log" + "math/bits" "os" "strings" "sync" @@ -701,7 +702,11 @@ func sendREMB(pc *webrtc.PeerConnection, ssrc uint32, bitrate uint64) error { } func (up *upConnection) sendNACK(track *upTrack, first uint16, bitmap uint16) error { - return sendNACK(up.pc, track.track.SSRC(), first, bitmap) + err := sendNACK(up.pc, track.track.SSRC(), first, bitmap) + if err == nil { + track.cache.Expect(1 + bits.OnesCount16(bitmap)) + } + return err } func sendNACK(pc *webrtc.PeerConnection, ssrc uint32, first uint16, bitmap uint16) error { diff --git a/packetcache/packetcache.go b/packetcache/packetcache.go index 50aa6f0..b905c87 100644 --- a/packetcache/packetcache.go +++ b/packetcache/packetcache.go @@ -114,6 +114,15 @@ func (cache *Cache) Store(seqno uint16, buf []byte) uint16 { return cache.first } +func (cache *Cache) Expect(n int) { + if n <= 0 { + return + } + cache.mu.Lock() + defer cache.mu.Unlock() + cache.expected += uint32(n) +} + func (cache *Cache) Get(seqno uint16) []byte { cache.mu.Lock() defer cache.mu.Unlock()