From 0ffb8a97e40eaf3beffba15306a6693ed5e0543c Mon Sep 17 00:00:00 2001 From: David Colburn Date: Tue, 22 Jun 2021 15:00:27 -0700 Subject: [PATCH] rtcpThrottle -> pliThrottle --- config-sample.yaml | 8 ++++++++ pkg/config/config.go | 8 ++++---- pkg/rtc/participant.go | 14 +++++++------- pkg/rtc/participant_internal_test.go | 2 +- pkg/rtc/{rtcpthrottle.go => plithrottle.go} | 16 ++++++++-------- pkg/service/roommanager.go | 2 +- 6 files changed, 29 insertions(+), 21 deletions(-) rename pkg/rtc/{rtcpthrottle.go => plithrottle.go} (76%) diff --git a/config-sample.yaml b/config-sample.yaml index 445fac1fa..55f6de2e5 100644 --- a/config-sample.yaml +++ b/config-sample.yaml @@ -36,6 +36,14 @@ rtc: # # LiveKit will automatically configure connected clients to use the same STUN servers # stun_servers: # - server1 +# # minimum amount of time between pli/fir rtcp packets being sent to an individual +# # producer. Increasing these times can lead to longer black screens when participants join, +# # while reducing them can lead to higher producer bitrates. +# pli_throttle: +# low_quality: 1s +# mid_quality: 2s +# high_quality: 3s + # API key / secret pairs. # Keys are used for JWT authentication, server APIs would require a keypair in order to generate access tokens diff --git a/pkg/config/config.go b/pkg/config/config.go index 29af8a9c4..610ae2bf0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -39,11 +39,11 @@ type RTCConfig struct { // Max bitrate for REMB MaxBitrate uint64 `yaml:"max_bitrate"` - // Throttle periods for rtcp packets - Throttle RTCPThrottleConfig `yaml:"rtcp_throttle"` + // Throttle periods for pli/fir rtcp packets + PLIThrottle PLIThrottleConfig `yaml:"pli_throttle"` } -type RTCPThrottleConfig struct { +type PLIThrottleConfig struct { LowQuality time.Duration `yaml:"low_quality"` MidQuality time.Duration `yaml:"mid_quality"` HighQuality time.Duration `yaml:"high_quality"` @@ -93,7 +93,7 @@ func NewConfig(confString string) (*Config, error) { }, MaxBitrate: 3 * 1024 * 1024, // 3 mbps PacketBufferSize: 500, - Throttle: RTCPThrottleConfig{ + PLIThrottle: PLIThrottleConfig{ LowQuality: time.Second, MidQuality: time.Second * 2, HighQuality: time.Second * 3, diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 90dd5c91c..fd8b98872 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -37,7 +37,7 @@ type ParticipantParams struct { AudioConfig config.AudioConfig ProtocolVersion types.ProtocolVersion Stats *RoomStatsReporter - ThrottleConfig config.RTCPThrottleConfig + ThrottleConfig config.PLIThrottleConfig } type ParticipantImpl struct { @@ -50,7 +50,7 @@ type ParticipantImpl struct { state atomic.Value // livekit.ParticipantInfo_State updateAfterActive atomic.Value // bool rtcpCh chan []rtcp.Packet - rtcpThrottle *rtcpThrottle + pliThrottle *pliThrottle // reliable and unreliable data channels reliableDC *webrtc.DataChannel @@ -91,7 +91,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) { params: params, id: utils.NewGuid(utils.ParticipantPrefix), rtcpCh: make(chan []rtcp.Packet, 50), - rtcpThrottle: newRtcpThrottle(params.ThrottleConfig), + pliThrottle: newPLIThrottle(params.ThrottleConfig), subscribedTracks: make(map[string][]types.SubscribedTrack), publishedTracks: make(map[string]types.PublishedTrack, 0), pendingTracks: make(map[string]*livekit.TrackInfo), @@ -401,7 +401,7 @@ func (p *ParticipantImpl) Close() error { if onClose != nil { onClose(p) } - p.rtcpThrottle.close() + p.pliThrottle.close() p.publisher.Close() p.subscriber.Close() close(p.rtcpCh) @@ -739,7 +739,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w } ssrc := uint32(track.SSRC()) - p.rtcpThrottle.addTrack(ssrc, track.RID()) + p.pliThrottle.addTrack(ssrc, track.RID()) if p.twcc == nil { p.twcc = twcc.NewTransportWideCCResponder(ssrc) p.twcc.OnFeedback(func(pkt rtcp.RawPacket) { @@ -840,7 +840,7 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) { p.onTrackUpdated(p, track) } if mt, ok := track.(*MediaTrack); ok { - p.rtcpThrottle.removeTrack(uint32(mt.ssrc)) + p.pliThrottle.removeTrack(uint32(mt.ssrc)) } track.OnClose(nil) }) @@ -958,7 +958,7 @@ func (p *ParticipantImpl) rtcpSendWorker() { continue } - p.rtcpThrottle.add(mediaSSRC, func() { write([]rtcp.Packet{pkt}) }) + p.pliThrottle.add(mediaSSRC, func() { write([]rtcp.Packet{pkt}) }) } if len(fwdPkts) > 0 { diff --git a/pkg/rtc/participant_internal_test.go b/pkg/rtc/participant_internal_test.go index c4150acc9..537ca650d 100644 --- a/pkg/rtc/participant_internal_test.go +++ b/pkg/rtc/participant_internal_test.go @@ -173,7 +173,7 @@ func newParticipantForTest(identity string) *ParticipantImpl { Config: rtcConf, Sink: &routingfakes.FakeMessageSink{}, ProtocolVersion: 0, - ThrottleConfig: conf.RTC.Throttle, + ThrottleConfig: conf.RTC.PLIThrottle, }) return p } diff --git a/pkg/rtc/rtcpthrottle.go b/pkg/rtc/plithrottle.go similarity index 76% rename from pkg/rtc/rtcpthrottle.go rename to pkg/rtc/plithrottle.go index 9ca644a29..e8e907f67 100644 --- a/pkg/rtc/rtcpthrottle.go +++ b/pkg/rtc/plithrottle.go @@ -9,8 +9,8 @@ import ( "github.com/livekit/livekit-server/pkg/config" ) -type rtcpThrottle struct { - config config.RTCPThrottleConfig +type pliThrottle struct { + config config.PLIThrottleConfig mu sync.RWMutex throttles map[uint32]func(func()) } @@ -22,14 +22,14 @@ const ( quarterResolution = "q" ) -func newRtcpThrottle(conf config.RTCPThrottleConfig) *rtcpThrottle { - return &rtcpThrottle{ +func newPLIThrottle(conf config.PLIThrottleConfig) *pliThrottle { + return &pliThrottle{ config: conf, throttles: make(map[uint32]func(func())), } } -func (t *rtcpThrottle) addTrack(ssrc uint32, rid string) { +func (t *pliThrottle) addTrack(ssrc uint32, rid string) { t.mu.Lock() defer t.mu.Unlock() @@ -48,7 +48,7 @@ func (t *rtcpThrottle) addTrack(ssrc uint32, rid string) { t.throttles[ssrc] = throttle.New(duration) } -func (t *rtcpThrottle) add(ssrc uint32, f func()) { +func (t *pliThrottle) add(ssrc uint32, f func()) { t.mu.RLock() defer t.mu.RUnlock() @@ -57,7 +57,7 @@ func (t *rtcpThrottle) add(ssrc uint32, f func()) { } } -func (t *rtcpThrottle) removeTrack(ssrc uint32) { +func (t *pliThrottle) removeTrack(ssrc uint32) { t.mu.Lock() defer t.mu.Unlock() @@ -67,7 +67,7 @@ func (t *rtcpThrottle) removeTrack(ssrc uint32) { } } -func (t *rtcpThrottle) close() { +func (t *pliThrottle) close() { t.mu.Lock() defer t.mu.Unlock() diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 8b45c820a..4b34e3975 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -261,7 +261,7 @@ func (r *RoomManager) StartSession(roomName string, pi routing.ParticipantInit, AudioConfig: r.config.Audio, ProtocolVersion: pv, Stats: room.GetStatsReporter(), - ThrottleConfig: r.config.RTC.Throttle, + ThrottleConfig: r.config.RTC.PLIThrottle, }) if err != nil { logger.Errorw("could not create participant", err)