//src/api/peer_connection_factory_proxy.h
BEGIN_PRIMARY_PROXY_MAP(PeerConnectionFactory) //primary
PROXY_PRIMARY_THREAD_DESTRUCTOR()
PROXY_METHOD4(rtc::scoped_refptr<PeerConnectionInterface>,
CreatePeerConnection,
const PeerConnectionInterface::RTCConfiguration&,
std::unique_ptr<cricket::PortAllocator>,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface>,
PeerConnectionObserver*)
...
END_PROXY_MAP()
//实现在proxy.h
#define BEGIN_PRIMARY_PROXY_MAP(c) \
PROXY_MAP_BOILERPLATE(c) \
PRIMARY_PROXY_MAP_BOILERPLATE(c) \
REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \
public: \
static rtc::scoped_refptr<c##ProxyWithInternal> Create( \
rtc::Thread* primary_thread, INTERNAL_CLASS* c) { \
return new rtc::RefCountedObject<c##ProxyWithInternal>(primary_thread, c); \
}
class MethodCall : public QueuedTask {
R Marshal(const rtc::Location& posted_from, rtc::Thread* t) {
if (t->IsCurrent()) {
Invoke(std::index_sequence_for<Args...>());
} else {
t->PostTask(std::unique_ptr<QueuedTask>(this));
event_.Wait(rtc::Event::kForever);
}
return r_.moved_result();
}
}
//Synchronous同步, Asynchronous异步,
//没判断是否在信令线程 ?
peer_connection_->SetRemoteDescription(...)
//检查是否在信令线程
rtc::scoped_refptr<PeerConnectionInterface>
PeerConnectionFactory::CreatePeerConnection(...) {
RTC_DCHECK(signaling_thread_->IsCurrent());
}
peer_connection_factory_->CreateVideoTrack(
kVideoLabel,
peer_connection_factory_->CreateVideoSource(OpenVideoCaptureDevice(),
NULL)));
peer_connection_factory_->CreateLocalMediaStream(kStreamLabel);
信令线程用在:发送信令。
工作线程:VideoReceiveStream、BaseChannel等有判断。
网络线程:WebRtcSession等有判断。
博客内容涉及WebRTC中PeerConnectionFactory的实现,包括创建PeerConnection的方法,并强调了线程安全的重要性。创建PeerConnection时需在信令线程上进行,而其他如VideoReceiveStream和BaseChannel的工作则在不同的线程上处理。代码示例展示了如何确保任务在正确线程上执行以及如何调用SetRemoteDescription等方法。

被折叠的 条评论
为什么被折叠?



