2020-09-18 10:28:05 +02:00
|
|
|
package rtpconn
|
2020-09-18 10:14:57 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"time"
|
|
|
|
|
2020-12-19 17:37:48 +01:00
|
|
|
"github.com/jech/galene/rtptime"
|
|
|
|
"github.com/jech/galene/stats"
|
2020-09-18 10:14:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *webClient) GetStats() *stats.Client {
|
|
|
|
c.mu.Lock()
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
|
|
|
|
cs := stats.Client{
|
|
|
|
Id: c.id,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, up := range c.up {
|
|
|
|
conns := stats.Conn{
|
|
|
|
Id: up.id,
|
|
|
|
}
|
|
|
|
tracks := up.getTracks()
|
|
|
|
for _, t := range tracks {
|
2021-04-30 16:26:17 +02:00
|
|
|
s := t.cache.GetStats(false)
|
2021-05-07 02:23:10 +02:00
|
|
|
var loss float64
|
|
|
|
if s.Expected > 0 {
|
|
|
|
loss = float64(s.Expected-s.Received) /
|
|
|
|
float64(s.Expected)
|
|
|
|
}
|
2020-09-18 10:14:57 +02:00
|
|
|
jitter := time.Duration(t.jitter.Jitter()) *
|
|
|
|
(time.Second / time.Duration(t.jitter.HZ()))
|
|
|
|
rate, _ := t.rate.Estimate()
|
|
|
|
conns.Tracks = append(conns.Tracks, stats.Track{
|
2021-08-03 03:28:36 +02:00
|
|
|
Bitrate: uint64(rate) * 8,
|
|
|
|
MaxBitrate: maxUpBitrate(t),
|
|
|
|
Loss: loss,
|
|
|
|
Jitter: stats.Duration(jitter),
|
2020-09-18 10:14:57 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
cs.Up = append(cs.Up, conns)
|
|
|
|
}
|
|
|
|
sort.Slice(cs.Up, func(i, j int) bool {
|
|
|
|
return cs.Up[i].Id < cs.Up[j].Id
|
|
|
|
})
|
|
|
|
|
|
|
|
jiffies := rtptime.Jiffies()
|
|
|
|
for _, down := range c.down {
|
|
|
|
conns := stats.Conn{
|
2021-05-11 15:28:30 +02:00
|
|
|
Id: down.id,
|
2020-09-18 10:14:57 +02:00
|
|
|
}
|
|
|
|
for _, t := range down.tracks {
|
2021-05-17 16:23:07 +02:00
|
|
|
layer := t.getLayerInfo()
|
|
|
|
sid := layer.sid
|
|
|
|
maxSid := layer.maxSid
|
|
|
|
tid := layer.tid
|
|
|
|
maxTid := layer.maxTid
|
2020-09-18 10:14:57 +02:00
|
|
|
rate, _ := t.rate.Estimate()
|
2022-02-01 15:20:43 +01:00
|
|
|
maxRate, _, _ := t.GetMaxBitrate()
|
2022-04-15 03:35:34 +02:00
|
|
|
rtt := rtptime.ToDuration(int64(t.getRTT()),
|
2020-09-18 10:14:57 +02:00
|
|
|
rtptime.JiffiesPerSec)
|
|
|
|
loss, jitter := t.stats.Get(jiffies)
|
|
|
|
j := time.Duration(jitter) * time.Second /
|
|
|
|
time.Duration(t.track.Codec().ClockRate)
|
|
|
|
conns.Tracks = append(conns.Tracks, stats.Track{
|
2021-05-17 16:23:07 +02:00
|
|
|
Tid: &tid,
|
|
|
|
MaxTid: &maxTid,
|
|
|
|
Sid: &sid,
|
|
|
|
MaxSid: &maxSid,
|
2020-09-18 10:14:57 +02:00
|
|
|
Bitrate: uint64(rate) * 8,
|
2022-02-01 15:20:43 +01:00
|
|
|
MaxBitrate: maxRate,
|
2021-04-30 19:50:42 +02:00
|
|
|
Loss: float64(loss) / 256.0,
|
|
|
|
Rtt: stats.Duration(rtt),
|
|
|
|
Jitter: stats.Duration(j),
|
2020-09-18 10:14:57 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
cs.Down = append(cs.Down, conns)
|
|
|
|
}
|
|
|
|
sort.Slice(cs.Down, func(i, j int) bool {
|
|
|
|
return cs.Down[i].Id < cs.Down[j].Id
|
|
|
|
})
|
|
|
|
|
|
|
|
return &cs
|
|
|
|
}
|