//Thread从MessageQueue派生,有消息队列
class LOCKABLE Thread : public MessageQueue {}
rtc::Thread* network_thread_;
//Convenience method to invoke a functor on another thread
1 xxx_n:network线程执行的
std::unique_ptr<SessionStats> WebRtcSession::GetStats(
const ChannelNamePairs& channel_name_pairs) {
if (network_thread()->IsCurrent()) {
return GetStats_n(channel_name_pairs);
}
return network_thread()->Invoke<std::unique_ptr<SessionStats>>(
RTC_FROM_HERE,
rtc::Bind(&WebRtcSession::GetStats_n, this, channel_name_pairs));
}
//把消息放到队列:MessageQueue::Post(
2 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_GETSTATS,
new GetStatsMsg(observer, track));
//ThreadManager统一管理
signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
二 三大线程在那创建
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
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 */);
//信令线程为空,调用的线程就是信令线程
// If |network_thread| or |worker_thread| are null, the PeerConnectionFactory
// will create the necessary thread internally. If |signaling_thread| is null,
// the PeerConnectionFactory will use the thread on which this method is called
// as the signaling thread, wrapping it in an rtc::Thread object if needed.
RTC_EXPORT rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreateModularPeerConnectionFactory(
PeerConnectionFactoryDependencies dependencies);
}
src\pc\peer_connection_factory.cc
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreateModularPeerConnectionFactory(
{
// The PeerConnectionFactory must be created on the signaling thread.
auto pc_factory = PeerConnectionFactory::Create(std::move(dependencies));
//PeerConnectionFactory::Create 实现
PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
pc_factory);
}
//用宏扩展实现Proxy
static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
return new rtc::RefCountedObject<c##ProxyWithInternal>(primary_thread, c); \
}
rtc::scoped_refptr<PeerConnectionFactory> PeerConnectionFactory::Create(
PeerConnectionFactoryDependencies dependencies) {
auto context = ConnectionContext::Create(&dependencies);
if (!context) {
return nullptr;
}
return new rtc::RefCountedObject<PeerConnectionFactory>(context,
&dependencies);
}