webrtc ice代碼流程走讀

1、獲取turn、stun服務器信息處理流程
Conductor::InitializePeerConnection

->Conductor::CreatePeerConnection
->PeerConnectionFactory::CreatePeerConnection
->PeerConnection::Initialize
->PeerConnection::InitializePortAllocator_n//這個函數解析配置信息,確定探測類型及參數。

->PortAllocator::SetConfiguration//這裏配置服務器信息。

 

2、生效turn、stun服務器處理流程
WebRtcSessionDescriptionFactory::OnMessage

->Conductor::OnSuccess
->PeerConnection::SetLocalDescription   (session_->MaybeStartGathering())
->WebRtcSession::MaybeStartGathering
->TransportController::MaybeStartGathering
->TransportController::MaybeStartGathering_n
->P2PTransportChannel::MaybeStartGathering
AddAllocatorSession(allocator_->CreateSession());//註冊信號量
allocator_sessions_.back()->StartGettingPorts(); //啓動Port資源申請消息

當P2PTransportChannel::MaybeStartGathering函數調用BasicPortAllocatorSession::StartGettingPorts後,就會啓動MSG_CONFIG_START消息處理流程。開始收集本端的candidates信息。

 

3、發送candidates信息給對端:
每次調用EnableProtocol函數,就是將本地的Candidates信息,發送給對端的Client
AllocationSequence::EnableProtocol
->BasicPortAllocatorSession::OnProtocolEnabled
->SignalCandidatesReady
->P2PTransportChannel::OnCandidatesReady
->SignalCandidateGathered
->TransportController::OnChannelCandidateGathered_n
->SignalCandidatesGathered
->WebRtcSession::OnTransportControllerCandidatesGathered
->Conductor::OnIceCandidate
->Conductor::SendMessage
->PeerConnectionClient::SendToPeer
Port資源申請結束後,通過信號量傳遞該信息:
SignalPortAllocationComplete信號量觸發調用
BasicPortAllocatorSession::OnPortAllocationComplete

4、接收端

Conductor::OnMessageFromPeer

->PeerConnection::SetRemoteDescription
->WebRtcSession::SetRemoteDescription
->WebRtcSession::UpdateSessionState
->WebRtcSession::PushdownTransportDescription
->WebRtcSession::PushdownRemoteTransportDescription
->TransportController::SetRemoteTransportDescription
->TransportController::SetRemoteTransportDescription_n
->JsepTransport::SetRemoteTransportDescription
->JsepTransport::ApplyRemoteTransportDescription
->P2PTransportChannel::SetRemoteIceParameters

->P2PTransportChannel::RequestSortAndStateUpdate

->P2PTransportChannel::SortConnectionsAndUpdateState

5、心跳檢測

webrtc進行ICE探測時,會在不穩定鏈接時,持續發送ping心跳報文,當檢測鏈接已經穩定後,就不再發心跳報文,也不會探測切換傳輸路徑。

鏈接是否穩定是在weak函數裏面判斷的。要是服務器資源寬裕的話,可以把weak修改問false。整個通話期間持續探測。可以做到主備倒換的目的

p2p\base\p2ptransportchannel.h

 

 

 

6、額外說明

  webrtc會每隔兩秒,檢查一下網絡狀態是否有變化,若是有變化,就重新探測網絡,選擇其他的傳輸方式。所以會概率出現一會P2P一會中轉的現象。

  

Network::Network
BasicNetworkManager::CreateNetworks
BasicNetworkManager::UpdateNetworksOnce
BasicNetworkManager::UpdateNetworksContinually
BasicNetworkManager::OnMessage
MessageQueue::Dispatch
Thread::ProcessMessages
Thread::Run
Thread::PreRun

 

 

 

————————————————
some from:https://blog.csdn.net/CrystalShaw/article/details/80804225

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章