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
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
Show 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 {
...
@@ -654,7 +654,7 @@ func getDownConn(c *client, id string) *downConnection {
return
conn
return
conn
}
}
func
getConn
(
c
*
client
,
id
string
)
c
onnection
{
func
getConn
(
c
*
client
,
id
string
)
iceC
onnection
{
up
:=
getUpConn
(
c
,
id
)
up
:=
getUpConn
(
c
,
id
)
if
up
!=
nil
{
if
up
!=
nil
{
return
up
return
up
...
@@ -1053,6 +1053,11 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
...
@@ -1053,6 +1053,11 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
up
.
labels
=
labels
up
.
labels
=
labels
err
=
up
.
flushICECandidates
()
if
err
!=
nil
{
log
.
Printf
(
"ICE: %v"
,
err
)
}
return
c
.
write
(
clientMessage
{
return
c
.
write
(
clientMessage
{
Type
:
"answer"
,
Type
:
"answer"
,
Id
:
id
,
Id
:
id
,
...
@@ -1061,17 +1066,22 @@ func gotOffer(c *client, id string, offer webrtc.SessionDescription, labels map[
...
@@ -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
{
func
gotAnswer
(
c
*
client
,
id
string
,
answer
webrtc
.
SessionDescription
)
error
{
con
n
:=
getDownConn
(
c
,
id
)
dow
n
:=
getDownConn
(
c
,
id
)
if
con
n
==
nil
{
if
dow
n
==
nil
{
return
protocolError
(
"unknown id in answer"
)
return
protocolError
(
"unknown id in answer"
)
}
}
err
:=
con
n
.
pc
.
SetRemoteDescription
(
answer
)
err
:=
dow
n
.
pc
.
SetRemoteDescription
(
answer
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
t
:=
range
conn
.
tracks
{
err
=
down
.
flushICECandidates
()
activateDownTrack
(
conn
,
t
)
if
err
!=
nil
{
log
.
Printf
(
"ICE: %v"
,
err
)
}
for
_
,
t
:=
range
down
.
tracks
{
activateDownTrack
(
down
,
t
)
}
}
return
nil
return
nil
}
}
...
@@ -1081,7 +1091,7 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
...
@@ -1081,7 +1091,7 @@ func gotICE(c *client, candidate *webrtc.ICECandidateInit, id string) error {
if
conn
==
nil
{
if
conn
==
nil
{
return
errors
.
New
(
"unknown id in ICE"
)
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
{
func
(
c
*
client
)
setRequested
(
requested
map
[
string
]
uint32
)
error
{
...
...
conn.go
View file @
4699c338
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
package
main
package
main
import
(
import
(
"errors"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
...
@@ -16,8 +17,9 @@ import (
...
@@ -16,8 +17,9 @@ import (
"github.com/pion/webrtc/v2"
"github.com/pion/webrtc/v2"
)
)
type
connection
interface
{
type
iceConnection
interface
{
getPC
()
*
webrtc
.
PeerConnection
addICECandidate
(
candidate
*
webrtc
.
ICECandidateInit
)
error
flushICECandidates
()
error
}
}
type
upTrack
struct
{
type
upTrack
struct
{
...
@@ -30,6 +32,7 @@ type upTrack struct {
...
@@ -30,6 +32,7 @@ type upTrack struct {
lastPLI
uint64
lastPLI
uint64
lastSenderReport
uint32
lastSenderReport
uint32
lastSenderReportTime
uint32
lastSenderReportTime
uint32
iceCandidates
[]
*
webrtc
.
ICECandidateInit
localCh
chan
struct
{}
// signals that local has changed
localCh
chan
struct
{}
// signals that local has changed
writerDone
chan
struct
{}
// closed when the loop dies
writerDone
chan
struct
{}
// closed when the loop dies
...
@@ -103,6 +106,35 @@ func (up *upConnection) getPC() *webrtc.PeerConnection {
...
@@ -103,6 +106,35 @@ func (up *upConnection) getPC() *webrtc.PeerConnection {
return
up
.
pc
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
{
func
getUpMid
(
pc
*
webrtc
.
PeerConnection
,
track
*
webrtc
.
Track
)
string
{
for
_
,
t
:=
range
pc
.
GetTransceivers
()
{
for
_
,
t
:=
range
pc
.
GetTransceivers
()
{
if
t
.
Receiver
()
!=
nil
&&
t
.
Receiver
()
.
Track
()
==
track
{
if
t
.
Receiver
()
!=
nil
&&
t
.
Receiver
()
.
Track
()
==
track
{
...
@@ -201,3 +233,17 @@ type downConnection struct {
...
@@ -201,3 +233,17 @@ type downConnection struct {
func
(
down
*
downConnection
)
getPC
()
*
webrtc
.
PeerConnection
{
func
(
down
*
downConnection
)
getPC
()
*
webrtc
.
PeerConnection
{
return
down
.
pc
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