Pass NetworkMonitorFactory through PeerConnectionFactory.
Previously the instance was set through a static method, which was really only done because it was difficult to add new PeerConnectionFactory construction arguments at the time. Now that we have PeerConnectionFactoryDependencies it's easy to clean this up. I'm doing this because I plan to add a NetworkMonitor implementation for iOS, and don't want to inherit this ugliness. Bug: webrtc:9883 Change-Id: Id94dc061ab1c7186b81af8547393a6e336ff04c2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180241 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Commit-Queue: Taylor <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31815}
This commit is contained in:
committed by
Commit Bot
parent
9a1acec95b
commit
003c9be817
@ -18,6 +18,7 @@
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "rtc_base/network_monitor.h"
|
||||
#include "rtc_base/network_monitor_factory.h"
|
||||
#include "rtc_base/thread_checker.h"
|
||||
#include "sdk/android/src/jni/jni_helpers.h"
|
||||
|
||||
|
||||
@ -19,19 +19,11 @@ OwnedFactoryAndThreads::OwnedFactoryAndThreads(
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory,
|
||||
const rtc::scoped_refptr<PeerConnectionFactoryInterface>& factory)
|
||||
: network_thread_(std::move(network_thread)),
|
||||
worker_thread_(std::move(worker_thread)),
|
||||
signaling_thread_(std::move(signaling_thread)),
|
||||
network_monitor_factory_(network_monitor_factory),
|
||||
factory_(factory) {}
|
||||
|
||||
OwnedFactoryAndThreads::~OwnedFactoryAndThreads() {
|
||||
if (network_monitor_factory_ != nullptr) {
|
||||
rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jni
|
||||
} // namespace webrtc
|
||||
|
||||
@ -33,25 +33,19 @@ class OwnedFactoryAndThreads {
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory,
|
||||
const rtc::scoped_refptr<PeerConnectionFactoryInterface>& factory);
|
||||
|
||||
~OwnedFactoryAndThreads();
|
||||
~OwnedFactoryAndThreads() = default;
|
||||
|
||||
PeerConnectionFactoryInterface* factory() { return factory_.get(); }
|
||||
rtc::Thread* network_thread() { return network_thread_.get(); }
|
||||
rtc::Thread* signaling_thread() { return signaling_thread_.get(); }
|
||||
rtc::Thread* worker_thread() { return worker_thread_.get(); }
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory() {
|
||||
return network_monitor_factory_;
|
||||
}
|
||||
void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; }
|
||||
|
||||
private:
|
||||
const std::unique_ptr<rtc::Thread> network_thread_;
|
||||
const std::unique_ptr<rtc::Thread> worker_thread_;
|
||||
const std::unique_ptr<rtc::Thread> signaling_thread_;
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory_;
|
||||
const rtc::scoped_refptr<PeerConnectionFactoryInterface> factory_;
|
||||
};
|
||||
|
||||
|
||||
@ -138,11 +138,10 @@ ScopedJavaLocalRef<jobject> NativeToScopedJavaPeerConnectionFactory(
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory) {
|
||||
std::unique_ptr<rtc::Thread> signaling_thread) {
|
||||
OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
|
||||
std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread), network_monitor_factory, pcf);
|
||||
std::move(signaling_thread), pcf);
|
||||
|
||||
ScopedJavaLocalRef<jobject> j_pcf = Java_PeerConnectionFactory_Constructor(
|
||||
env, NativeToJavaPointer(owned_factory));
|
||||
@ -172,17 +171,15 @@ PeerConnectionFactoryInterface* PeerConnectionFactoryFromJava(jlong j_p) {
|
||||
// Set in PeerConnectionFactory_initializeAndroidGlobals().
|
||||
static bool factory_static_initialized = false;
|
||||
|
||||
|
||||
jobject NativeToJavaPeerConnectionFactory(
|
||||
JNIEnv* jni,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory) {
|
||||
std::unique_ptr<rtc::Thread> signaling_thread) {
|
||||
return NativeToScopedJavaPeerConnectionFactory(
|
||||
jni, pcf, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread), network_monitor_factory)
|
||||
std::move(signaling_thread))
|
||||
.Release();
|
||||
}
|
||||
|
||||
@ -284,18 +281,9 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
||||
signaling_thread->SetName("signaling_thread", NULL);
|
||||
RTC_CHECK(signaling_thread->Start()) << "Failed to start thread";
|
||||
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
|
||||
|
||||
const absl::optional<PeerConnectionFactoryInterface::Options> options =
|
||||
JavaToNativePeerConnectionFactoryOptions(jni, joptions);
|
||||
|
||||
// Do not create network_monitor_factory only if the options are
|
||||
// provided and disable_network_monitor therein is set to true.
|
||||
if (!(options && options->disable_network_monitor)) {
|
||||
network_monitor_factory = new AndroidNetworkMonitorFactory();
|
||||
rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
|
||||
}
|
||||
|
||||
PeerConnectionFactoryDependencies dependencies;
|
||||
dependencies.network_thread = network_thread.get();
|
||||
dependencies.worker_thread = worker_thread.get();
|
||||
@ -310,6 +298,10 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
||||
dependencies.network_state_predictor_factory =
|
||||
std::move(network_state_predictor_factory);
|
||||
dependencies.neteq_factory = std::move(neteq_factory);
|
||||
if (!(options && options->disable_network_monitor)) {
|
||||
dependencies.network_monitor_factory =
|
||||
std::make_unique<AndroidNetworkMonitorFactory>();
|
||||
}
|
||||
|
||||
cricket::MediaEngineDependencies media_dependencies;
|
||||
media_dependencies.task_queue_factory = dependencies.task_queue_factory.get();
|
||||
@ -336,7 +328,7 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
||||
|
||||
return NativeToScopedJavaPeerConnectionFactory(
|
||||
jni, factory, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread), network_monitor_factory);
|
||||
std::move(signaling_thread));
|
||||
}
|
||||
|
||||
static ScopedJavaLocalRef<jobject>
|
||||
|
||||
@ -24,8 +24,7 @@ jobject NativeToJavaPeerConnectionFactory(
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr);
|
||||
std::unique_ptr<rtc::Thread> signaling_thread);
|
||||
|
||||
} // namespace jni
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user