Revert "Reland "Pass NetworkMonitorFactory through PeerConnectionFactory.""

This reverts commit 7ded73351870bfb45160fa6b9db71a94fe49397b.

Reason for revert: Found more code calling NetworkMonitorFactory::SetFactory...

Original change's description:
> Reland "Pass NetworkMonitorFactory through PeerConnectionFactory."
> 
> This is a reland of 003c9be817817ed0e3aef3f50c78ae5cb31bc0ff
> 
> Original change's description:
> > 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}
> 
> TBR=hta@webrtc.org, sakal@webrtc.org
> 
> Bug: webrtc:9883
> Change-Id: Ibf69a22e8f94226908636c7d50ff9eda65bd4129
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180720
> Reviewed-by: Taylor <deadbeef@webrtc.org>
> Commit-Queue: Taylor <deadbeef@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#31822}

TBR=deadbeef@webrtc.org,sakal@webrtc.org,hta@webrtc.org

Change-Id: Iae51b94072cec9abc021eed4e51d1fbeee998adc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:9883
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180721
Reviewed-by: Taylor <deadbeef@webrtc.org>
Commit-Queue: Taylor <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31823}
This commit is contained in:
Taylor
2020-07-31 22:39:26 +00:00
committed by Commit Bot
parent 7ded733518
commit cfba4ffe31
21 changed files with 155 additions and 176 deletions

View File

@ -15,7 +15,7 @@
#include <memory>
#include "rtc_base/network_monitor_factory.h"
#include "rtc_base/network_monitor.h"
namespace webrtc {

View File

@ -23,10 +23,11 @@ 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) {
std::unique_ptr<rtc::Thread> signaling_thread,
rtc::NetworkMonitorFactory* network_monitor_factory) {
return webrtc::jni::NativeToJavaPeerConnectionFactory(
jni, pcf, std::move(network_thread), std::move(worker_thread),
std::move(signaling_thread));
std::move(signaling_thread), network_monitor_factory);
}
} // namespace webrtc

View File

@ -26,7 +26,8 @@ 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);
std::unique_ptr<rtc::Thread> signaling_thread,
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr);
} // namespace webrtc

View File

@ -100,7 +100,7 @@ TEST(PeerConnectionFactoryTest, NativeToJavaPeerConnectionFactory) {
jobject java_factory = NativeToJavaPeerConnectionFactory(
jni, factory, std::move(network_thread), std::move(worker_thread),
std::move(signaling_thread));
std::move(signaling_thread), nullptr /* network_monitor_factory */);
RTC_LOG(INFO) << java_factory;

View File

@ -18,7 +18,6 @@
#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"

View File

@ -19,11 +19,19 @@ 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

View File

@ -33,19 +33,25 @@ 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() = default;
~OwnedFactoryAndThreads();
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_;
};

View File

@ -138,10 +138,11 @@ 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) {
std::unique_ptr<rtc::Thread> signaling_thread,
rtc::NetworkMonitorFactory* network_monitor_factory) {
OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
std::move(network_thread), std::move(worker_thread),
std::move(signaling_thread), pcf);
std::move(signaling_thread), network_monitor_factory, pcf);
ScopedJavaLocalRef<jobject> j_pcf = Java_PeerConnectionFactory_Constructor(
env, NativeToJavaPointer(owned_factory));
@ -171,15 +172,17 @@ 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) {
std::unique_ptr<rtc::Thread> signaling_thread,
rtc::NetworkMonitorFactory* network_monitor_factory) {
return NativeToScopedJavaPeerConnectionFactory(
jni, pcf, std::move(network_thread), std::move(worker_thread),
std::move(signaling_thread))
std::move(signaling_thread), network_monitor_factory)
.Release();
}
@ -281,9 +284,18 @@ 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();
@ -298,10 +310,6 @@ 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();
@ -328,7 +336,7 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
return NativeToScopedJavaPeerConnectionFactory(
jni, factory, std::move(network_thread), std::move(worker_thread),
std::move(signaling_thread));
std::move(signaling_thread), network_monitor_factory);
}
static ScopedJavaLocalRef<jobject>

View File

@ -24,7 +24,8 @@ 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);
std::unique_ptr<rtc::Thread> signaling_thread,
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr);
} // namespace jni
} // namespace webrtc