Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1080)

Unified Diff: webrtc/api/java/jni/peerconnection_jni.cc

Issue 1888903003: Network thread (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/api/fakemediacontroller.h ('k') | webrtc/api/mediacontroller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « webrtc/api/fakemediacontroller.h ('k') | webrtc/api/mediacontroller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698