Split out audio level config. (#3163)

* Split out audio level config.

Inline it in yaml as it is exposed/documented config.

* test

* default congestion control enable
This commit is contained in:
Raja Subramanian
2024-11-08 21:36:38 +05:30
committed by GitHub
parent 86383b2271
commit 653857e42b
5 changed files with 52 additions and 36 deletions
+4 -1
View File
@@ -126,7 +126,7 @@ type CongestionControlConfig struct {
Enabled bool `yaml:"enabled,omitempty"` Enabled bool `yaml:"enabled,omitempty"`
AllowPause bool `yaml:"allow_pause,omitempty"` AllowPause bool `yaml:"allow_pause,omitempty"`
StreamAllocator streamallocator.StreamAllocatorConfig `yaml:"stream_allocator,omitempty"` StreamAllocator streamallocator.StreamAllocatorConfig `yaml:"stream_allocator,omitempty"`
UseSendSideBWE bool `yaml:"send_side_bandwidth_estimation,omitempty"` UseSendSideBWE bool `yaml:"use_send_side_bwe,omitempty"`
} }
type PlayoutDelayConfig struct { type PlayoutDelayConfig struct {
@@ -305,7 +305,10 @@ var DefaultConfig = Config{
StrictACKs: true, StrictACKs: true,
PLIThrottle: sfu.DefaultPLIThrottleConfig, PLIThrottle: sfu.DefaultPLIThrottleConfig,
CongestionControl: CongestionControlConfig{ CongestionControl: CongestionControlConfig{
Enabled: true,
AllowPause: false,
StreamAllocator: streamallocator.DefaultStreamAllocatorConfig, StreamAllocator: streamallocator.DefaultStreamAllocatorConfig,
UseSendSideBWE: false,
}, },
}, },
Audio: sfu.DefaultAudioConfig, Audio: sfu.DefaultAudioConfig,
+2
View File
@@ -804,9 +804,11 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *Room {
DepartureTimeout: 1, DepartureTimeout: 1,
}, },
&sfu.AudioConfig{ &sfu.AudioConfig{
AudioLevelConfig: audio.AudioLevelConfig{
UpdateInterval: audioUpdateInterval, UpdateInterval: audioUpdateInterval,
SmoothIntervals: opts.audioSmoothIntervals, SmoothIntervals: opts.audioSmoothIntervals,
}, },
},
&livekit.ServerInfo{ &livekit.ServerInfo{
Edition: livekit.ServerInfo_Standard, Edition: livekit.ServerInfo_Standard,
Version: version.Version, Version: version.Version,
+35 -12
View File
@@ -24,11 +24,34 @@ const (
negInv20 = -1.0 / 20 negInv20 = -1.0 / 20
) )
// --------------------------------------
type AudioLevelConfig struct {
// minimum level to be considered active, 0-127, where 0 is loudest
ActiveLevel uint8 `yaml:"active_level,omitempty"`
// percentile to measure, a participant is considered active if it has exceeded the ActiveLevel more than
// MinPercentile% of the time
MinPercentile uint8 `yaml:"min_percentile,omitempty"`
// interval to update clients, in ms
UpdateInterval uint32 `yaml:"update_interval,omitempty"`
// smoothing for audioLevel values sent to the client.
// audioLevel will be an average of `smooth_intervals`, 0 to disable
SmoothIntervals uint32 `yaml:"smooth_intervals,omitempty"`
}
var (
DefaultAudioLevelConfig = AudioLevelConfig{
ActiveLevel: 35, // -35dBov
MinPercentile: 40,
UpdateInterval: 400,
SmoothIntervals: 2,
}
)
// --------------------------------------
type AudioLevelParams struct { type AudioLevelParams struct {
ActiveLevel uint8 Config AudioLevelConfig
MinPercentile uint8
ObserveDuration uint32
SmoothIntervals uint32
} }
// keeps track of audio level for a participant // keeps track of audio level for a participant
@@ -51,15 +74,15 @@ type AudioLevel struct {
func NewAudioLevel(params AudioLevelParams) *AudioLevel { func NewAudioLevel(params AudioLevelParams) *AudioLevel {
l := &AudioLevel{ l := &AudioLevel{
params: params, params: params,
minActiveDuration: uint32(params.MinPercentile) * params.ObserveDuration / 100, minActiveDuration: uint32(params.Config.MinPercentile) * params.Config.UpdateInterval / 100,
smoothFactor: 1, smoothFactor: 1,
activeThreshold: ConvertAudioLevel(float64(params.ActiveLevel)), activeThreshold: ConvertAudioLevel(float64(params.Config.ActiveLevel)),
loudestObservedLevel: silentAudioLevel, loudestObservedLevel: silentAudioLevel,
} }
if l.params.SmoothIntervals > 0 { if l.params.Config.SmoothIntervals > 0 {
// exponential moving average (EMA), same center of mass with simple moving average (SMA) // exponential moving average (EMA), same center of mass with simple moving average (SMA)
l.smoothFactor = float64(2) / (float64(l.params.SmoothIntervals + 1)) l.smoothFactor = float64(2) / (float64(l.params.Config.SmoothIntervals + 1))
} }
return l return l
@@ -74,14 +97,14 @@ func (l *AudioLevel) Observe(level uint8, durationMs uint32, arrivalTime int64)
l.observedDuration += durationMs l.observedDuration += durationMs
if level <= l.params.ActiveLevel { if level <= l.params.Config.ActiveLevel {
l.activeDuration += durationMs l.activeDuration += durationMs
if l.loudestObservedLevel > level { if l.loudestObservedLevel > level {
l.loudestObservedLevel = level l.loudestObservedLevel = level
} }
} }
if l.observedDuration >= l.params.ObserveDuration { if l.observedDuration >= l.params.Config.UpdateInterval {
smoothedLevel := float64(0.0) smoothedLevel := float64(0.0)
// compute and reset // compute and reset
if l.activeDuration >= l.minActiveDuration { if l.activeDuration >= l.minActiveDuration {
@@ -89,7 +112,7 @@ func (l *AudioLevel) Observe(level uint8, durationMs uint32, arrivalTime int64)
// Weight will be 0 if active the entire duration // Weight will be 0 if active the entire duration
// > 0 if active for longer than observe duration // > 0 if active for longer than observe duration
// < 0 if active for less than observe duration // < 0 if active for less than observe duration
activityWeight := 20 * math.Log10(float64(l.activeDuration)/float64(l.params.ObserveDuration)) activityWeight := 20 * math.Log10(float64(l.activeDuration)/float64(l.params.Config.UpdateInterval))
adjustedLevel := float64(l.loudestObservedLevel) - activityWeight adjustedLevel := float64(l.loudestObservedLevel) - activityWeight
linearLevel := ConvertAudioLevel(adjustedLevel) linearLevel := ConvertAudioLevel(adjustedLevel)
@@ -111,7 +134,7 @@ func (l *AudioLevel) GetLevel(now int64) (float64, bool) {
} }
func (l *AudioLevel) resetIfStaleLocked(arrivalTime int64) { func (l *AudioLevel) resetIfStaleLocked(arrivalTime int64) {
if (arrivalTime-l.lastObservedAt)/1e6 < int64(2*l.params.ObserveDuration) { if (arrivalTime-l.lastObservedAt)/1e6 < int64(2*l.params.Config.UpdateInterval) {
return return
} }
+3 -1
View File
@@ -108,9 +108,11 @@ func TestAudioLevel(t *testing.T) {
func createAudioLevel(activeLevel uint8, minPercentile uint8, observeDuration uint32) *AudioLevel { func createAudioLevel(activeLevel uint8, minPercentile uint8, observeDuration uint32) *AudioLevel {
return NewAudioLevel(AudioLevelParams{ return NewAudioLevel(AudioLevelParams{
Config: AudioLevelConfig{
ActiveLevel: activeLevel, ActiveLevel: activeLevel,
MinPercentile: minPercentile, MinPercentile: minPercentile,
ObserveDuration: observeDuration, UpdateInterval: observeDuration,
},
}) })
} }
+4 -18
View File
@@ -63,16 +63,8 @@ var (
// -------------------------------------- // --------------------------------------
type AudioConfig struct { type AudioConfig struct {
// minimum level to be considered active, 0-127, where 0 is loudest audio.AudioLevelConfig `yaml:",inline"`
ActiveLevel uint8 `yaml:"active_level,omitempty"`
// percentile to measure, a participant is considered active if it has exceeded the ActiveLevel more than
// MinPercentile% of the time
MinPercentile uint8 `yaml:"min_percentile,omitempty"`
// interval to update clients, in ms
UpdateInterval uint32 `yaml:"update_interval,omitempty"`
// smoothing for audioLevel values sent to the client.
// audioLevel will be an average of `smooth_intervals`, 0 to disable
SmoothIntervals uint32 `yaml:"smooth_intervals,omitempty"`
// enable red encoding downtrack for opus only audio up track // enable red encoding downtrack for opus only audio up track
ActiveREDEncoding bool `yaml:"active_red_encoding,omitempty"` ActiveREDEncoding bool `yaml:"active_red_encoding,omitempty"`
// enable proxying weakest subscriber loss to publisher in RTCP Receiver Report // enable proxying weakest subscriber loss to publisher in RTCP Receiver Report
@@ -81,10 +73,7 @@ type AudioConfig struct {
var ( var (
DefaultAudioConfig = AudioConfig{ DefaultAudioConfig = AudioConfig{
ActiveLevel: 35, // -35dBov AudioLevelConfig: audio.DefaultAudioLevelConfig,
MinPercentile: 40,
UpdateInterval: 400,
SmoothIntervals: 2,
} }
) )
@@ -379,10 +368,7 @@ func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buff
} }
buff.SetLogger(w.logger.WithValues("layer", layer)) buff.SetLogger(w.logger.WithValues("layer", layer))
buff.SetAudioLevelParams(audio.AudioLevelParams{ buff.SetAudioLevelParams(audio.AudioLevelParams{
ActiveLevel: w.audioConfig.ActiveLevel, Config: w.audioConfig.AudioLevelConfig,
MinPercentile: w.audioConfig.MinPercentile,
ObserveDuration: w.audioConfig.UpdateInterval,
SmoothIntervals: w.audioConfig.SmoothIntervals,
}) })
buff.SetAudioLossProxying(w.audioConfig.EnableLossProxying) buff.SetAudioLossProxying(w.audioConfig.EnableLossProxying)
buff.OnRtcpFeedback(w.sendRTCP) buff.OnRtcpFeedback(w.sendRTCP)