Connection quality v1 (#260)
* audio connection quality mos for publisher stats Signed-off-by: shishir gowda <shishir@livekit.io> * Update tests Signed-off-by: shishir gowda <shishir@livekit.io> * Change ratings range, increase default rtt to 80 Signed-off-by: shishir gowda <shishir@livekit.io> * Use stats worker to get total packets to find %lost in window Signed-off-by: shishir gowda <shishir@livekit.io> * Update go dep Signed-off-by: shishir gowda <shishir@livekit.io> * Increase interval of score cal to 5 seconds Signed-off-by: shishir gowda <shishir@livekit.io> * use lastSequenceNumber in reports to find total packets Signed-off-by: shishir gowda <shishir@livekit.io> * Account for delay while calculating scores Signed-off-by: shishir gowda <shishir@livekit.io> * Fix minor typo Signed-off-by: shishir gowda <shishir@livekit.io> * Add connection stats/score to subscribed audio tracks Signed-off-by: shishir gowda <shishir@livekit.io> * Cleanup Signed-off-by: shishir gowda <shishir@livekit.io> * Ignore duplicate LastSequenceNumbers in rtcp reports Ignore if sequence number is less than what was recieved Signed-off-by: shishir gowda <shishir@livekit.io> * Move video track score calc to media/downtracks Signed-off-by: shishir gowda <shishir@livekit.io> * Deprecate SubscribeLossPercentage() as score calc is now handled downstream Signed-off-by: shishir gowda <shishir@livekit.io> * Initialize connection score to excellent score is calc at 5sec interval. Client fetches score before first score is computed * Update test cases for connection quality Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package connectionquality
|
||||
|
||||
import (
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
type ConnectionStat struct {
|
||||
PacketsLost uint32
|
||||
Delay uint32
|
||||
Jitter uint32
|
||||
TotalPackets uint32
|
||||
LastSeqNum uint32
|
||||
}
|
||||
|
||||
type ConnectionStats struct {
|
||||
Curr *ConnectionStat
|
||||
Prev *ConnectionStat
|
||||
Score float64
|
||||
}
|
||||
|
||||
func NewConnectionStats() *ConnectionStats {
|
||||
return &ConnectionStats{Curr: &ConnectionStat{}, Prev: &ConnectionStat{}, Score: 4.0}
|
||||
}
|
||||
|
||||
func getTotalPackets(curSN, prevSN uint32) uint32 {
|
||||
delta := curSN - prevSN
|
||||
// lower 16 bits is the counter
|
||||
counter := uint16(delta)
|
||||
// upper 16 bits contains the cycles/wrap
|
||||
cycles := uint16(delta >> 16)
|
||||
increment := (uint32(cycles) * (1 << 16)) + uint32(counter)
|
||||
|
||||
return increment
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) CalculateAudioScore() float64 {
|
||||
// update feedback stats
|
||||
current := cs.Curr
|
||||
previous := cs.Prev
|
||||
|
||||
// Update TotalPackets from SeqNum here
|
||||
current.TotalPackets += getTotalPackets(current.LastSeqNum, previous.LastSeqNum)
|
||||
cs.Score = ConnectionScore(current, previous, livekit.TrackType_AUDIO)
|
||||
|
||||
// store previous stats
|
||||
cs.Prev = current
|
||||
cs.Curr = &ConnectionStat{TotalPackets: cs.Prev.TotalPackets, PacketsLost: cs.Prev.PacketsLost}
|
||||
|
||||
return cs.Score
|
||||
}
|
||||
Reference in New Issue
Block a user