From 56226a29345c4095cf0986d5d704fab1162ebac5 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 3 Aug 2021 03:28:36 +0200 Subject: [PATCH] Export the max requested rate in track statistics. --- rtpconn/rtpconn.go | 85 +++++++++++++++++++++++---------------------- rtpconn/rtpstats.go | 7 ++-- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/rtpconn/rtpconn.go b/rtpconn/rtpconn.go index bcac921..138e619 100644 --- a/rtpconn/rtpconn.go +++ b/rtpconn/rtpconn.go @@ -853,6 +853,49 @@ func rtcpUpListener(track *rtpUpTrack) { } } +func maxUpBitrate(t *rtpUpTrack) uint64 { + minrate := ^uint64(0) + maxrate := uint64(group.MinBitrate) + maxsid := 0 + maxtid := 0 + local := t.getLocal() + for _, down := range local { + r, sid, tid := down.GetMaxBitrate() + if maxsid < sid { + maxsid = sid + } + if maxtid < tid { + maxtid = tid + } + if r < group.MinBitrate { + r = group.MinBitrate + } + if minrate > r { + minrate = r + } + if maxrate < r { + maxrate = r + } + } + // assume that lower spatial layers take up 1/5 of + // the throughput + if maxsid > 0 { + maxrate = maxrate * 5 / 4 + } + // assume that each layer takes two times less + // throughput than the higher one. Then we've + // got enough slack for a factor of 2^(layers-1). + for i := 0; i < maxtid; i++ { + if minrate < ^uint64(0)/2 { + minrate *= 2 + } + } + if minrate < maxrate { + return minrate + } + return maxrate +} + func sendUpRTCP(up *rtpUpConnection) error { tracks := up.getTracks() @@ -923,47 +966,7 @@ func sendUpRTCP(up *rtpUpConnection) error { } else if t.Label() == "l" { rate += group.LowBitrate } else { - minrate := ^uint64(0) - maxrate := uint64(group.MinBitrate) - maxsid := 0 - maxtid := 0 - local := t.getLocal() - for _, down := range local { - r, sid, tid := down.GetMaxBitrate() - if maxsid < sid { - maxsid = sid - } - if maxtid < tid { - maxtid = tid - } - if r < group.MinBitrate { - r = group.MinBitrate - } - if minrate > r { - minrate = r - } - if maxrate < r { - maxrate = r - } - } - // assume that lower spatial layers take up 1/5 of - // the throughput - if maxsid > 0 { - maxrate = maxrate * 5 / 4 - } - // assume that each layer takes two times less - // throughput than the higher one. Then we've - // got enough slack for a factor of 2^(layers-1). - for i := 0; i < maxtid; i++ { - if minrate < ^uint64(0)/2 { - minrate *= 2 - } - } - if minrate < maxrate { - rate += minrate - } else { - rate += maxrate - } + rate += maxUpBitrate(t) } } diff --git a/rtpconn/rtpstats.go b/rtpconn/rtpstats.go index 9f816bf..d10f57f 100644 --- a/rtpconn/rtpstats.go +++ b/rtpconn/rtpstats.go @@ -32,9 +32,10 @@ func (c *webClient) GetStats() *stats.Client { (time.Second / time.Duration(t.jitter.HZ())) rate, _ := t.rate.Estimate() conns.Tracks = append(conns.Tracks, stats.Track{ - Bitrate: uint64(rate) * 8, - Loss: loss, - Jitter: stats.Duration(jitter), + Bitrate: uint64(rate) * 8, + MaxBitrate: maxUpBitrate(t), + Loss: loss, + Jitter: stats.Duration(jitter), }) } cs.Up = append(cs.Up, conns)