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"`
AllowPause bool `yaml:"allow_pause,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 {
@@ -305,7 +305,10 @@ var DefaultConfig = Config{
StrictACKs: true,
PLIThrottle: sfu.DefaultPLIThrottleConfig,
CongestionControl: CongestionControlConfig{
Enabled: true,
AllowPause: false,
StreamAllocator: streamallocator.DefaultStreamAllocatorConfig,
UseSendSideBWE: false,
},
},
Audio: sfu.DefaultAudioConfig,
+4 -2
View File
@@ -804,8 +804,10 @@ func newRoomWithParticipants(t *testing.T, opts testRoomOpts) *Room {
DepartureTimeout: 1,
},
&sfu.AudioConfig{
UpdateInterval: audioUpdateInterval,
SmoothIntervals: opts.audioSmoothIntervals,
AudioLevelConfig: audio.AudioLevelConfig{
UpdateInterval: audioUpdateInterval,
SmoothIntervals: opts.audioSmoothIntervals,
},
},
&livekit.ServerInfo{
Edition: livekit.ServerInfo_Standard,
+35 -12
View File
@@ -24,11 +24,34 @@ const (
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 {
ActiveLevel uint8
MinPercentile uint8
ObserveDuration uint32
SmoothIntervals uint32
Config AudioLevelConfig
}
// keeps track of audio level for a participant
@@ -51,15 +74,15 @@ type AudioLevel struct {
func NewAudioLevel(params AudioLevelParams) *AudioLevel {
l := &AudioLevel{
params: params,
minActiveDuration: uint32(params.MinPercentile) * params.ObserveDuration / 100,
minActiveDuration: uint32(params.Config.MinPercentile) * params.Config.UpdateInterval / 100,
smoothFactor: 1,
activeThreshold: ConvertAudioLevel(float64(params.ActiveLevel)),
activeThreshold: ConvertAudioLevel(float64(params.Config.ActiveLevel)),
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)
l.smoothFactor = float64(2) / (float64(l.params.SmoothIntervals + 1))
l.smoothFactor = float64(2) / (float64(l.params.Config.SmoothIntervals + 1))
}
return l
@@ -74,14 +97,14 @@ func (l *AudioLevel) Observe(level uint8, durationMs uint32, arrivalTime int64)
l.observedDuration += durationMs
if level <= l.params.ActiveLevel {
if level <= l.params.Config.ActiveLevel {
l.activeDuration += durationMs
if l.loudestObservedLevel > level {
l.loudestObservedLevel = level
}
}
if l.observedDuration >= l.params.ObserveDuration {
if l.observedDuration >= l.params.Config.UpdateInterval {
smoothedLevel := float64(0.0)
// compute and reset
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
// > 0 if active for longer 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
linearLevel := ConvertAudioLevel(adjustedLevel)
@@ -111,7 +134,7 @@ func (l *AudioLevel) GetLevel(now int64) (float64, bool) {
}
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
}
+5 -3
View File
@@ -108,9 +108,11 @@ func TestAudioLevel(t *testing.T) {
func createAudioLevel(activeLevel uint8, minPercentile uint8, observeDuration uint32) *AudioLevel {
return NewAudioLevel(AudioLevelParams{
ActiveLevel: activeLevel,
MinPercentile: minPercentile,
ObserveDuration: observeDuration,
Config: AudioLevelConfig{
ActiveLevel: activeLevel,
MinPercentile: minPercentile,
UpdateInterval: observeDuration,
},
})
}
+4 -18
View File
@@ -63,16 +63,8 @@ var (
// --------------------------------------
type AudioConfig 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"`
audio.AudioLevelConfig `yaml:",inline"`
// enable red encoding downtrack for opus only audio up track
ActiveREDEncoding bool `yaml:"active_red_encoding,omitempty"`
// enable proxying weakest subscriber loss to publisher in RTCP Receiver Report
@@ -81,10 +73,7 @@ type AudioConfig struct {
var (
DefaultAudioConfig = AudioConfig{
ActiveLevel: 35, // -35dBov
MinPercentile: 40,
UpdateInterval: 400,
SmoothIntervals: 2,
AudioLevelConfig: audio.DefaultAudioLevelConfig,
}
)
@@ -379,10 +368,7 @@ func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buff
}
buff.SetLogger(w.logger.WithValues("layer", layer))
buff.SetAudioLevelParams(audio.AudioLevelParams{
ActiveLevel: w.audioConfig.ActiveLevel,
MinPercentile: w.audioConfig.MinPercentile,
ObserveDuration: w.audioConfig.UpdateInterval,
SmoothIntervals: w.audioConfig.SmoothIntervals,
Config: w.audioConfig.AudioLevelConfig,
})
buff.SetAudioLossProxying(w.audioConfig.EnableLossProxying)
buff.OnRtcpFeedback(w.sendRTCP)