From a8415fe9ea381946148498f1fe7fd0b2b04f02ec Mon Sep 17 00:00:00 2001 From: Taylor Brandstetter Date: Wed, 23 Mar 2016 10:38:07 -0700 Subject: [PATCH] Adding comments about threading around CreatePeerConnectionFactory. This has confused a lot of developers (understandably). R=pthatcher@webrtc.org Review URL: https://codereview.webrtc.org/1828463002 . Cr-Commit-Position: refs/heads/master@{#12105} --- webrtc/api/peerconnectionfactory.cc | 17 ++++++----------- webrtc/api/peerconnectioninterface.h | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc index 22e450ca4e..852b7a8cce 100644 --- a/webrtc/api/peerconnectionfactory.cc +++ b/webrtc/api/peerconnectionfactory.cc @@ -64,16 +64,11 @@ CreatePeerConnectionFactory() { rtc::scoped_refptr pc_factory( new rtc::RefCountedObject()); - - // Call Initialize synchronously but make sure its executed on - // |signaling_thread|. - MethodCall0 call( - pc_factory.get(), - &PeerConnectionFactory::Initialize); - bool result = call.Marshal(pc_factory->signaling_thread()); - - if (!result) { - return NULL; + RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread()); + // The signaling thread is the current thread so we can + // safely call Initialize directly. + if (!pc_factory->Initialize()) { + return nullptr; } return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(), pc_factory); @@ -101,7 +96,7 @@ CreatePeerConnectionFactory( bool result = call.Marshal(signaling_thread); if (!result) { - return NULL; + return nullptr; } return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory); } diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index 22109c4088..08a131920e 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -634,12 +634,25 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { }; // Create a new instance of PeerConnectionFactoryInterface. +// +// This method relies on the thread it's called on as the "signaling thread" +// for the PeerConnectionFactory it creates. +// +// As such, if the current thread is not already running an rtc::Thread message +// loop, an application using this method must eventually either call +// rtc::Thread::Current()->Run(), or call +// rtc::Thread::Current()->ProcessMessages() within the application's own +// message loop. rtc::scoped_refptr CreatePeerConnectionFactory(); // Create a new instance of PeerConnectionFactoryInterface. -// Ownership of |factory|, |default_adm|, and optionally |encoder_factory| and -// |decoder_factory| transferred to the returned factory. +// +// |worker_thread| and |signaling_thread| are the only mandatory +// parameters. +// +// If non-null, ownership of |default_adm|, |encoder_factory| and +// |decoder_factory| are transferred to the returned factory. rtc::scoped_refptr CreatePeerConnectionFactory( rtc::Thread* worker_thread,