From 0cdedd53c66f651a38e74255a2b8c687603d081f Mon Sep 17 00:00:00 2001 From: Yohan Totting Date: Wed, 1 May 2024 17:22:08 +0700 Subject: [PATCH] enable duplicate packet --- client.go | 2 +- pkg/pacer/leakybucket.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 5cac258..1d90442 100644 --- a/client.go +++ b/client.go @@ -259,7 +259,7 @@ func NewClient(s *SFU, id string, name string, peerConnectionConfig webrtc.Confi // TODO: we need to use packet loss based bandwidth adjuster when the bandwidth is below 100_000 return gcc.NewSendSideBWE( gcc.SendSideBWEInitialBitrate(int(s.bitrateConfigs.InitialBandwidth)), - gcc.SendSideBWEPacer(pacer.NewLeakyBucketPacer(int(s.bitrateConfigs.InitialBandwidth))), + gcc.SendSideBWEPacer(pacer.NewLeakyBucketPacer(int(s.bitrateConfigs.InitialBandwidth), true)), // gcc.SendSideBWEPacer(gcc.NewNoOpPacer()), ) }) diff --git a/pkg/pacer/leakybucket.go b/pkg/pacer/leakybucket.go index 0ed5f15..b5a1863 100644 --- a/pkg/pacer/leakybucket.go +++ b/pkg/pacer/leakybucket.go @@ -48,6 +48,7 @@ func (q *queue) Remove(e *list.Element) *item { // LeakyBucketPacer implements a leaky bucket pacing algorithm type LeakyBucketPacer struct { + allowDuplicate bool f float64 targetBitrate int targetBitrateLock sync.Mutex @@ -63,8 +64,9 @@ type LeakyBucketPacer struct { } // NewLeakyBucketPacer initializes a new LeakyBucketPacer -func NewLeakyBucketPacer(initialBitrate int) *LeakyBucketPacer { +func NewLeakyBucketPacer(initialBitrate int, allowDuplicate bool) *LeakyBucketPacer { p := &LeakyBucketPacer{ + allowDuplicate: allowDuplicate, f: 1.5, targetBitrate: initialBitrate, pacingInterval: 5 * time.Millisecond, @@ -165,6 +167,12 @@ Loop: currentCache, _ := e.Value.(*item) if currentCache.packet.Header().SequenceNumber == pkt.Header().SequenceNumber { + if p.allowDuplicate { + queue.InsertAfter(newItem, e) + + break Loop + } + glog.Warning("packet cache: packet sequence ", pkt.Header().SequenceNumber, " already exists in the cache, will not adding the packet") return 0, ErrDuplicate