* 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>
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package sfu
|
|
|
|
import (
|
|
"math"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/pion/rtcp"
|
|
"github.com/pion/webrtc/v3"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
)
|
|
|
|
const (
|
|
QuarterResolution = "q"
|
|
HalfResolution = "h"
|
|
FullResolution = "f"
|
|
)
|
|
|
|
// Do a fuzzy find for a codec in the list of codecs
|
|
// Used for lookup up a codec in an existing list to find a match
|
|
func codecParametersFuzzySearch(needle webrtc.RTPCodecParameters, haystack []webrtc.RTPCodecParameters) (webrtc.RTPCodecParameters, error) {
|
|
// First attempt to match on MimeType + SDPFmtpLine
|
|
for _, c := range haystack {
|
|
if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) &&
|
|
c.RTPCodecCapability.SDPFmtpLine == needle.RTPCodecCapability.SDPFmtpLine {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
// Fallback to just MimeType
|
|
for _, c := range haystack {
|
|
if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
return webrtc.RTPCodecParameters{}, webrtc.ErrCodecNotFound
|
|
}
|
|
|
|
// -----------------------------------------------
|
|
|
|
func getRttMs(report *rtcp.ReceptionReport) uint32 {
|
|
if report.LastSenderReport == 0 {
|
|
return 0
|
|
}
|
|
|
|
// RTT calculation reference: https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1
|
|
|
|
// middle 32-bits of current NTP time
|
|
now := uint32(buffer.ToNtpTime(time.Now()) >> 16)
|
|
if now < (report.LastSenderReport + report.Delay) {
|
|
return 0
|
|
}
|
|
ntpDiff := now - report.LastSenderReport - report.Delay
|
|
return uint32(math.Ceil(float64(ntpDiff) * 1000.0 / 65536.0))
|
|
}
|
|
|
|
func getCodecNameFromMime(mime string) string {
|
|
codecName := ""
|
|
codecParsed := strings.Split(strings.ToLower(mime), "/")
|
|
if len(codecParsed) > 1 {
|
|
codecName = codecParsed[1]
|
|
}
|
|
return codecName
|
|
}
|