* file output * wake under lock * keep track of RTX bytes separately * packet group * Packet group of 50ms * Minor refactoring * rate calculator * send bit rate * WIP * comment * reduce packet infos size * extended twcc seq num * fix packet info * WIP * queuing delay * refactor * config * callbacks * fixes * clean up * remove debug file, fix rate calculation * fmt * fix probes * format * notes * check loss * tweak detection settings * 24-bit wrap * clean up a bit * limit symbol list to number of packets * fmt * clean up * lost * fixes * fmt * rename * fixes * fmt * use min/max * hold on early warning of congestion * make note about need for all optimal allocation on hold release * estimate trend in congested state * tweaks * quantized * fmt * TrendDetector generics * CTR trend * tweaks * config * config * comments * clean up * consistent naming * pariticpant level setting * log usage mode * feedback
96 lines
1.8 KiB
Go
96 lines
1.8 KiB
Go
// Copyright 2023 LiveKit, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package pacer
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/gammazero/deque"
|
|
"github.com/livekit/livekit-server/pkg/sfu/sendsidebwe"
|
|
"github.com/livekit/protocol/logger"
|
|
)
|
|
|
|
type NoQueue struct {
|
|
*Base
|
|
|
|
logger logger.Logger
|
|
|
|
lock sync.RWMutex
|
|
packets deque.Deque[Packet]
|
|
wake chan struct{}
|
|
isStopped bool
|
|
}
|
|
|
|
func NewNoQueue(logger logger.Logger, sendSideBWE *sendsidebwe.SendSideBWE) *NoQueue {
|
|
n := &NoQueue{
|
|
Base: NewBase(logger, sendSideBWE),
|
|
logger: logger,
|
|
wake: make(chan struct{}, 1),
|
|
}
|
|
n.packets.SetMinCapacity(9)
|
|
|
|
go n.sendWorker()
|
|
return n
|
|
}
|
|
|
|
func (n *NoQueue) Stop() {
|
|
n.lock.Lock()
|
|
if n.isStopped {
|
|
n.lock.Unlock()
|
|
return
|
|
}
|
|
|
|
close(n.wake)
|
|
n.isStopped = true
|
|
n.lock.Unlock()
|
|
}
|
|
|
|
func (n *NoQueue) Enqueue(p Packet) {
|
|
n.lock.Lock()
|
|
defer n.lock.Unlock()
|
|
|
|
n.packets.PushBack(p)
|
|
if n.packets.Len() == 1 && !n.isStopped {
|
|
select {
|
|
case n.wake <- struct{}{}:
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
|
|
func (n *NoQueue) sendWorker() {
|
|
for {
|
|
<-n.wake
|
|
for {
|
|
n.lock.Lock()
|
|
if n.isStopped {
|
|
n.lock.Unlock()
|
|
return
|
|
}
|
|
|
|
if n.packets.Len() == 0 {
|
|
n.lock.Unlock()
|
|
break
|
|
}
|
|
p := n.packets.PopFront()
|
|
n.lock.Unlock()
|
|
|
|
n.Base.SendPacket(&p)
|
|
}
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------
|