Open jinleileiking opened 1 year ago
接收ontrack
(pc PeerConnection) SetLocalDescription if weAnswer && remoteDesc != nil { pc.ops.Enqueue(func() { = func (pc PeerConnection) startRTP
(pc *PeerConnection) SetRemoteDescription if weOffer { pc.startRTP
startRTP (pc PeerConnection) startRTPReceivers (pc PeerConnection) startReceiver for _, t := range receiver.Tracks() go func(track TrackRemote) = (pc PeerConnection) onTrack
API: (a *Agent) GatherCandidates()
(a *Agent) gatherCandidates
(a *Agent) gatherCandidatesLocal
(a *Agent) addCandidate
c.start =(c *candidateBase) start
(c *candidateBase) recvLoop
(c *candidateBase) handleInboundPacket
(a *Agent) handleInbound
a.selector.HandleBindingRequest
if remoteCandidates, ok := a.remoteCandidates[c.NetworkType()]; ok
a.addPair(c, remoteCandidate)
(s *controlledSelector) HandleBindingRequest / (s *controllingSelector) HandleBindingRequest
if remoteCandidates, ok := a.remoteCandidates[c.NetworkType()]; ok {¬
(a *Agent) addPair
a.checklist = append(a.checklist, p)
API (a *Agent) AddRemoteCandidate(c Candidate)
(a *Agent) addRemoteCandidate(c Candidate)
API: (a *Agent) Dial
a.connect
(a *Agent) startConnectivityChecks
(a *Agent) connectivityChecks()
a.selector.ContactCandidates()
(s *controllingSelector) ContactCandidates() / (s *controlledSelector) ContactCandidates()
(a *Agent) pingAllCandidates()
_, p := range a.checklist
a.selector.PingCandidate(p.Local, p.Remote)
(s *controlledSelector) PingCandidate / (s *controllingSelector) PingCandidate
(a *Agent) sendBindingRequest
(a *Agent) sendSTUN
local.writeTo ( local : Candidate) =
c (c *candidateBase) writeTo
n, err := c.conn.WriteTo(raw, dst.addr()) PacketConn
SFU
data flow:
When call
curl
, the server will:webrtc.New
the logs:
go program callback trace:
NewAgent will
a.gatherCandidatesLocal
will listen udp ports. Each port will setup a goroutine to recv udp messages.setup a goroutine
a.taskLoop
. Then wait for pinging the all candidates.startConnectivityChecks will setup a timer. When fire (SetRemoteDescription), call the pingAllcandidates
peerConnection.SetRemoteDescription
sfu will use the SDP from browser offer call this func
peerConnection.SetRemoteDescription
will set the state tohave-remote-offer
and run a goroutineerr := pc.iceTransport.Start
<-receiver.Receive(RTCRtpReceiveParameters)
wait forpc.onTrack
call
onICEConnectionStateChange
when hookedNewRTCPeerConnection -> pc.createICETransport() -> t.OnConnectionStateChange will setup
t.onConnectionStateChangeHdlr
pingCandidate will send STUN binding request to candidates.
When click the
start session
buttonMy browser is in NAT. So you can see your ip is not your laptop ip in logs.
chrome will send bind request to sfu, sfu will recv udp
(c *Candidate) recvLoop()
-> is stun -> kfunc (a *Agent) handleInbound
-> setValidPair -> ice to connected ->Agent.taskLoop
-> checkKeepaliveon track
as above said:
logs
receive rtcp
Recevie will setup up two goroutine. One for RTP, One for Rtcp.