Telemetry connection scores (#377)
* octets - total bytes needs to be uint64 uint32 wraps at 4GB Signed-off-by: shishir gowda <shishir@livekit.io> * Cleanup stats handler to use connectionQuality stats remove per packet rtcp handlers, buffer stats * cleanup connection stats * Update mediatrack to store rtcp stats in connection stats * Update downstream handling of connection stats and telemetry * Update telemetry tests Signed-off-by: shishir gowda <shishir@livekit.io> * Misc fixes Signed-off-by: shishir gowda <shishir@livekit.io> * Minor fix to avoid accessing buffer before its allocated Signed-off-by: shishir gowda <shishir@livekit.io> * start updateStats worker in AddReciever() Signed-off-by: shishir gowda <shishir@livekit.io> * Use previous score to calculate avg scores * Restructure connectionStats Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
@@ -1,25 +1,28 @@
|
||||
package connectionquality
|
||||
|
||||
import (
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
import "sync"
|
||||
|
||||
type ConnectionStat struct {
|
||||
PacketsLost uint32
|
||||
Delay uint32
|
||||
Jitter uint32
|
||||
TotalPackets uint32
|
||||
LastSeqNum uint32
|
||||
TotalBytes uint64
|
||||
}
|
||||
|
||||
type ConnectionStats struct {
|
||||
Curr *ConnectionStat
|
||||
Prev *ConnectionStat
|
||||
Score float64
|
||||
Lock sync.Mutex
|
||||
ConnectionStat
|
||||
Prev *ConnectionStat
|
||||
Delay uint32
|
||||
Jitter uint32
|
||||
NackCount int32
|
||||
PliCount int32
|
||||
FirCount int32
|
||||
Score float64
|
||||
}
|
||||
|
||||
func NewConnectionStats() *ConnectionStats {
|
||||
return &ConnectionStats{Curr: &ConnectionStat{}, Prev: &ConnectionStat{}, Score: 4.0}
|
||||
return &ConnectionStats{Prev: &ConnectionStat{}, Score: 4.0}
|
||||
}
|
||||
|
||||
func getTotalPackets(curSN, prevSN uint32) uint32 {
|
||||
@@ -33,18 +36,22 @@ func getTotalPackets(curSN, prevSN uint32) uint32 {
|
||||
return increment
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) CalculateAudioScore() float64 {
|
||||
func (cs *ConnectionStats) UpdateStats(totalBytes uint64) ConnectionStat {
|
||||
// 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)
|
||||
cs.TotalPackets += getTotalPackets(cs.LastSeqNum, previous.LastSeqNum)
|
||||
cs.TotalBytes = totalBytes
|
||||
|
||||
var delta ConnectionStat
|
||||
|
||||
delta.TotalPackets = cs.TotalPackets - previous.TotalPackets
|
||||
delta.PacketsLost = cs.PacketsLost - previous.PacketsLost
|
||||
delta.TotalBytes = cs.TotalBytes - previous.TotalBytes
|
||||
|
||||
// store previous stats
|
||||
cs.Prev = current
|
||||
cs.Curr = &ConnectionStat{TotalPackets: cs.Prev.TotalPackets, PacketsLost: cs.Prev.PacketsLost}
|
||||
cs.Prev = &ConnectionStat{TotalPackets: cs.TotalPackets, PacketsLost: cs.PacketsLost, TotalBytes: cs.TotalBytes, LastSeqNum: cs.LastSeqNum}
|
||||
|
||||
return cs.Score
|
||||
return delta
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user