创建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