| Index: webrtc/api/java/jni/peerconnection_jni.cc
|
| diff --git a/webrtc/api/java/jni/peerconnection_jni.cc b/webrtc/api/java/jni/peerconnection_jni.cc
|
| index c5154c95d2954b11f7040d1440bc622cb96f2864..e0043f41d3a9cca9aa914f87b5dabf6704e08649 100644
|
| --- a/webrtc/api/java/jni/peerconnection_jni.cc
|
| +++ b/webrtc/api/java/jni/peerconnection_jni.cc
|
| @@ -1035,14 +1035,16 @@ JOW(void, PeerConnectionFactory_shutdownInternalTracer)(JNIEnv* jni, jclass) {
|
| // single thing for Java to hold and eventually free.
|
| class OwnedFactoryAndThreads {
|
| public:
|
| - OwnedFactoryAndThreads(Thread* worker_thread,
|
| - Thread* signaling_thread,
|
| + OwnedFactoryAndThreads(std::unique_ptr<Thread> network_thread,
|
| + std::unique_ptr<Thread> worker_thread,
|
| + std::unique_ptr<Thread> signaling_thread,
|
| WebRtcVideoEncoderFactory* encoder_factory,
|
| WebRtcVideoDecoderFactory* decoder_factory,
|
| rtc::NetworkMonitorFactory* network_monitor_factory,
|
| PeerConnectionFactoryInterface* factory)
|
| - : worker_thread_(worker_thread),
|
| - signaling_thread_(signaling_thread),
|
| + : network_thread_(std::move(network_thread)),
|
| + worker_thread_(std::move(worker_thread)),
|
| + signaling_thread_(std::move(signaling_thread)),
|
| encoder_factory_(encoder_factory),
|
| decoder_factory_(decoder_factory),
|
| network_monitor_factory_(network_monitor_factory),
|
| @@ -1067,6 +1069,7 @@ class OwnedFactoryAndThreads {
|
| private:
|
| void JavaCallbackOnFactoryThreads();
|
|
|
| + const std::unique_ptr<Thread> network_thread_;
|
| const std::unique_ptr<Thread> worker_thread_;
|
| const std::unique_ptr<Thread> signaling_thread_;
|
| WebRtcVideoEncoderFactory* encoder_factory_;
|
| @@ -1080,6 +1083,10 @@ void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() {
|
| ScopedLocalRefFrame local_ref_frame(jni);
|
| jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory");
|
| jmethodID m = nullptr;
|
| + if (Thread::Current() == network_thread_.get()) {
|
| + LOG(LS_INFO) << "Network thread JavaCallback";
|
| + m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V");
|
| + }
|
| if (Thread::Current() == worker_thread_.get()) {
|
| LOG(LS_INFO) << "Worker thread JavaCallback";
|
| m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V");
|
| @@ -1097,8 +1104,12 @@ void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() {
|
|
|
| void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() {
|
| LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads.";
|
| - worker_thread_->Invoke<void>(
|
| + network_thread_->Invoke<void>(
|
| Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
|
| + if (worker_thread_) {
|
| + worker_thread_->Invoke<void>(
|
| + Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
|
| + }
|
| signaling_thread_->Invoke<void>(
|
| Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
|
| }
|
| @@ -1138,14 +1149,27 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
| // created. Since the semantics around when auto-wrapping happens in
|
| // webrtc/base/ are convoluted, we simply wrap here to avoid having to think
|
| // about ramifications of auto-wrapping there.
|
| + // TODO(danilchap): Make choice or move flag below to easier settable.
|
| + const bool worker_is_network = false;
|
| rtc::ThreadManager::Instance()->WrapCurrentThread();
|
| webrtc::Trace::CreateTrace();
|
| - Thread* worker_thread = new Thread();
|
| - worker_thread->SetName("worker_thread", NULL);
|
| - Thread* signaling_thread = new Thread();
|
| + std::unique_ptr<Thread> network_thread =
|
| + rtc::Thread::CreateWithSocketServer();
|
| + network_thread->SetName("network_thread", NULL);
|
| + RTC_CHECK(network_thread->Start()) << "Failed to start thread";
|
| + Thread* worker_thread = nullptr;
|
| + std::unique_ptr<Thread> worker_thread_own;
|
| + if (worker_is_network) {
|
| + worker_thread = network_thread.get();
|
| + } else {
|
| + worker_thread_own = rtc::Thread::Create();
|
| + worker_thread = worker_thread_own.get();
|
| + worker_thread->SetName("worker_thread", NULL);
|
| + RTC_CHECK(worker_thread->Start()) << "Failed to start thread";
|
| + }
|
| + std::unique_ptr<Thread> signaling_thread = rtc::Thread::Create();
|
| signaling_thread->SetName("signaling_thread", NULL);
|
| - RTC_CHECK(worker_thread->Start() && signaling_thread->Start())
|
| - << "Failed to start threads";
|
| + RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
|
| WebRtcVideoEncoderFactory* encoder_factory = nullptr;
|
| WebRtcVideoDecoderFactory* decoder_factory = nullptr;
|
| rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
|
| @@ -1168,11 +1192,9 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
| }
|
|
|
| rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
|
| - webrtc::CreatePeerConnectionFactory(worker_thread,
|
| - signaling_thread,
|
| - NULL,
|
| - encoder_factory,
|
| - decoder_factory));
|
| + webrtc::CreatePeerConnectionFactory(network_thread.get(), worker_thread,
|
| + signaling_thread.get(), NULL,
|
| + encoder_factory, decoder_factory));
|
| RTC_CHECK(factory) << "Failed to create the peer connection factory; "
|
| << "WebRTC/libjingle init likely failed on this device";
|
| // TODO(honghaiz): Maybe put the options as the argument of
|
| @@ -1181,8 +1203,8 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
| factory->SetOptions(options);
|
| }
|
| OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
|
| - worker_thread, signaling_thread,
|
| - encoder_factory, decoder_factory,
|
| + std::move(network_thread), std::move(worker_thread_own),
|
| + std::move(signaling_thread), encoder_factory, decoder_factory,
|
| network_monitor_factory, factory.release());
|
| owned_factory->InvokeJavaCallbacksOnFactoryThreads();
|
| return jlongFromPointer(owned_factory);
|
|
|