Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
4da03a3c
Commit
4da03a3c
authored
Jun 03, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make rate estimator estimate packet rates too.
parent
19a65318
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
16 deletions
+43
-16
estimator/estimator.go
estimator/estimator.go
+21
-11
estimator/estimator_test.go
estimator/estimator_test.go
+15
-1
group.go
group.go
+4
-2
webclient.go
webclient.go
+3
-2
No files found.
estimator/estimator.go
View file @
4da03a3c
...
...
@@ -8,12 +8,14 @@ import (
type
Estimator
struct
{
interval
time
.
Duration
count
uint32
bytes
uint32
packets
uint32
mu
sync
.
Mutex
totalBytes
uint32
totalPackets
uint32
rate
uint32
packetRate
uint32
time
time
.
Time
}
...
...
@@ -26,30 +28,38 @@ func New(interval time.Duration) *Estimator {
func
(
e
*
Estimator
)
swap
(
now
time
.
Time
)
{
interval
:=
now
.
Sub
(
e
.
time
)
count
:=
atomic
.
SwapUint32
(
&
e
.
count
,
0
)
bytes
:=
atomic
.
SwapUint32
(
&
e
.
bytes
,
0
)
packets
:=
atomic
.
SwapUint32
(
&
e
.
packets
,
0
)
atomic
.
AddUint32
(
&
e
.
totalBytes
,
bytes
)
atomic
.
AddUint32
(
&
e
.
totalPackets
,
packets
)
if
interval
<
time
.
Millisecond
{
e
.
rate
=
0
e
.
packetRate
=
0
}
else
{
e
.
rate
=
uint32
(
uint64
(
count
*
1000
)
/
uint64
(
interval
/
time
.
Millisecond
))
e
.
rate
=
uint32
(
uint64
(
bytes
*
1000
)
/
uint64
(
interval
/
time
.
Millisecond
))
e
.
packetRate
=
uint32
(
uint64
(
packets
*
1000
)
/
uint64
(
interval
/
time
.
Millisecond
))
}
e
.
time
=
now
}
func
(
e
*
Estimator
)
Accumulate
(
count
uint32
)
{
atomic
.
AddUint32
(
&
e
.
totalBytes
,
count
)
atomic
.
AddUint32
(
&
e
.
totalPackets
,
1
)
atomic
.
AddUint32
(
&
e
.
count
,
count
)
atomic
.
AddUint32
(
&
e
.
bytes
,
count
)
atomic
.
AddUint32
(
&
e
.
packets
,
1
)
}
func
(
e
*
Estimator
)
estimate
(
now
time
.
Time
)
uint32
{
func
(
e
*
Estimator
)
estimate
(
now
time
.
Time
)
(
uint32
,
uint32
)
{
if
now
.
Sub
(
e
.
time
)
>
e
.
interval
{
e
.
swap
(
now
)
}
return
e
.
rate
return
e
.
rate
,
e
.
packetRate
}
func
(
e
*
Estimator
)
Estimate
()
uint32
{
func
(
e
*
Estimator
)
Estimate
()
(
uint32
,
uint32
)
{
now
:=
time
.
Now
()
e
.
mu
.
Lock
()
...
...
@@ -58,7 +68,7 @@ func (e *Estimator) Estimate() uint32 {
}
func
(
e
*
Estimator
)
Totals
()
(
uint32
,
uint32
)
{
b
:=
atomic
.
LoadUint32
(
&
e
.
totalBytes
)
p
:=
atomic
.
LoadUint32
(
&
e
.
totalPackets
)
b
:=
atomic
.
LoadUint32
(
&
e
.
totalBytes
)
+
atomic
.
LoadUint32
(
&
e
.
bytes
)
p
:=
atomic
.
LoadUint32
(
&
e
.
totalPackets
)
+
atomic
.
LoadUint32
(
&
e
.
packets
)
return
p
,
b
}
estimator/estimator_test.go
View file @
4da03a3c
...
...
@@ -13,11 +13,14 @@ func TestEstimator(t *testing.T) {
e
.
Accumulate
(
42
)
e
.
Accumulate
(
128
)
e
.
estimate
(
now
.
Add
(
time
.
Second
))
rate
:=
e
.
estimate
(
now
.
Add
(
time
.
Second
+
time
.
Millisecond
))
rate
,
packetRate
:=
e
.
estimate
(
now
.
Add
(
time
.
Second
+
time
.
Millisecond
))
if
rate
!=
42
+
128
{
t
.
Errorf
(
"Expected %v, got %v"
,
42
+
128
,
rate
)
}
if
packetRate
!=
2
{
t
.
Errorf
(
"Expected 2, got %v"
,
packetRate
)
}
totalP
,
totalB
:=
e
.
Totals
()
if
totalP
!=
2
{
...
...
@@ -26,4 +29,15 @@ func TestEstimator(t *testing.T) {
if
totalB
!=
42
+
128
{
t
.
Errorf
(
"Expected %v, got %v"
,
42
+
128
,
totalB
)
}
e
.
Accumulate
(
12
)
totalP
,
totalB
=
e
.
Totals
()
if
totalP
!=
3
{
t
.
Errorf
(
"Expected 2, got %v"
,
totalP
)
}
if
totalB
!=
42
+
128
+
12
{
t
.
Errorf
(
"Expected %v, got %v"
,
42
+
128
,
totalB
)
}
}
group.go
View file @
4da03a3c
...
...
@@ -573,8 +573,9 @@ func getClientStats(c *webClient) clientStats {
loss
:=
uint8
(
lost
*
100
/
expected
)
jitter
:=
time
.
Duration
(
t
.
jitter
.
Jitter
())
*
(
time
.
Second
/
time
.
Duration
(
t
.
jitter
.
HZ
()))
rate
,
_
:=
t
.
rate
.
Estimate
()
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
bitrate
:
uint64
(
t
.
rate
.
Estimate
()
)
*
8
,
bitrate
:
uint64
(
rate
)
*
8
,
maxBitrate
:
atomic
.
LoadUint64
(
&
t
.
maxBitrate
),
loss
:
loss
,
jitter
:
jitter
,
...
...
@@ -590,13 +591,14 @@ func getClientStats(c *webClient) clientStats {
conns
:=
connStats
{
id
:
down
.
id
}
for
_
,
t
:=
range
down
.
tracks
{
jiffies
:=
rtptime
.
Jiffies
()
rate
,
_
:=
t
.
rate
.
Estimate
()
rtt
:=
rtptime
.
ToDuration
(
atomic
.
LoadUint64
(
&
t
.
rtt
),
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
,
trackStats
{
bitrate
:
uint64
(
t
.
rate
.
Estimate
()
)
*
8
,
bitrate
:
uint64
(
rate
)
*
8
,
maxBitrate
:
t
.
GetMaxBitrate
(
jiffies
),
loss
:
uint8
(
uint32
(
loss
)
*
100
/
256
),
rtt
:
rtt
,
...
...
webclient.go
View file @
4da03a3c
...
...
@@ -847,7 +847,8 @@ func (track *rtpDownTrack) updateRate(loss uint8, now uint64) {
if
loss
<
5
{
// if our actual rate is low, then we're not probing the
// bottleneck
actual
:=
8
*
uint64
(
track
.
rate
.
Estimate
())
r
,
_
:=
track
.
rate
.
Estimate
()
actual
:=
8
*
uint64
(
r
)
if
actual
>=
(
rate
*
7
)
/
8
{
// loss < 0.02, multiply by 1.05
rate
=
rate
*
269
/
256
...
...
@@ -937,7 +938,7 @@ func rtcpDownListener(conn *rtpDownConnection, track *rtpDownTrack, s *webrtc.RT
}
case
*
rtcp
.
TransportLayerNack
:
maxBitrate
:=
track
.
GetMaxBitrate
(
jiffies
)
bitrate
:=
track
.
rate
.
Estimate
()
bitrate
,
_
:=
track
.
rate
.
Estimate
()
if
uint64
(
bitrate
)
*
7
/
8
<
maxBitrate
{
sendRecovery
(
p
,
track
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment