mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Add rtc:SocketFactory as member of jni OwnedFactoryAndThreads
Bug: webrtc:13145 Change-Id: Iff1b59d291b1a36d474cf3fb6fafa4e9ff007aa0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232060 Reviewed-by: Jonas Oreland <jonaso@webrtc.org> Reviewed-by: Xavier Lepaul <xalep@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35051}
This commit is contained in:
parent
f7a7698aaf
commit
e7c77ecd32
8 changed files with 34 additions and 15 deletions
|
@ -1569,6 +1569,7 @@ if (is_android) {
|
|||
"../../rtc_base:checks",
|
||||
"../../rtc_base:ip_address",
|
||||
"../../rtc_base:rtc_base",
|
||||
"../../rtc_base:threading",
|
||||
"../../rtc_base/synchronization:mutex",
|
||||
"../../rtc_base/system:inline",
|
||||
"../../system_wrappers",
|
||||
|
|
|
@ -21,12 +21,13 @@ namespace webrtc {
|
|||
jobject NativeToJavaPeerConnectionFactory(
|
||||
JNIEnv* jni,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread) {
|
||||
return webrtc::jni::NativeToJavaPeerConnectionFactory(
|
||||
jni, pcf, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread));
|
||||
jni, pcf, std::move(socket_factory), std::move(network_thread),
|
||||
std::move(worker_thread), std::move(signaling_thread));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace webrtc {
|
|||
jobject NativeToJavaPeerConnectionFactory(
|
||||
JNIEnv* jni,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "media/engine/webrtc_media_engine.h"
|
||||
#include "media/engine/webrtc_media_engine_defaults.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/physical_socket_server.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "sdk/android/generated_native_unittests_jni/PeerConnectionFactoryInitializationHelper_jni.h"
|
||||
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
|
||||
#include "sdk/android/native_api/jni/jvm.h"
|
||||
|
@ -80,9 +82,10 @@ TEST(PeerConnectionFactoryTest, NativeToJavaPeerConnectionFactory) {
|
|||
jni);
|
||||
RTC_LOG(INFO) << "Java peer connection factory initialized.";
|
||||
|
||||
auto socket_server = std::make_unique<rtc::PhysicalSocketServer>();
|
||||
|
||||
// Create threads.
|
||||
std::unique_ptr<rtc::Thread> network_thread =
|
||||
rtc::Thread::CreateWithSocketServer();
|
||||
auto network_thread = std::make_unique<rtc::Thread>(socket_server.get());
|
||||
network_thread->SetName("network_thread", nullptr);
|
||||
RTC_CHECK(network_thread->Start()) << "Failed to start thread";
|
||||
|
||||
|
@ -99,8 +102,8 @@ TEST(PeerConnectionFactoryTest, NativeToJavaPeerConnectionFactory) {
|
|||
signaling_thread.get());
|
||||
|
||||
jobject java_factory = NativeToJavaPeerConnectionFactory(
|
||||
jni, factory, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread));
|
||||
jni, factory, std::move(socket_server), std::move(network_thread),
|
||||
std::move(worker_thread), std::move(signaling_thread));
|
||||
|
||||
RTC_LOG(INFO) << java_factory;
|
||||
|
||||
|
|
|
@ -16,11 +16,13 @@ namespace webrtc {
|
|||
namespace jni {
|
||||
|
||||
OwnedFactoryAndThreads::OwnedFactoryAndThreads(
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
const rtc::scoped_refptr<PeerConnectionFactoryInterface>& factory)
|
||||
: network_thread_(std::move(network_thread)),
|
||||
: socket_factory_(std::move(socket_factory)),
|
||||
network_thread_(std::move(network_thread)),
|
||||
worker_thread_(std::move(worker_thread)),
|
||||
signaling_thread_(std::move(signaling_thread)),
|
||||
factory_(factory) {}
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace jni {
|
|||
class OwnedFactoryAndThreads {
|
||||
public:
|
||||
OwnedFactoryAndThreads(
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread,
|
||||
|
@ -38,11 +39,15 @@ class OwnedFactoryAndThreads {
|
|||
~OwnedFactoryAndThreads() = default;
|
||||
|
||||
PeerConnectionFactoryInterface* factory() { return factory_.get(); }
|
||||
rtc::SocketFactory* socket_factory() { return socket_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(); }
|
||||
|
||||
private:
|
||||
// Usually implemented by the SocketServer associated with the network thread,
|
||||
// so needs to outlive the network thread.
|
||||
const std::unique_ptr<rtc::SocketFactory> socket_factory_;
|
||||
const std::unique_ptr<rtc::Thread> network_thread_;
|
||||
const std::unique_ptr<rtc::Thread> worker_thread_;
|
||||
const std::unique_ptr<rtc::Thread> signaling_thread_;
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "modules/audio_device/include/audio_device.h"
|
||||
#include "modules/audio_processing/include/audio_processing.h"
|
||||
#include "rtc_base/event_tracer.h"
|
||||
#include "rtc_base/physical_socket_server.h"
|
||||
#include "rtc_base/system/thread_registry.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "sdk/android/generated_peerconnection_jni/PeerConnectionFactory_jni.h"
|
||||
|
@ -136,12 +137,13 @@ StaticObjectContainer& GetStaticObjects() {
|
|||
ScopedJavaLocalRef<jobject> NativeToScopedJavaPeerConnectionFactory(
|
||||
JNIEnv* env,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread) {
|
||||
OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
|
||||
std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread), pcf);
|
||||
std::move(socket_factory), std::move(network_thread),
|
||||
std::move(worker_thread), std::move(signaling_thread), pcf);
|
||||
|
||||
ScopedJavaLocalRef<jobject> j_pcf = Java_PeerConnectionFactory_Constructor(
|
||||
env, NativeToJavaPointer(owned_factory));
|
||||
|
@ -174,12 +176,13 @@ static bool factory_static_initialized = false;
|
|||
jobject NativeToJavaPeerConnectionFactory(
|
||||
JNIEnv* jni,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread) {
|
||||
return NativeToScopedJavaPeerConnectionFactory(
|
||||
jni, pcf, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread))
|
||||
jni, pcf, std::move(socket_factory), std::move(network_thread),
|
||||
std::move(worker_thread), std::move(signaling_thread))
|
||||
.Release();
|
||||
}
|
||||
|
||||
|
@ -268,8 +271,8 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
|||
// think about ramifications of auto-wrapping there.
|
||||
rtc::ThreadManager::Instance()->WrapCurrentThread();
|
||||
|
||||
std::unique_ptr<rtc::Thread> network_thread =
|
||||
rtc::Thread::CreateWithSocketServer();
|
||||
auto socket_server = std::make_unique<rtc::PhysicalSocketServer>();
|
||||
auto network_thread = std::make_unique<rtc::Thread>(socket_server.get());
|
||||
network_thread->SetName("network_thread", nullptr);
|
||||
RTC_CHECK(network_thread->Start()) << "Failed to start thread";
|
||||
|
||||
|
@ -285,6 +288,8 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
|||
JavaToNativePeerConnectionFactoryOptions(jni, joptions);
|
||||
|
||||
PeerConnectionFactoryDependencies dependencies;
|
||||
// TODO(bugs.webrtc.org/13145): Also add socket_server.get() to the
|
||||
// dependencies.
|
||||
dependencies.network_thread = network_thread.get();
|
||||
dependencies.worker_thread = worker_thread.get();
|
||||
dependencies.signaling_thread = signaling_thread.get();
|
||||
|
@ -327,8 +332,8 @@ ScopedJavaLocalRef<jobject> CreatePeerConnectionFactoryForJava(
|
|||
factory->SetOptions(*options);
|
||||
|
||||
return NativeToScopedJavaPeerConnectionFactory(
|
||||
jni, factory, std::move(network_thread), std::move(worker_thread),
|
||||
std::move(signaling_thread));
|
||||
jni, factory, std::move(socket_server), std::move(network_thread),
|
||||
std::move(worker_thread), std::move(signaling_thread));
|
||||
}
|
||||
|
||||
static ScopedJavaLocalRef<jobject>
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace jni {
|
|||
jobject NativeToJavaPeerConnectionFactory(
|
||||
JNIEnv* jni,
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pcf,
|
||||
std::unique_ptr<rtc::SocketFactory> socket_factory,
|
||||
std::unique_ptr<rtc::Thread> network_thread,
|
||||
std::unique_ptr<rtc::Thread> worker_thread,
|
||||
std::unique_ptr<rtc::Thread> signaling_thread);
|
||||
|
|
Loading…
Reference in a new issue