rtcpThrottle -> pliThrottle

This commit is contained in:
David Colburn
2021-06-22 15:00:27 -07:00
parent 6b67ba4af0
commit 0ffb8a97e4
6 changed files with 29 additions and 21 deletions
+8
View File
@@ -36,6 +36,14 @@ rtc:
# # LiveKit will automatically configure connected clients to use the same STUN servers # # LiveKit will automatically configure connected clients to use the same STUN servers
# stun_servers: # stun_servers:
# - server1 # - 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. # API key / secret pairs.
# Keys are used for JWT authentication, server APIs would require a keypair in order to generate access tokens # Keys are used for JWT authentication, server APIs would require a keypair in order to generate access tokens
+4 -4
View File
@@ -39,11 +39,11 @@ type RTCConfig struct {
// Max bitrate for REMB // Max bitrate for REMB
MaxBitrate uint64 `yaml:"max_bitrate"` MaxBitrate uint64 `yaml:"max_bitrate"`
// Throttle periods for rtcp packets // Throttle periods for pli/fir rtcp packets
Throttle RTCPThrottleConfig `yaml:"rtcp_throttle"` PLIThrottle PLIThrottleConfig `yaml:"pli_throttle"`
} }
type RTCPThrottleConfig struct { type PLIThrottleConfig struct {
LowQuality time.Duration `yaml:"low_quality"` LowQuality time.Duration `yaml:"low_quality"`
MidQuality time.Duration `yaml:"mid_quality"` MidQuality time.Duration `yaml:"mid_quality"`
HighQuality time.Duration `yaml:"high_quality"` HighQuality time.Duration `yaml:"high_quality"`
@@ -93,7 +93,7 @@ func NewConfig(confString string) (*Config, error) {
}, },
MaxBitrate: 3 * 1024 * 1024, // 3 mbps MaxBitrate: 3 * 1024 * 1024, // 3 mbps
PacketBufferSize: 500, PacketBufferSize: 500,
Throttle: RTCPThrottleConfig{ PLIThrottle: PLIThrottleConfig{
LowQuality: time.Second, LowQuality: time.Second,
MidQuality: time.Second * 2, MidQuality: time.Second * 2,
HighQuality: time.Second * 3, HighQuality: time.Second * 3,
+7 -7
View File
@@ -37,7 +37,7 @@ type ParticipantParams struct {
AudioConfig config.AudioConfig AudioConfig config.AudioConfig
ProtocolVersion types.ProtocolVersion ProtocolVersion types.ProtocolVersion
Stats *RoomStatsReporter Stats *RoomStatsReporter
ThrottleConfig config.RTCPThrottleConfig ThrottleConfig config.PLIThrottleConfig
} }
type ParticipantImpl struct { type ParticipantImpl struct {
@@ -50,7 +50,7 @@ type ParticipantImpl struct {
state atomic.Value // livekit.ParticipantInfo_State state atomic.Value // livekit.ParticipantInfo_State
updateAfterActive atomic.Value // bool updateAfterActive atomic.Value // bool
rtcpCh chan []rtcp.Packet rtcpCh chan []rtcp.Packet
rtcpThrottle *rtcpThrottle pliThrottle *pliThrottle
// reliable and unreliable data channels // reliable and unreliable data channels
reliableDC *webrtc.DataChannel reliableDC *webrtc.DataChannel
@@ -91,7 +91,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
params: params, params: params,
id: utils.NewGuid(utils.ParticipantPrefix), id: utils.NewGuid(utils.ParticipantPrefix),
rtcpCh: make(chan []rtcp.Packet, 50), rtcpCh: make(chan []rtcp.Packet, 50),
rtcpThrottle: newRtcpThrottle(params.ThrottleConfig), pliThrottle: newPLIThrottle(params.ThrottleConfig),
subscribedTracks: make(map[string][]types.SubscribedTrack), subscribedTracks: make(map[string][]types.SubscribedTrack),
publishedTracks: make(map[string]types.PublishedTrack, 0), publishedTracks: make(map[string]types.PublishedTrack, 0),
pendingTracks: make(map[string]*livekit.TrackInfo), pendingTracks: make(map[string]*livekit.TrackInfo),
@@ -401,7 +401,7 @@ func (p *ParticipantImpl) Close() error {
if onClose != nil { if onClose != nil {
onClose(p) onClose(p)
} }
p.rtcpThrottle.close() p.pliThrottle.close()
p.publisher.Close() p.publisher.Close()
p.subscriber.Close() p.subscriber.Close()
close(p.rtcpCh) close(p.rtcpCh)
@@ -739,7 +739,7 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
} }
ssrc := uint32(track.SSRC()) ssrc := uint32(track.SSRC())
p.rtcpThrottle.addTrack(ssrc, track.RID()) p.pliThrottle.addTrack(ssrc, track.RID())
if p.twcc == nil { if p.twcc == nil {
p.twcc = twcc.NewTransportWideCCResponder(ssrc) p.twcc = twcc.NewTransportWideCCResponder(ssrc)
p.twcc.OnFeedback(func(pkt rtcp.RawPacket) { p.twcc.OnFeedback(func(pkt rtcp.RawPacket) {
@@ -840,7 +840,7 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) {
p.onTrackUpdated(p, track) p.onTrackUpdated(p, track)
} }
if mt, ok := track.(*MediaTrack); ok { if mt, ok := track.(*MediaTrack); ok {
p.rtcpThrottle.removeTrack(uint32(mt.ssrc)) p.pliThrottle.removeTrack(uint32(mt.ssrc))
} }
track.OnClose(nil) track.OnClose(nil)
}) })
@@ -958,7 +958,7 @@ func (p *ParticipantImpl) rtcpSendWorker() {
continue continue
} }
p.rtcpThrottle.add(mediaSSRC, func() { write([]rtcp.Packet{pkt}) }) p.pliThrottle.add(mediaSSRC, func() { write([]rtcp.Packet{pkt}) })
} }
if len(fwdPkts) > 0 { if len(fwdPkts) > 0 {
+1 -1
View File
@@ -173,7 +173,7 @@ func newParticipantForTest(identity string) *ParticipantImpl {
Config: rtcConf, Config: rtcConf,
Sink: &routingfakes.FakeMessageSink{}, Sink: &routingfakes.FakeMessageSink{},
ProtocolVersion: 0, ProtocolVersion: 0,
ThrottleConfig: conf.RTC.Throttle, ThrottleConfig: conf.RTC.PLIThrottle,
}) })
return p return p
} }
@@ -9,8 +9,8 @@ import (
"github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/config"
) )
type rtcpThrottle struct { type pliThrottle struct {
config config.RTCPThrottleConfig config config.PLIThrottleConfig
mu sync.RWMutex mu sync.RWMutex
throttles map[uint32]func(func()) throttles map[uint32]func(func())
} }
@@ -22,14 +22,14 @@ const (
quarterResolution = "q" quarterResolution = "q"
) )
func newRtcpThrottle(conf config.RTCPThrottleConfig) *rtcpThrottle { func newPLIThrottle(conf config.PLIThrottleConfig) *pliThrottle {
return &rtcpThrottle{ return &pliThrottle{
config: conf, config: conf,
throttles: make(map[uint32]func(func())), 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() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
@@ -48,7 +48,7 @@ func (t *rtcpThrottle) addTrack(ssrc uint32, rid string) {
t.throttles[ssrc] = throttle.New(duration) 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() t.mu.RLock()
defer t.mu.RUnlock() 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() t.mu.Lock()
defer t.mu.Unlock() 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() t.mu.Lock()
defer t.mu.Unlock() defer t.mu.Unlock()
+1 -1
View File
@@ -261,7 +261,7 @@ func (r *RoomManager) StartSession(roomName string, pi routing.ParticipantInit,
AudioConfig: r.config.Audio, AudioConfig: r.config.Audio,
ProtocolVersion: pv, ProtocolVersion: pv,
Stats: room.GetStatsReporter(), Stats: room.GetStatsReporter(),
ThrottleConfig: r.config.RTC.Throttle, ThrottleConfig: r.config.RTC.PLIThrottle,
}) })
if err != nil { if err != nil {
logger.Errorw("could not create participant", err) logger.Errorw("could not create participant", err)