sfu: fix data stats active window bitrate and duration units (#4922)
This commit is contained in:
@@ -68,13 +68,14 @@ func (s *DataStats) ToProtoActive() *livekit.RTPStats {
|
|||||||
if duration > s.params.WindowDuration.Nanoseconds() {
|
if duration > s.params.WindowDuration.Nanoseconds() {
|
||||||
return &livekit.RTPStats{}
|
return &livekit.RTPStats{}
|
||||||
}
|
}
|
||||||
|
seconds := float64(duration) / 1e9
|
||||||
|
|
||||||
return &livekit.RTPStats{
|
return &livekit.RTPStats{
|
||||||
StartTime: timestamppb.New(time.Unix(s.windowStart/1e9, s.windowStart%1e9)),
|
StartTime: timestamppb.New(time.Unix(s.windowStart/1e9, s.windowStart%1e9)),
|
||||||
EndTime: timestamppb.New(time.Unix(0, now)),
|
EndTime: timestamppb.New(time.Unix(0, now)),
|
||||||
Duration: float64(duration / 1e9),
|
Duration: seconds,
|
||||||
Bytes: uint64(s.windowBytes),
|
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.EqualValues(t, 100, r.Bytes)
|
||||||
require.NotZero(t, r.Bitrate)
|
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