创建PC factory
作者:LanPZzzz
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
rtc::scoped_refptr default_adm,
rtc::scoped_refptr audio_encoder_factory,
rtc::scoped_refptr audio_decoder_factory,
std::unique_ptr video_encoder_factory,
std::unique_ptr video_decoder_factory,
rtc::scoped_refptr audio_mixer,
rtc::scoped_refptr audio_processing
nullptr /* network_thread */, nullptr /* worker_thread */,
nullptr /* signaling_thread */, nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */
这里的每一个后续都要进行学习的,大家不要惊慌
1. 创建audio 的后处理
if (!audio_processing)
audio_processing = AudioProcessingBuilder().Create();
2. 创建media engine
std::unique_ptr media_engine =
cricket::WebRtcMediaEngineFactory::Create(
default_adm, audio_encoder_factory, audio_decoder_factory,
std::move(video_encoder_factory), std::move(video_decoder_factory),
audio_mixer, audio_processing);
3. 创建call factory
std::unique_ptr call_factory = CreateCallFactory();
std::unique_ptr event_log_factory =
CreateRtcEventLogFactory();
4. 创建PC factory
return CreateModularPeerConnectionFactory(
network_thread, worker_thread, signaling_thread, std::move(media_engine),
std::move(call_factory), std::move(event_log_factory));
1. new PeerConnectionFactory
rtc::scoped_refptr pc_factory(
new rtc::RefCountedObject(
std::move(dependencies)));
1.1. PeerConnectionFactory::PeerConnectionFactory(pc\peerconnectionfactory.cc 129行)
创建 network_thread_,worker_thread_, signaling_thread_
2. 直接使用同步线程调用, PeerConnectionFactory::Initialize,这个函数要在pc_factory->signaling_thread() 线程中调用,保证线程同步,在调试的时候很麻烦。
MethodCall0 call(
pc_factory.get(), &PeerConnectionFactory::Initialize);
bool result = call.Marshal(RTC_FROM_HERE, pc_factory->signaling_thread());
if (!result) {
return nullptr;
}
3. 直接在proxy 中创建PC factory
return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
pc_factory);
bool PeerConnectionFactory::Initialize() {
RTC_DCHECK(signaling_thread_->IsCurrent());
rtc::InitRandom(rtc::Time32());
default_network_manager_.reset(new rtc::BasicNetworkManager());
if (!default_network_manager_) {
return false;
}
default_socket_factory_.reset(
new rtc::BasicPacketSocketFactory(network_thread_));
if (!default_socket_factory_) {
return false;
}
1. **** 这里是个关键位置,channel_manager (负责创建各种channal),我们后续会学习到
channel_manager_ = absl::make_unique(
std::move(media_engine_), absl::make_unique(),
worker_thread_, network_thread_);
channel_manager_->SetVideoRtxEnabled(true);
if (!channel_manager_->Init()) {
return false;
}
return true;
}
rtc::scoped_refptr
到这里PC factory 已经创建完成,我们可以看到线程、media引擎、channel manager,RtpDataEngine,call_factory 的创建,这些具体有上面作用呢,continue…