zoukankan      html  css  js  c++  java
  • 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。整个通话期间持续探测。可以做到主备倒换的目的

    p2pasep2ptransportchannel.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

  • 相关阅读:
    Python学习之路
    like's photos
    Django---子框架drf内容总结
    Django---子框架drf项目---路飞学城---前后端搭建
    Django---drf,JWT补充、基于就角色的权限控制(django内置auth体系)
    常见三种加密(MD5、非对称加密,对称加密)
    Django---drf,自定制频率、自动生成文档、JWT
    PEP8 常用规范
    Class meta
    Django---drf, books系列表接口、分页器、根据ip进行频率限制---作业
  • 原文地址:https://www.cnblogs.com/132818Creator/p/14898810.html
Copyright © 2011-2022 走看看