webrtc 代码学习(四)创建PC

本文简要介绍WebRTC中创建PeerConnection的过程,包括PeerConnectionFactory的CreatePeerConnection方法,PeerConnectionProxy的原理,以及PeerConnection的Initialize操作。通过分析源代码,帮助理解这一复杂流程。
摘要由CSDN通过智能技术生成

创建PC
作者:LanPZzzz
本章我们简单讲述下PC 创建,PC 是我最头疼的一个类(┳_┳)…,太庞大了,可以说是整个webrtc中最复杂的,我感觉没有之一了,.h就1000行,.cc 就更不敢想象,你就不能分一下啊,能死啊… 我们还是要分析下PC 的内容,工程巨大啊

1. PC 创建
bool Conductor::CreatePeerConnection(bool dtls) {
  RTC_DCHECK(peer_connection_factory_);
  RTC_DCHECK(!peer_connection_);

  webrtc::PeerConnectionInterface::RTCConfiguration config;
  1. 使用kUnifiedPlan,因为kUnifiedPlan 是为了的趋势,PlanB和PlanA 必将被淘汰的
  config.sdp_semantics = webrtc::SdpSemantics::kUnifiedPlan;
  2. dtls = false
  config.enable_dtls_srtp = dtls;
  webrtc::PeerConnectionInterface::IceServer server;
  3. server.uri = "stun:43.240.127.199:5000",这个应该是google 的stun 服务器,当然也可以自己搭建
  server.uri = GetPeerConnectionString();
  config.servers.push_back(server);

  4. 创建PC
  peer_connection_ = peer_connection_factory_->CreatePeerConnection(
      config, nullptr, nullptr, this);
  return peer_connection_ != nullptr;
}
2. PeerConnectionFactory::CreatePeerConnection(pc\peerconnectionfactory.cc 363行)
rtc::scoped_refptr<PeerConnectionInterface>
PeerConnectionFactory::CreatePeerConnection(
    const PeerConnectionInterface::RTCConfiguration& configuration,
    PeerConnectionDependencies dependencies) {
  RTC_DCHECK(signaling_thread_->IsCurrent());

  1. 我们在创出PC 时cert_generator = nullptr 和 allocator = nullptr,都是要重新创建的
  // Set internal defaults if optional dependencies are not set.
  if (!dependencies.cert_generator) {
    dependencies.cert_generator =
        absl::make_unique<rtc::RTCCertificateGenerator>(signaling_thread_,
                                                        network_thread_);
  }

  if (!dependencies.allocator) {
    dependencies.allocator.reset(new cricket::BasicPortAllocator(
        default_network_manager_.get(), default_socket_factory_.get(),
        configuration.turn_customizer));
  }

  network_thread_->Invoke<void>(
      RTC_FROM_HERE,
      rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
                dependencies.allocator.get(), options_.network_ignore_mask));

  2. event_log 创建
  std::unique_ptr<RtcEventLog> event_log =
      worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>(
          RTC_FROM_HERE,
          rtc::Bind(&PeerConnectionFactory::CreateRtcEventLog_w, this));

  3. Call 创建,Call 感觉应该是个很重要的对象,**具体干什么,要在后续学习了
  std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>(
      RTC_FROM_HERE,
      rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get()));

  4. new PC
  rtc::scoped_refptr<PeerConnection> pc(
      new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
                                                std::move(call)));
  5. PC Initialize
  ActionsBeforeInitializeF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值