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}
diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc
index 22e450c..852b7a8 100644
--- a/webrtc/api/peerconnectionfactory.cc
+++ b/webrtc/api/peerconnectionfactory.cc
@@ -64,16 +64,11 @@
rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
new rtc::RefCountedObject<PeerConnectionFactory>());
-
- // Call Initialize synchronously but make sure its executed on
- // |signaling_thread|.
- MethodCall0<PeerConnectionFactory, bool> 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 @@
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 22109c4..08a1319 100644
--- a/webrtc/api/peerconnectioninterface.h
+++ b/webrtc/api/peerconnectioninterface.h
@@ -634,12 +634,25 @@
};
// 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<PeerConnectionFactoryInterface>
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<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory(
rtc::Thread* worker_thread,