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
87f70c43
Commit
87f70c43
authored
Apr 28, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mute clients when bitrate is too low.
parent
1de42bd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
client.go
client.go
+23
-15
group.go
group.go
+18
-0
No files found.
client.go
View file @
87f70c43
...
...
@@ -305,6 +305,9 @@ func addUpConn(c *client, id string) (*upConnection, error) {
local
:=
track
.
getLocal
()
for
_
,
l
:=
range
local
{
if
l
.
muted
()
{
continue
}
err
:=
l
.
track
.
WriteRTP
(
&
packet
)
if
err
!=
nil
{
log
.
Printf
(
"%v"
,
err
)
...
...
@@ -463,8 +466,11 @@ func addDownTrack(c *client, id string, remoteTrack *upTrack, remoteConn *upConn
return
nil
,
nil
,
err
}
track
:=
&
downTrack
{
local
,
remoteTrack
,
new
(
timeStampedBitrate
)}
track
:=
&
downTrack
{
track
:
local
,
remote
:
remoteTrack
,
maxBitrate
:
new
(
timeStampedBitrate
),
}
conn
.
tracks
=
append
(
conn
.
tracks
,
track
)
remoteTrack
.
addLocal
(
track
)
...
...
@@ -479,8 +485,7 @@ func msSinceEpoch() uint64 {
return
uint64
(
time
.
Since
(
epoch
)
/
time
.
Millisecond
)
}
func
rtcpListener
(
g
*
group
,
c
*
downConnection
,
s
*
webrtc
.
RTPSender
,
bitrate
*
timeStampedBitrate
)
{
func
rtcpListener
(
g
*
group
,
c
*
downConnection
,
s
*
webrtc
.
RTPSender
,
bitrate
*
timeStampedBitrate
)
{
for
{
ps
,
err
:=
s
.
ReadRTCP
()
if
err
!=
nil
{
...
...
@@ -539,20 +544,25 @@ func trackKinds(down *downConnection) (audio bool, video bool) {
}
func
updateUpBitrate
(
up
*
upConnection
)
{
for
_
,
t
:=
range
up
.
tracks
{
t
.
maxBitrate
=
^
uint64
(
0
)
}
now
:=
msSinceEpoch
()
for
_
,
track
:=
range
up
.
tracks
{
track
.
maxBitrate
=
^
uint64
(
0
)
local
:=
track
.
getLocal
()
for
_
,
l
:=
range
local
{
ms
:=
atomic
.
LoadUint64
(
&
l
.
maxBitrate
.
timestamp
)
bitrate
:=
atomic
.
LoadUint64
(
&
l
.
maxBitrate
.
bitrate
)
if
now
-
ms
>
5000
||
bitrate
==
0
{
if
now
<
ms
||
now
>
ms
+
5000
||
bitrate
==
0
{
l
.
setMuted
(
false
)
continue
}
if
bitrate
<
9600
||
(
l
.
track
.
Kind
()
==
webrtc
.
RTPCodecTypeVideo
&&
bitrate
<
128000
)
{
l
.
setMuted
(
true
)
continue
}
l
.
setMuted
(
false
)
if
track
.
maxBitrate
>
bitrate
{
track
.
maxBitrate
=
bitrate
}
...
...
@@ -917,13 +927,11 @@ func sendRateUpdate(c *client) {
updateUpBitrate
(
u
)
for
_
,
t
:=
range
u
.
tracks
{
bitrate
:=
t
.
maxBitrate
if
bitrate
!=
^
uint64
(
0
)
{
if
bitrate
<
6000
{
bitrate
=
6000
}
rembs
=
append
(
rembs
,
remb
{
u
.
pc
,
t
.
track
.
SSRC
(),
bitrate
})
if
bitrate
==
^
uint64
(
0
)
{
continue
}
rembs
=
append
(
rembs
,
remb
{
u
.
pc
,
t
.
track
.
SSRC
(),
bitrate
})
}
}
c
.
mu
.
Unlock
()
...
...
group.go
View file @
87f70c43
...
...
@@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/pion/webrtc/v2"
...
...
@@ -63,12 +64,29 @@ type timeStampedBitrate struct {
bitrate
uint64
timestamp
uint64
}
type
downTrack
struct
{
track
*
webrtc
.
Track
remote
*
upTrack
isMuted
uint32
maxBitrate
*
timeStampedBitrate
}
func
(
t
*
downTrack
)
muted
()
bool
{
return
atomic
.
LoadUint32
(
&
t
.
isMuted
)
!=
0
}
func
(
t
*
downTrack
)
setMuted
(
muted
bool
)
{
if
t
.
muted
()
==
muted
{
return
}
m
:=
uint32
(
0
)
if
muted
{
m
=
1
}
atomic
.
StoreUint32
(
&
t
.
isMuted
,
m
)
}
type
downConnection
struct
{
id
string
pc
*
webrtc
.
PeerConnection
...
...
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