* Use rtcscore-go to calculate audio/video score Signed-off-by: shishir gowda <shishir@livekit.io> * Get max expected layer and find max actual layer from stream Signed-off-by: shishir gowda <shishir@livekit.io> * Cleanup unused methods Signed-off-by: shishir gowda <shishir@livekit.io> * Cleanup code - address review comments Signed-off-by: shishir gowda <shishir@livekit.io> * get expected layer info instead of just quality Signed-off-by: shishir gowda <shishir@livekit.io> * Move SpatialLayerForQuality to utils/helpers method is required in rtc,sfu and connectionstats pkg Moved to utils/helpers.go to remove cyclic deps Signed-off-by: shishir gowda <shishir@livekit.io> * update tests Signed-off-by: shishir gowda <shishir@livekit.io> * Pick stream stats with max layer Signed-off-by: shishir gowda <shishir@livekit.io> * Update rtcscore-go pkg to make rtt/jitter optional when passing 0, rtcscore-go was setting default values Signed-off-by: shishir gowda <shishir@livekit.io> * update score to rating Signed-off-by: shishir gowda <shishir@livekit.io> * Update rtcscore-go pkg to use simulcast layer info for score Signed-off-by: shishir gowda <shishir@livekit.io> * Update score ratings to reflect rtcscore range Signed-off-by: shishir gowda <shishir@livekit.io> * update test params for new rtcscore Signed-off-by: shishir gowda <shishir@livekit.io> * Delay sending scores to connections only till full data is available first interval can have partial data leading to lower scores Signed-off-by: shishir gowda <shishir@livekit.io> * Check for inf values in quality params Signed-off-by: shishir gowda <shishir@livekit.io> * Clean up initial score calculation. Default to 5 Signed-off-by: shishir gowda <shishir@livekit.io> Co-authored-by: David Zhao <dz@livekit.io>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package connectionquality
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
"github.com/livekit/protocol/livekit"
|
|
"github.com/livekit/rtcscore-go/pkg/rtcmos"
|
|
)
|
|
|
|
func Score2Rating(score float32) livekit.ConnectionQuality {
|
|
if score > 4.0 {
|
|
return livekit.ConnectionQuality_EXCELLENT
|
|
}
|
|
|
|
if score > 3.0 {
|
|
return livekit.ConnectionQuality_GOOD
|
|
}
|
|
return livekit.ConnectionQuality_POOR
|
|
}
|
|
|
|
func getBitRate(interval float64, totalBytes int64) int32 {
|
|
return int32(float64(totalBytes*8) / interval)
|
|
}
|
|
|
|
func getFrameRate(interval float64, totalFrames int64) int32 {
|
|
return int32(float64(totalFrames) / interval)
|
|
}
|
|
|
|
func int32Ptr(x int32) *int32 {
|
|
return &x
|
|
}
|
|
|
|
func AudioConnectionScore(interval time.Duration, totalBytes int64,
|
|
qualityParam *buffer.ConnectionQualityParams, dtxDisabled bool) float32 {
|
|
|
|
stat := rtcmos.Stat{
|
|
Bitrate: getBitRate(interval.Seconds(), totalBytes),
|
|
PacketLoss: qualityParam.LossPercentage,
|
|
RoundTripTime: int32Ptr(int32(qualityParam.Rtt)),
|
|
BufferDelay: int32Ptr(int32(qualityParam.Jitter)),
|
|
AudioConfig: &rtcmos.AudioConfig{},
|
|
}
|
|
|
|
if dtxDisabled {
|
|
flag := false
|
|
stat.AudioConfig.Dtx = &flag
|
|
}
|
|
|
|
scores := rtcmos.Score([]rtcmos.Stat{stat})
|
|
if len(scores) == 1 {
|
|
return float32(scores[0].AudioScore)
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func VideoConnectionScore(interval time.Duration, totalBytes int64, totalFrames int64, qualityParam *buffer.ConnectionQualityParams,
|
|
codec string, expectedHeight int32, expectedWidth int32, actualHeight int32, actualWidth int32) float32 {
|
|
stat := rtcmos.Stat{
|
|
Bitrate: getBitRate(interval.Seconds(), totalBytes),
|
|
PacketLoss: qualityParam.LossPercentage,
|
|
RoundTripTime: int32Ptr(int32(qualityParam.Rtt)),
|
|
BufferDelay: int32Ptr(int32(qualityParam.Jitter)),
|
|
VideoConfig: &rtcmos.VideoConfig{
|
|
FrameRate: int32Ptr(getFrameRate(interval.Seconds(), totalFrames)),
|
|
Codec: codec,
|
|
ExpectedHeight: &expectedHeight,
|
|
ExpectedWidth: &expectedWidth,
|
|
Height: &actualHeight,
|
|
Width: &actualWidth,
|
|
},
|
|
}
|
|
scores := rtcmos.Score([]rtcmos.Stat{stat})
|
|
if len(scores) == 1 {
|
|
return float32(scores[0].VideoScore)
|
|
}
|
|
return 0
|
|
}
|