Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
nexedi
galene
Commits
e8fbfcb9
Commit
e8fbfcb9
authored
Jan 25, 2022
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid overflow in bitrate computation.
parent
0d8fdc5c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
8 deletions
+36
-8
group/group.go
group/group.go
+1
-0
rtpconn/rtpconn.go
rtpconn/rtpconn.go
+18
-8
rtpconn/rtpconn_test.go
rtpconn/rtpconn_test.go
+17
-0
No files found.
group/group.go
View file @
e8fbfcb9
...
...
@@ -64,6 +64,7 @@ type ChatHistoryEntry struct {
const
(
LowBitrate
=
100
*
1024
MinBitrate
=
LowBitrate
*
2
MaxBitrate
=
1024
*
1024
*
1024
)
type
Group
struct
{
...
...
rtpconn/rtpconn.go
View file @
e8fbfcb9
...
...
@@ -881,6 +881,15 @@ func rtcpUpListener(track *rtpUpTrack) {
}
}
// saturating addition
func
sadd
(
x
,
y
uint64
)
uint64
{
s
,
c
:=
bits
.
Add64
(
x
,
y
,
0
)
if
c
!=
0
{
return
^
uint64
(
0
)
}
return
s
}
func
maxUpBitrate
(
t
*
rtpUpTrack
)
uint64
{
minrate
:=
^
uint64
(
0
)
maxrate
:=
uint64
(
group
.
MinBitrate
)
...
...
@@ -908,15 +917,13 @@ func maxUpBitrate(t *rtpUpTrack) uint64 {
// assume that lower spatial layers take up 1/5 of
// the throughput
if
maxsid
>
0
{
maxrate
=
maxrate
*
5
/
4
maxrate
=
sadd
(
maxrate
,
maxrate
/
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
}
minrate
=
sadd
(
minrate
,
minrate
)
}
if
minrate
<
maxrate
{
return
minrate
...
...
@@ -990,15 +997,18 @@ func sendUpRTCP(up *rtpUpConnection) error {
}
ssrcs
=
append
(
ssrcs
,
uint32
(
t
.
track
.
SSRC
()))
if
t
.
Kind
()
==
webrtc
.
RTPCodecTypeAudio
{
rate
+=
100
*
1024
rate
=
sadd
(
rate
,
100
*
1024
)
}
else
if
t
.
Label
()
==
"l"
{
rate
+=
group
.
LowBitrate
rate
=
sadd
(
rate
,
group
.
LowBitrate
)
}
else
{
rate
+=
maxUpBitrate
(
t
)
rate
=
sadd
(
rate
,
maxUpBitrate
(
t
)
)
}
}
if
rate
<
^
uint64
(
0
)
&&
len
(
ssrcs
)
>
0
{
if
rate
>
group
.
MaxBitrate
{
rate
=
group
.
MaxBitrate
}
if
len
(
ssrcs
)
>
0
{
packets
=
append
(
packets
,
&
rtcp
.
ReceiverEstimatedMaximumBitrate
{
Bitrate
:
float32
(
rate
),
...
...
rtpconn/rtpconn_test.go
View file @
e8fbfcb9
...
...
@@ -37,3 +37,20 @@ func TestDownTrackAtomics(t *testing.T) {
t
.
Errorf
(
"Expected %v, got %v"
,
info
,
info2
)
}
}
func
TestSadd
(
t
*
testing
.
T
)
{
ts
:=
[]
struct
{
x
,
y
,
z
uint64
}{
{
0
,
0
,
0
},
{
1
,
2
,
3
},
{
^
uint64
(
0
)
-
10
,
5
,
^
uint64
(
0
)
-
5
},
{
^
uint64
(
0
)
-
10
,
15
,
^
uint64
(
0
)},
}
for
_
,
tt
:=
range
ts
{
z
:=
sadd
(
tt
.
x
,
tt
.
y
)
if
z
!=
tt
.
z
{
t
.
Errorf
(
"%v + %v: expected %v, got %v"
,
tt
.
x
,
tt
.
y
,
tt
.
z
,
z
,
)
}
}
}
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