Connection quality clean up (#766)
* WIP commit * WIP commit * Remove debug * Revert to reduce diff * Fix tests * Determine spatial layer from track info quality if non-simulcast * Adjust for invalid layer on no rid, previously that function was returning 0 for no rid case * Fall back to top level width/height if there are no layers * Use duration from RTPDeltaInfo
This commit is contained in:
@@ -3,7 +3,6 @@ package connectionquality
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/rtcscore-go/pkg/rtcmos"
|
||||
)
|
||||
@@ -19,30 +18,55 @@ func Score2Rating(score float32) livekit.ConnectionQuality {
|
||||
return livekit.ConnectionQuality_POOR
|
||||
}
|
||||
|
||||
func getBitRate(interval float64, totalBytes int64) int32 {
|
||||
return int32(float64(totalBytes*8) / interval)
|
||||
func getBitRate(interval float64, bytes uint64) int32 {
|
||||
return int32(float64(bytes*8) / interval)
|
||||
}
|
||||
|
||||
func getFrameRate(interval float64, totalFrames int64) int32 {
|
||||
return int32(float64(totalFrames) / interval)
|
||||
func getFrameRate(interval float64, frames uint32) int32 {
|
||||
return int32(float64(frames) / interval)
|
||||
}
|
||||
|
||||
func getLossPercentage(expected uint32, lost uint32) float32 {
|
||||
if expected == 0 {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
return float32(lost) * 100.0 / float32(expected)
|
||||
}
|
||||
|
||||
func int32Ptr(x int32) *int32 {
|
||||
return &x
|
||||
}
|
||||
|
||||
func AudioConnectionScore(interval time.Duration, totalBytes int64,
|
||||
qualityParam *buffer.ConnectionQualityParams, dtxDisabled bool) float32 {
|
||||
type TrackScoreParams struct {
|
||||
Duration time.Duration
|
||||
Codec string
|
||||
PacketsExpected uint32
|
||||
PacketsLost uint32
|
||||
Bytes uint64
|
||||
Frames uint32
|
||||
Jitter float64
|
||||
Rtt uint32
|
||||
DtxDisabled bool
|
||||
ActualWidth uint32
|
||||
ActualHeight uint32
|
||||
ExpectedWidth uint32
|
||||
ExpectedHeight uint32
|
||||
}
|
||||
|
||||
stat := rtcmos.Stat{
|
||||
Bitrate: getBitRate(interval.Seconds(), totalBytes),
|
||||
PacketLoss: qualityParam.LossPercentage,
|
||||
RoundTripTime: int32Ptr(int32(qualityParam.Rtt)),
|
||||
BufferDelay: int32Ptr(int32(qualityParam.Jitter)),
|
||||
AudioConfig: &rtcmos.AudioConfig{},
|
||||
func getRtcMosStat(params TrackScoreParams) rtcmos.Stat {
|
||||
return rtcmos.Stat{
|
||||
Bitrate: getBitRate(params.Duration.Seconds(), params.Bytes),
|
||||
PacketLoss: getLossPercentage(params.PacketsExpected, params.PacketsLost),
|
||||
RoundTripTime: int32Ptr(int32(params.Rtt)),
|
||||
BufferDelay: int32Ptr(int32(params.Jitter / 1000.0)),
|
||||
}
|
||||
}
|
||||
|
||||
if dtxDisabled {
|
||||
func AudioTrackScore(params TrackScoreParams) float32 {
|
||||
stat := getRtcMosStat(params)
|
||||
stat.AudioConfig = &rtcmos.AudioConfig{}
|
||||
if params.DtxDisabled {
|
||||
flag := false
|
||||
stat.AudioConfig.Dtx = &flag
|
||||
}
|
||||
@@ -54,22 +78,17 @@ func AudioConnectionScore(interval time.Duration, totalBytes int64,
|
||||
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,
|
||||
},
|
||||
func VideoTrackScore(params TrackScoreParams) float32 {
|
||||
stat := getRtcMosStat(params)
|
||||
stat.VideoConfig = &rtcmos.VideoConfig{
|
||||
FrameRate: int32Ptr(getFrameRate(params.Duration.Seconds(), params.Frames)),
|
||||
Codec: params.Codec,
|
||||
ExpectedWidth: int32Ptr(int32(params.ExpectedWidth)),
|
||||
ExpectedHeight: int32Ptr(int32(params.ExpectedHeight)),
|
||||
Width: int32Ptr(int32(params.ActualWidth)),
|
||||
Height: int32Ptr(int32(params.ActualHeight)),
|
||||
}
|
||||
|
||||
scores := rtcmos.Score([]rtcmos.Stat{stat})
|
||||
if len(scores) == 1 {
|
||||
return float32(scores[0].VideoScore)
|
||||
|
||||
Reference in New Issue
Block a user