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
4699c338
Commit
4699c338
authored
May 22, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache early ICE candidates.
parent
57163c70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
9 deletions
+65
-9
client.go
client.go
+17
-7
conn.go
conn.go
+48
-2
No files found.
client.go
View file @
4699c338
...
...
@@ -654,7 +654,7 @@ func getDownConn(c *client, id string) *downConnection {
return
conn
}
func
getConn
(
c
*
client
,
id
string
)
c
onnection
{
func
getConn
(
c
*
client
,
id
string
)
iceC
onnection
{
up
:=
getUpConn
(
c
,
id
)
if
up
!=
nil
{
return
up
...
...
@@ -1053,6 +1053,11 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
up
.
labels
=
labels
err
=
up
.
flushICECandidates
()
if
err
!=
nil
{
log
.
Printf
(
"ICE: %v"
,
err
)
}
return
c
.
write
(
clientMessage
{
Type
:
"answer"
,
Id
:
id
,
...
...
@@ -1061,17 +1066,22 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
}
func
gotAnswer
(
c
*
client
,
id
string
,
answer
webrtc
.
SessionDescription
)
error
{
con
n
:=
getDownConn
(
c
,
id
)
if
con
n
==
nil
{
dow
n
:=
getDownConn
(
c
,
id
)
if
dow
n
==
nil
{
return
protocolError
(
"unknown id in answer"
)
}
err
:=
con
n
.
pc
.
SetRemoteDescription
(
answer
)
err
:=
dow
n
.
pc
.
SetRemoteDescription
(
answer
)
if
err
!=
nil
{
return
err
}
for
_
,
t
:=
range
conn
.
tracks
{
activateDownTrack
(
conn
,
t
)
err
=
down
.
flushICECandidates
()
if
err
!=
nil
{
log
.
Printf
(
"ICE: %v"
,
err
)
}
for
_
,
t
:=
range
down
.
tracks
{
activateDownTrack
(
down
,
t
)
}
return
nil
}
...
...
@@ -1081,7 +1091,7 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
if
conn
==
nil
{
return
errors
.
New
(
"unknown id in ICE"
)
}
return
conn
.
getPC
()
.
AddICECandidate
(
*
candidate
)
return
conn
.
addICECandidate
(
candidate
)
}
func
(
c
*
client
)
setRequested
(
requested
map
[
string
]
uint32
)
error
{
...
...
conn.go
View file @
4699c338
...
...
@@ -6,6 +6,7 @@
package
main
import
(
"errors"
"sync"
"sync/atomic"
...
...
@@ -16,8 +17,9 @@ import (
"github.com/pion/webrtc/v2"
)
type
connection
interface
{
getPC
()
*
webrtc
.
PeerConnection
type
iceConnection
interface
{
addICECandidate
(
candidate
*
webrtc
.
ICECandidateInit
)
error
flushICECandidates
()
error
}
type
upTrack
struct
{
...
...
@@ -30,6 +32,7 @@ type upTrack struct {
lastPLI
uint64
lastSenderReport
uint32
lastSenderReportTime
uint32
iceCandidates
[]
*
webrtc
.
ICECandidateInit
localCh
chan
struct
{}
// signals that local has changed
writerDone
chan
struct
{}
// closed when the loop dies
...
...
@@ -103,6 +106,35 @@ func (up *upConnection) getPC() *webrtc.PeerConnection {
return
up
.
pc
}
func
(
up
*
upConnection
)
addICECandidate
(
candidate
*
webrtc
.
ICECandidateInit
)
error
{
if
up
.
pc
.
RemoteDescription
()
!=
nil
{
return
up
.
pc
.
AddICECandidate
(
*
candidate
)
}
up
.
iceCandidates
=
append
(
up
.
iceCandidates
,
candidate
)
return
nil
}
func
flushICECandidates
(
pc
*
webrtc
.
PeerConnection
,
candidates
[]
*
webrtc
.
ICECandidateInit
)
error
{
if
pc
.
RemoteDescription
()
==
nil
{
return
errors
.
New
(
"flushICECandidates called in bad state"
)
}
var
err
error
for
_
,
candidate
:=
range
candidates
{
err2
:=
pc
.
AddICECandidate
(
*
candidate
)
if
err
==
nil
{
err
=
err2
}
}
return
err
}
func
(
up
*
upConnection
)
flushICECandidates
()
error
{
err
:=
flushICECandidates
(
up
.
pc
,
up
.
iceCandidates
)
up
.
iceCandidates
=
nil
return
err
}
func
getUpMid
(
pc
*
webrtc
.
PeerConnection
,
track
*
webrtc
.
Track
)
string
{
for
_
,
t
:=
range
pc
.
GetTransceivers
()
{
if
t
.
Receiver
()
!=
nil
&&
t
.
Receiver
()
.
Track
()
==
track
{
...
...
@@ -201,3 +233,17 @@ type downConnection struct {
func
(
down
*
downConnection
)
getPC
()
*
webrtc
.
PeerConnection
{
return
down
.
pc
}
func
(
down
*
downConnection
)
addICECandidate
(
candidate
*
webrtc
.
ICECandidateInit
)
error
{
if
down
.
pc
.
RemoteDescription
()
!=
nil
{
return
down
.
pc
.
AddICECandidate
(
*
candidate
)
}
down
.
iceCandidates
=
append
(
down
.
iceCandidates
,
candidate
)
return
nil
}
func
(
down
*
downConnection
)
flushICECandidates
()
error
{
err
:=
flushICECandidates
(
down
.
pc
,
down
.
iceCandidates
)
down
.
iceCandidates
=
nil
return
err
}
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