mirror of
https://github.com/livekit/livekit.git
synced 2026-10-23 19:32:41 +00:00
sfu: fix data stats active window bitrate and duration units (#4922)
This commit is contained in:
1 parent
2d9bf12581
commit
ad54223d1b
2 files changed
+16
-2
No files matched your search
@@ -68,13 +68,14 @@ func (s *DataStats) ToProtoActive() *livekit.RTPStats {
|
||||
if duration > s.params.WindowDuration.Nanoseconds() {
|
||||
return &livekit.RTPStats{}
|
||||
}
|
||||
seconds := float64(duration) / 1e9
|
||||
|
||||
return &livekit.RTPStats{
|
||||
StartTime: timestamppb.New(time.Unix(s.windowStart/1e9, s.windowStart%1e9)),
|
||||
EndTime: timestamppb.New(time.Unix(0, now)),
|
||||
Duration: float64(duration / 1e9),
|
||||
Duration: seconds,
|
||||
Bytes: uint64(s.windowBytes),
|
||||
Bitrate: float64(s.windowBytes) * 8 / float64(duration) / 1e9,
|
||||
Bitrate: float64(s.windowBytes) * 8 / seconds,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,3 +51,16 @@ func TestDataStats(t *testing.T) {
|
||||
require.EqualValues(t, 100, r.Bytes)
|
||||
require.NotZero(t, r.Bitrate)
|
||||
}
|
||||
|
||||
func TestDataStatsActiveBitrateAndDuration(t *testing.T) {
|
||||
stats := NewDataStats(DataStatsParam{WindowDuration: 10 * time.Second})
|
||||
|
||||
// 1000 bytes over a 1.5 second window is 8000 bits / 1.5 s
|
||||
stats.windowStart = time.Now().Add(-1500 * time.Millisecond).UnixNano()
|
||||
stats.windowBytes = 1000
|
||||
|
||||
r := stats.ToProtoActive()
|
||||
require.EqualValues(t, 1000, r.Bytes)
|
||||
require.InDelta(t, 1.5, r.Duration, 0.1)
|
||||
require.InDelta(t, 8000/1.5, r.Bitrate, 0.1*8000/1.5)
|
||||
}
|
||||
Reference in new issue
Block a user