Pacer in down stream path. (#1835)
* Pacer interface to send packets * notify outside lock * use select * use pass through pacer * add error to OnSent * Remove log which could get noisy * Starting TWCC work (#1727) * add packet time * WIP commit * WIP commit * WIP commit * minor comments * Some measurements (#1736) * WIP commit * some notes * WIP commit * variable name change and do not post to closed channel * unlock * clean up * comment * Hooking up some more bits for TWCC (#1752) * wake under lock * Pacer in down stream path. Splitting out only the pacer from a feature branch to introduce the concept of pacer. Currently, there should be no difference in functionality as a pass through pacer is used. Another implementation exists which is just put it in a queue and send it from one goroutine. A potential implementation to try would be data paced by bandwidth estimate. That could include priority queues and such. But, the main goal here is to introduce notion of pacer in the down stream path and prepare for more congestion control possibilities down the line. * Don't need peak detector * remove throttling of write IO errors
This commit is contained in:
@@ -104,6 +104,7 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
|
||||
sub.GetBufferFactory(),
|
||||
subscriberID,
|
||||
t.params.ReceiverConfig.PacketBufferSize,
|
||||
sub.GetPacer(),
|
||||
LoggerWithTrack(sub.GetLogger(), trackID, t.params.IsRelayed),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
@@ -231,6 +232,10 @@ func (p *ParticipantImpl) GetAdaptiveStream() bool {
|
||||
return p.params.AdaptiveStream
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) GetPacer() pacer.Pacer {
|
||||
return p.TransportManager.GetSubscriberPacer()
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) ID() livekit.ParticipantID {
|
||||
return p.params.SID
|
||||
}
|
||||
|
||||
+14
-18
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
@@ -185,6 +186,9 @@ type PCTransport struct {
|
||||
// stream allocator for subscriber PC
|
||||
streamAllocator *streamallocator.StreamAllocator
|
||||
|
||||
// only for subscriber PC
|
||||
pacer pacer.Pacer
|
||||
|
||||
previousAnswer *webrtc.SessionDescription
|
||||
// track id -> description map in previous offer sdp
|
||||
previousTrackDescription map[string]*trackDescription
|
||||
@@ -232,9 +236,7 @@ type TransportParams struct {
|
||||
}
|
||||
|
||||
func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimator cc.BandwidthEstimator)) (*webrtc.PeerConnection, *webrtc.MediaEngine, error) {
|
||||
directionConfig := params.DirectionConfig
|
||||
|
||||
me, err := createMediaEngine(params.EnabledCodecs, directionConfig)
|
||||
me, err := createMediaEngine(params.EnabledCodecs, params.DirectionConfig)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -305,21 +307,7 @@ func newPeerConnection(params TransportParams, onBandwidthEstimator func(estimat
|
||||
|
||||
ir := &interceptor.Registry{}
|
||||
if params.IsSendSide {
|
||||
isSendSideBWE := false
|
||||
for _, ext := range directionConfig.RTPHeaderExtension.Video {
|
||||
if ext == sdp.TransportCCURI {
|
||||
isSendSideBWE = true
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, ext := range directionConfig.RTPHeaderExtension.Audio {
|
||||
if ext == sdp.TransportCCURI {
|
||||
isSendSideBWE = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isSendSideBWE {
|
||||
if params.CongestionControlConfig.UseSendSideBWE {
|
||||
gf, err := cc.NewInterceptor(func() (cc.BandwidthEstimator, error) {
|
||||
return gcc.NewSendSideBWE(
|
||||
gcc.SendSideBWEInitialBitrate(1*1000*1000),
|
||||
@@ -376,6 +364,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||
Logger: params.Logger,
|
||||
})
|
||||
t.streamAllocator.Start()
|
||||
t.pacer = pacer.NewPassThrough(params.Logger)
|
||||
}
|
||||
|
||||
if err := t.createPeerConnection(); err != nil {
|
||||
@@ -414,6 +403,10 @@ func (t *PCTransport) createPeerConnection() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetPacer() pacer.Pacer {
|
||||
return t.pacer
|
||||
}
|
||||
|
||||
func (t *PCTransport) SetSignalingRTT(rtt uint32) {
|
||||
t.signalingRTT.Store(rtt)
|
||||
}
|
||||
@@ -898,6 +891,9 @@ func (t *PCTransport) Close() {
|
||||
if t.streamAllocator != nil {
|
||||
t.streamAllocator.Stop()
|
||||
}
|
||||
if t.pacer != nil {
|
||||
t.pacer.Stop()
|
||||
}
|
||||
|
||||
_ = t.pc.Close()
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/streamallocator"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
@@ -283,6 +284,10 @@ func (t *TransportManager) WriteSubscriberRTCP(pkts []rtcp.Packet) error {
|
||||
return t.subscriber.WriteRTCP(pkts)
|
||||
}
|
||||
|
||||
func (t *TransportManager) GetSubscriberPacer() pacer.Pacer {
|
||||
return t.subscriber.GetPacer()
|
||||
}
|
||||
|
||||
func (t *TransportManager) OnPrimaryTransportInitialConnected(f func()) {
|
||||
t.onPrimaryTransportInitialConnected = f
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
|
||||
@@ -383,6 +384,8 @@ type LocalParticipant interface {
|
||||
// down stream bandwidth management
|
||||
SetSubscriberAllowPause(allowPause bool)
|
||||
SetSubscriberChannelCapacity(channelCapacity int64)
|
||||
|
||||
GetPacer() pacer.Pacer
|
||||
}
|
||||
|
||||
// Room is a container of participants, and can provide room-level actions
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -252,6 +253,16 @@ type FakeLocalParticipant struct {
|
||||
getLoggerReturnsOnCall map[int]struct {
|
||||
result1 logger.Logger
|
||||
}
|
||||
GetPacerStub func() pacer.Pacer
|
||||
getPacerMutex sync.RWMutex
|
||||
getPacerArgsForCall []struct {
|
||||
}
|
||||
getPacerReturns struct {
|
||||
result1 pacer.Pacer
|
||||
}
|
||||
getPacerReturnsOnCall map[int]struct {
|
||||
result1 pacer.Pacer
|
||||
}
|
||||
GetPublishedTrackStub func(livekit.TrackID) types.MediaTrack
|
||||
getPublishedTrackMutex sync.RWMutex
|
||||
getPublishedTrackArgsForCall []struct {
|
||||
@@ -2071,6 +2082,59 @@ func (fake *FakeLocalParticipant) GetLoggerReturnsOnCall(i int, result1 logger.L
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacer() pacer.Pacer {
|
||||
fake.getPacerMutex.Lock()
|
||||
ret, specificReturn := fake.getPacerReturnsOnCall[len(fake.getPacerArgsForCall)]
|
||||
fake.getPacerArgsForCall = append(fake.getPacerArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.GetPacerStub
|
||||
fakeReturns := fake.getPacerReturns
|
||||
fake.recordInvocation("GetPacer", []interface{}{})
|
||||
fake.getPacerMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacerCallCount() int {
|
||||
fake.getPacerMutex.RLock()
|
||||
defer fake.getPacerMutex.RUnlock()
|
||||
return len(fake.getPacerArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacerCalls(stub func() pacer.Pacer) {
|
||||
fake.getPacerMutex.Lock()
|
||||
defer fake.getPacerMutex.Unlock()
|
||||
fake.GetPacerStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacerReturns(result1 pacer.Pacer) {
|
||||
fake.getPacerMutex.Lock()
|
||||
defer fake.getPacerMutex.Unlock()
|
||||
fake.GetPacerStub = nil
|
||||
fake.getPacerReturns = struct {
|
||||
result1 pacer.Pacer
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacerReturnsOnCall(i int, result1 pacer.Pacer) {
|
||||
fake.getPacerMutex.Lock()
|
||||
defer fake.getPacerMutex.Unlock()
|
||||
fake.GetPacerStub = nil
|
||||
if fake.getPacerReturnsOnCall == nil {
|
||||
fake.getPacerReturnsOnCall = make(map[int]struct {
|
||||
result1 pacer.Pacer
|
||||
})
|
||||
}
|
||||
fake.getPacerReturnsOnCall[i] = struct {
|
||||
result1 pacer.Pacer
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPublishedTrack(arg1 livekit.TrackID) types.MediaTrack {
|
||||
fake.getPublishedTrackMutex.Lock()
|
||||
ret, specificReturn := fake.getPublishedTrackReturnsOnCall[len(fake.getPublishedTrackArgsForCall)]
|
||||
@@ -5546,6 +5610,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.getICEConnectionTypeMutex.RUnlock()
|
||||
fake.getLoggerMutex.RLock()
|
||||
defer fake.getLoggerMutex.RUnlock()
|
||||
fake.getPacerMutex.RLock()
|
||||
defer fake.getPacerMutex.RUnlock()
|
||||
fake.getPublishedTrackMutex.RLock()
|
||||
defer fake.getPublishedTrackMutex.RUnlock()
|
||||
fake.getPublishedTracksMutex.RLock()
|
||||
|
||||
Reference in New Issue
Block a user