Propogate network-worker thread split to api

BUG=webrtc:5645

Review-Url: https://codereview.webrtc.org/1968393002
Cr-Commit-Position: refs/heads/master@{#12767}
This commit is contained in:
danilchap 2016-05-17 01:52:02 -07:00 committed by Commit bot
parent c561479841
commit e9021a3601
18 changed files with 190 additions and 107 deletions

View File

@ -55,8 +55,9 @@
#include "webrtc/base/ssladapter.h"
@implementation RTCPeerConnectionFactory {
std::unique_ptr<rtc::Thread> _signalingThread;
std::unique_ptr<rtc::Thread> _networkThread;
std::unique_ptr<rtc::Thread> _workerThread;
std::unique_ptr<rtc::Thread> _signalingThread;
}
@synthesize nativeFactory = _nativeFactory;
@ -73,15 +74,21 @@
- (id)init {
if ((self = [super init])) {
_signalingThread.reset(new rtc::Thread());
BOOL result = _signalingThread->Start();
NSAssert(result, @"Failed to start signaling thread.");
_workerThread.reset(new rtc::Thread());
_networkThread = rtc::Thread::CreateWithSocketServer();
BOOL result = _networkThread->Start();
NSAssert(result, @"Failed to start network thread.");
_workerThread = rtc::Thread::Create();
result = _workerThread->Start();
NSAssert(result, @"Failed to start worker thread.");
_signalingThread = rtc::Thread::Create();
result = _signalingThread->Start();
NSAssert(result, @"Failed to start signaling thread.");
_nativeFactory = webrtc::CreatePeerConnectionFactory(
_signalingThread.get(), _workerThread.get(), nullptr, nullptr, nullptr);
_networkThread.get(), _workerThread.get(), _signalingThread.get(),
nullptr, nullptr, nullptr);
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
// Uncomment to get sensitive logs emitted (to stderr or logcat).
// rtc::LogMessage::LogToDebug(rtc::LS_SENSITIVE);

View File

@ -1038,14 +1038,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),
@ -1070,6 +1072,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_;
@ -1083,11 +1086,15 @@ void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() {
ScopedLocalRefFrame local_ref_frame(jni);
jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory");
jmethodID m = nullptr;
if (Thread::Current() == worker_thread_.get()) {
if (network_thread_->IsCurrent()) {
LOG(LS_INFO) << "Network thread JavaCallback";
m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V");
}
if (worker_thread_->IsCurrent()) {
LOG(LS_INFO) << "Worker thread JavaCallback";
m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V");
}
if (Thread::Current() == signaling_thread_.get()) {
if (signaling_thread_->IsCurrent()) {
LOG(LS_INFO) << "Signaling thread JavaCallback";
m = GetStaticMethodID(
jni, j_factory_class, "onSignalingThreadReady", "()V");
@ -1100,10 +1107,9 @@ void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() {
void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() {
LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads.";
worker_thread_->Invoke<void>(
Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
signaling_thread_->Invoke<void>(
Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
network_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
worker_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
signaling_thread_->Invoke<void>([this] { JavaCallbackOnFactoryThreads(); });
}
PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni,
@ -1143,12 +1149,20 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
// about ramifications of auto-wrapping there.
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", nullptr);
RTC_CHECK(network_thread->Start()) << "Failed to start thread";
std::unique_ptr<Thread> worker_thread = rtc::Thread::Create();
worker_thread->SetName("worker_thread", nullptr);
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;
@ -1171,11 +1185,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.get(), signaling_thread.get(),
nullptr, 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
@ -1184,8 +1196,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),
std::move(signaling_thread), encoder_factory, decoder_factory,
network_monitor_factory, factory.release());
owned_factory->InvokeJavaCallbacksOnFactoryThreads();
return jlongFromPointer(owned_factory);

View File

@ -24,6 +24,7 @@ public class PeerConnectionFactory {
private static final String TAG = "PeerConnectionFactory";
private final long nativeFactory;
private static Thread networkThread;
private static Thread workerThread;
private static Thread signalingThread;
private EglBase localEglbase;
@ -198,8 +199,9 @@ public class PeerConnectionFactory {
public void dispose() {
nativeFreeFactory(nativeFactory);
signalingThread = null;
networkThread = null;
workerThread = null;
signalingThread = null;
if (localEglbase != null)
localEglbase.release();
if (remoteEglbase != null)
@ -223,10 +225,16 @@ public class PeerConnectionFactory {
}
public static void printStackTraces() {
printStackTrace(networkThread, "Network thread");
printStackTrace(workerThread, "Worker thread");
printStackTrace(signalingThread, "Signaling thread");
}
private static void onNetworkThreadReady() {
networkThread = Thread.currentThread();
Logging.d(TAG, "onNetworkThreadReady");
}
private static void onWorkerThreadReady() {
workerThread = Thread.currentThread();
Logging.d(TAG, "onWorkerThreadReady");

View File

@ -588,8 +588,9 @@ bool PeerConnection::Initialize(
factory_->CreateMediaController(configuration.media_config));
session_.reset(
new WebRtcSession(media_controller_.get(), factory_->signaling_thread(),
factory_->worker_thread(), port_allocator_.get()));
new WebRtcSession(media_controller_.get(), factory_->network_thread(),
factory_->worker_thread(), factory_->signaling_thread(),
port_allocator_.get()));
stats_.reset(new StatsCollector(this));
// Initialize the WebRtcSession. It creates transport channels etc.

View File

@ -156,10 +156,11 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
const PeerConnectionFactory::Options* options,
std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
bool prefer_constraint_apis,
rtc::Thread* network_thread,
rtc::Thread* worker_thread) {
PeerConnectionTestClient* client(new PeerConnectionTestClient(id));
if (!client->Init(constraints, options, std::move(dtls_identity_store),
prefer_constraint_apis, worker_thread)) {
prefer_constraint_apis, network_thread, worker_thread)) {
delete client;
return nullptr;
}
@ -170,27 +171,29 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
const std::string& id,
const MediaConstraintsInterface* constraints,
const PeerConnectionFactory::Options* options,
rtc::Thread* network_thread,
rtc::Thread* worker_thread) {
std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore()
: nullptr);
return CreateClientWithDtlsIdentityStore(id, constraints, options,
std::move(dtls_identity_store),
true, worker_thread);
return CreateClientWithDtlsIdentityStore(
id, constraints, options, std::move(dtls_identity_store), true,
network_thread, worker_thread);
}
static PeerConnectionTestClient* CreateClientPreferNoConstraints(
const std::string& id,
const PeerConnectionFactory::Options* options,
rtc::Thread* network_thread,
rtc::Thread* worker_thread) {
std::unique_ptr<FakeDtlsIdentityStore> dtls_identity_store(
rtc::SSLStreamAdapter::HaveDtlsSrtp() ? new FakeDtlsIdentityStore()
: nullptr);
return CreateClientWithDtlsIdentityStore(id, nullptr, options,
std::move(dtls_identity_store),
false, worker_thread);
return CreateClientWithDtlsIdentityStore(
id, nullptr, options, std::move(dtls_identity_store), false,
network_thread, worker_thread);
}
~PeerConnectionTestClient() {
@ -806,6 +809,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
const PeerConnectionFactory::Options* options,
std::unique_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
bool prefer_constraint_apis,
rtc::Thread* network_thread,
rtc::Thread* worker_thread) {
EXPECT_TRUE(!peer_connection_);
EXPECT_TRUE(!peer_connection_factory_);
@ -815,7 +819,7 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
prefer_constraint_apis_ = prefer_constraint_apis;
std::unique_ptr<cricket::PortAllocator> port_allocator(
new cricket::FakePortAllocator(worker_thread, nullptr));
new cricket::FakePortAllocator(network_thread, nullptr));
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
if (fake_audio_capture_module_ == nullptr) {
@ -823,9 +827,11 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
}
fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
rtc::Thread* const signaling_thread = rtc::Thread::Current();
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
worker_thread, rtc::Thread::Current(), fake_audio_capture_module_,
fake_video_encoder_factory_, fake_video_decoder_factory_);
network_thread, worker_thread, signaling_thread,
fake_audio_capture_module_, fake_video_encoder_factory_,
fake_video_decoder_factory_);
if (!peer_connection_factory_) {
return false;
}
@ -1022,10 +1028,13 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
class P2PTestConductor : public testing::Test {
public:
P2PTestConductor()
: pss_(new rtc::PhysicalSocketServer),
: network_thread_(rtc::Thread::CreateWithSocketServer()),
worker_thread_(rtc::Thread::Create()),
pss_(new rtc::PhysicalSocketServer),
ss_(new rtc::VirtualSocketServer(pss_.get())),
ss_scope_(ss_.get()) {
RTC_CHECK(worker_thread_.Start());
RTC_CHECK(network_thread_->Start());
RTC_CHECK(worker_thread_->Start());
}
bool SessionActive() {
@ -1135,10 +1144,10 @@ class P2PTestConductor : public testing::Test {
bool CreateTestClientsThatPreferNoConstraints() {
initiating_client_.reset(
PeerConnectionTestClient::CreateClientPreferNoConstraints(
"Caller: ", nullptr, &worker_thread_));
"Caller: ", nullptr, network_thread_.get(), worker_thread_.get()));
receiving_client_.reset(
PeerConnectionTestClient::CreateClientPreferNoConstraints(
"Callee: ", nullptr, &worker_thread_));
"Callee: ", nullptr, network_thread_.get(), worker_thread_.get()));
if (!initiating_client_ || !receiving_client_) {
return false;
}
@ -1158,9 +1167,11 @@ class P2PTestConductor : public testing::Test {
MediaConstraintsInterface* recv_constraints,
PeerConnectionFactory::Options* recv_options) {
initiating_client_.reset(PeerConnectionTestClient::CreateClient(
"Caller: ", init_constraints, init_options, &worker_thread_));
"Caller: ", init_constraints, init_options, network_thread_.get(),
worker_thread_.get()));
receiving_client_.reset(PeerConnectionTestClient::CreateClient(
"Callee: ", recv_constraints, recv_options, &worker_thread_));
"Callee: ", recv_constraints, recv_options, network_thread_.get(),
worker_thread_.get()));
if (!initiating_client_ || !receiving_client_) {
return false;
}
@ -1262,7 +1273,7 @@ class P2PTestConductor : public testing::Test {
return PeerConnectionTestClient::CreateClientWithDtlsIdentityStore(
"New Peer: ", &setup_constraints, nullptr,
std::move(dtls_identity_store), prefer_constraint_apis_,
&worker_thread_);
network_thread_.get(), worker_thread_.get());
}
void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
@ -1304,7 +1315,8 @@ class P2PTestConductor : public testing::Test {
private:
// |worker_thread_| is used by both |initiating_client_| and
// |receiving_client_|. Must be destroyed last.
rtc::Thread worker_thread_;
std::unique_ptr<rtc::Thread> network_thread_;
std::unique_ptr<rtc::Thread> worker_thread_;
std::unique_ptr<rtc::PhysicalSocketServer> pss_;
std::unique_ptr<rtc::VirtualSocketServer> ss_;
rtc::SocketServerScope ss_scope_;

View File

@ -50,11 +50,12 @@ class PeerConnectionEndToEndTest
DataChannelList;
PeerConnectionEndToEndTest() {
RTC_CHECK(network_thread_.Start());
RTC_CHECK(worker_thread_.Start());
caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
"caller", &worker_thread_);
"caller", &network_thread_, &worker_thread_);
callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>(
"callee", &worker_thread_);
"callee", &network_thread_, &worker_thread_);
#ifdef WEBRTC_ANDROID
webrtc::InitializeAndroidObjects();
#endif
@ -155,6 +156,7 @@ class PeerConnectionEndToEndTest
}
protected:
rtc::Thread network_thread_;
rtc::Thread worker_thread_;
rtc::scoped_refptr<PeerConnectionTestWrapper> caller_;
rtc::scoped_refptr<PeerConnectionTestWrapper> callee_;

View File

@ -74,19 +74,17 @@ CreatePeerConnectionFactory() {
pc_factory);
}
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory(
rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory) {
rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
new rtc::RefCountedObject<PeerConnectionFactory>(worker_thread,
signaling_thread,
default_adm,
encoder_factory,
decoder_factory));
new rtc::RefCountedObject<PeerConnectionFactory>(
network_thread, worker_thread, signaling_thread, default_adm,
encoder_factory, decoder_factory));
// Call Initialize synchronously but make sure its executed on
// |signaling_thread|.
@ -104,16 +102,19 @@ CreatePeerConnectionFactory(
PeerConnectionFactory::PeerConnectionFactory()
: owns_ptrs_(true),
wraps_current_thread_(false),
signaling_thread_(rtc::ThreadManager::Instance()->CurrentThread()),
worker_thread_(new rtc::Thread) {
network_thread_(rtc::Thread::CreateWithSocketServer().release()),
worker_thread_(rtc::Thread::Create().release()),
signaling_thread_(rtc::Thread::Current()) {
if (!signaling_thread_) {
signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
wraps_current_thread_ = true;
}
network_thread_->Start();
worker_thread_->Start();
}
PeerConnectionFactory::PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
@ -121,13 +122,15 @@ PeerConnectionFactory::PeerConnectionFactory(
cricket::WebRtcVideoDecoderFactory* video_decoder_factory)
: owns_ptrs_(false),
wraps_current_thread_(false),
signaling_thread_(signaling_thread),
network_thread_(network_thread),
worker_thread_(worker_thread),
signaling_thread_(signaling_thread),
default_adm_(default_adm),
video_encoder_factory_(video_encoder_factory),
video_decoder_factory_(video_decoder_factory) {
ASSERT(worker_thread != NULL);
ASSERT(signaling_thread != NULL);
RTC_DCHECK(network_thread);
RTC_DCHECK(worker_thread);
RTC_DCHECK(signaling_thread);
// TODO: Currently there is no way creating an external adm in
// libjingle source tree. So we can 't currently assert if this is NULL.
// ASSERT(default_adm != NULL);
@ -148,6 +151,7 @@ PeerConnectionFactory::~PeerConnectionFactory() {
if (wraps_current_thread_)
rtc::ThreadManager::Instance()->UnwrapCurrentThread();
delete worker_thread_;
delete network_thread_;
}
}
@ -161,7 +165,7 @@ bool PeerConnectionFactory::Initialize() {
}
default_socket_factory_.reset(
new rtc::BasicPacketSocketFactory(worker_thread_));
new rtc::BasicPacketSocketFactory(network_thread_));
if (!default_socket_factory_) {
return false;
}
@ -172,17 +176,16 @@ bool PeerConnectionFactory::Initialize() {
worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind(
&PeerConnectionFactory::CreateMediaEngine_w, this));
rtc::Thread* const network_thread = worker_thread_;
channel_manager_.reset(new cricket::ChannelManager(
media_engine, worker_thread_, network_thread));
media_engine, worker_thread_, network_thread_));
channel_manager_->SetVideoRtxEnabled(true);
if (!channel_manager_->Init()) {
return false;
}
dtls_identity_store_ = new RefCountedDtlsIdentityStore(
signaling_thread_, worker_thread_);
dtls_identity_store_ =
new RefCountedDtlsIdentityStore(signaling_thread_, network_thread_);
return true;
}
@ -340,6 +343,10 @@ rtc::Thread* PeerConnectionFactory::worker_thread() {
return worker_thread_;
}
rtc::Thread* PeerConnectionFactory::network_thread() {
return network_thread_;
}
cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() {
ASSERT(worker_thread_ == rtc::Thread::Current());
return cricket::WebRtcMediaEngineFactory::Create(

View File

@ -94,11 +94,13 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
const cricket::MediaConfig& config) const;
virtual rtc::Thread* signaling_thread();
virtual rtc::Thread* worker_thread();
virtual rtc::Thread* network_thread();
const Options& options() const { return options_; }
protected:
PeerConnectionFactory();
PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
@ -111,8 +113,9 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
bool owns_ptrs_;
bool wraps_current_thread_;
rtc::Thread* signaling_thread_;
rtc::Thread* network_thread_;
rtc::Thread* worker_thread_;
rtc::Thread* signaling_thread_;
Options options_;
// External Audio device used for audio playback.
rtc::scoped_refptr<AudioDeviceModule> default_adm_;

View File

@ -87,11 +87,9 @@ class PeerConnectionFactoryTest : public testing::Test {
#ifdef WEBRTC_ANDROID
webrtc::InitializeAndroidObjects();
#endif
factory_ = webrtc::CreatePeerConnectionFactory(rtc::Thread::Current(),
rtc::Thread::Current(),
NULL,
NULL,
NULL);
factory_ = webrtc::CreatePeerConnectionFactory(
rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
nullptr, nullptr, nullptr);
ASSERT_TRUE(factory_.get() != NULL);
port_allocator_.reset(

View File

@ -58,7 +58,6 @@
#include "webrtc/api/datachannelinterface.h"
#include "webrtc/api/dtlsidentitystore.h"
#include "webrtc/api/dtlsidentitystore.h"
#include "webrtc/api/dtmfsenderinterface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/mediastreaminterface.h"
@ -66,6 +65,7 @@
#include "webrtc/api/rtpsenderinterface.h"
#include "webrtc/api/statstypes.h"
#include "webrtc/api/umametrics.h"
#include "webrtc/base/deprecation.h"
#include "webrtc/base/fileutils.h"
#include "webrtc/base/network.h"
#include "webrtc/base/rtccertificate.h"
@ -679,19 +679,34 @@ CreatePeerConnectionFactory();
// Create a new instance of PeerConnectionFactoryInterface.
//
// |worker_thread| and |signaling_thread| are the only mandatory
// parameters.
// |network_thread|, |worker_thread| and |signaling_thread| are
// the only mandatory parameters.
//
// If non-null, ownership of |default_adm|, |encoder_factory| and
// |decoder_factory| are transferred to the returned factory.
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory(
rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory);
// Create a new instance of PeerConnectionFactoryInterface.
// Same thread is used as worker and network thread.
RTC_DEPRECATED
inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory(
rtc::Thread* worker_and_network_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory) {
return CreatePeerConnectionFactory(
worker_and_network_thread, worker_and_network_thread, signaling_thread,
default_adm, encoder_factory, decoder_factory);
}
} // namespace webrtc
#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_

View File

@ -545,9 +545,9 @@ class PeerConnectionInterfaceTest : public testing::Test {
virtual void SetUp() {
pc_factory_ = webrtc::CreatePeerConnectionFactory(
rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL,
NULL);
ASSERT_TRUE(pc_factory_.get() != NULL);
rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
nullptr, nullptr, nullptr);
ASSERT_TRUE(pc_factory_);
}
void CreatePeerConnection() {

View File

@ -73,6 +73,7 @@ class MockWebRtcSession : public webrtc::WebRtcSession {
// http://crbug.com/428099.
explicit MockWebRtcSession(webrtc::MediaControllerInterface* media_controller)
: WebRtcSession(media_controller,
rtc::Thread::Current(),
rtc::Thread::Current(),
rtc::Thread::Current(),
nullptr) {}

View File

@ -47,16 +47,20 @@ void PeerConnectionTestWrapper::Connect(PeerConnectionTestWrapper* caller,
caller, &PeerConnectionTestWrapper::ReceiveAnswerSdp);
}
PeerConnectionTestWrapper::PeerConnectionTestWrapper(const std::string& name,
rtc::Thread* worker_thread)
: name_(name), worker_thread_(worker_thread) {}
PeerConnectionTestWrapper::PeerConnectionTestWrapper(
const std::string& name,
rtc::Thread* network_thread,
rtc::Thread* worker_thread)
: name_(name),
network_thread_(network_thread),
worker_thread_(worker_thread) {}
PeerConnectionTestWrapper::~PeerConnectionTestWrapper() {}
bool PeerConnectionTestWrapper::CreatePc(
const MediaConstraintsInterface* constraints) {
std::unique_ptr<cricket::PortAllocator> port_allocator(
new cricket::FakePortAllocator(worker_thread_, nullptr));
new cricket::FakePortAllocator(network_thread_, nullptr));
fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
if (fake_audio_capture_module_ == NULL) {
@ -64,8 +68,8 @@ bool PeerConnectionTestWrapper::CreatePc(
}
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
worker_thread_, rtc::Thread::Current(), fake_audio_capture_module_, NULL,
NULL);
network_thread_, worker_thread_, rtc::Thread::Current(),
fake_audio_capture_module_, NULL, NULL);
if (!peer_connection_factory_) {
return false;
}

View File

@ -27,8 +27,9 @@ class PeerConnectionTestWrapper
static void Connect(PeerConnectionTestWrapper* caller,
PeerConnectionTestWrapper* callee);
explicit PeerConnectionTestWrapper(const std::string& name,
rtc::Thread* worker_thread);
PeerConnectionTestWrapper(const std::string& name,
rtc::Thread* network_thread,
rtc::Thread* worker_thread);
virtual ~PeerConnectionTestWrapper();
bool CreatePc(const webrtc::MediaConstraintsInterface* constraints);
@ -91,7 +92,8 @@ class PeerConnectionTestWrapper
bool video, const webrtc::FakeConstraints& video_constraints);
std::string name_;
rtc::Thread* worker_thread_;
rtc::Thread* const network_thread_;
rtc::Thread* const worker_thread_;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
peer_connection_factory_;

View File

@ -454,17 +454,18 @@ bool CheckForRemoteIceRestart(const SessionDescriptionInterface* old_desc,
}
WebRtcSession::WebRtcSession(webrtc::MediaControllerInterface* media_controller,
rtc::Thread* signaling_thread,
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
cricket::PortAllocator* port_allocator)
: signaling_thread_(signaling_thread),
worker_thread_(worker_thread),
: worker_thread_(worker_thread),
signaling_thread_(signaling_thread),
// RFC 3264: The numeric value of the session id and version in the
// o line MUST be representable with a "64 bit signed integer".
// Due to this constraint session id |sid_| is max limited to LLONG_MAX.
sid_(rtc::ToString(rtc::CreateRandomId64() & LLONG_MAX)),
transport_controller_(new cricket::TransportController(signaling_thread,
worker_thread,
network_thread,
port_allocator)),
media_controller_(media_controller),
channel_manager_(media_controller_->channel_manager()),

View File

@ -138,14 +138,15 @@ class WebRtcSession : public AudioProviderInterface,
};
WebRtcSession(webrtc::MediaControllerInterface* media_controller,
rtc::Thread* signaling_thread,
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
cricket::PortAllocator* port_allocator);
virtual ~WebRtcSession();
// These are const to allow them to be called from const methods.
rtc::Thread* signaling_thread() const { return signaling_thread_; }
rtc::Thread* worker_thread() const { return worker_thread_; }
rtc::Thread* signaling_thread() const { return signaling_thread_; }
// The ID of this session.
const std::string& id() const { return sid_; }
@ -470,8 +471,8 @@ class WebRtcSession : public AudioProviderInterface,
void OnSentPacket_w(const rtc::SentPacket& sent_packet);
rtc::Thread* const signaling_thread_;
rtc::Thread* const worker_thread_;
rtc::Thread* const signaling_thread_;
State state_ = STATE_INIT;
Error error_ = ERROR_NONE;

View File

@ -208,13 +208,15 @@ class MockIceObserver : public webrtc::IceObserver {
class WebRtcSessionForTest : public webrtc::WebRtcSession {
public:
WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
rtc::Thread* signaling_thread,
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
cricket::PortAllocator* port_allocator,
webrtc::IceObserver* ice_observer)
: WebRtcSession(media_controller,
signaling_thread,
network_thread,
worker_thread,
signaling_thread,
port_allocator) {
RegisterIceObserver(ice_observer);
}
@ -381,7 +383,7 @@ class WebRtcSessionTest
ASSERT_TRUE(session_.get() == NULL);
session_.reset(new WebRtcSessionForTest(
media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
allocator_.get(), &observer_));
rtc::Thread::Current(), allocator_.get(), &observer_));
session_->SignalDataChannelOpenMessage.connect(
this, &WebRtcSessionTest::OnDataChannelOpenMessage);
session_->GetOnDestroyedSignal()->connect(

View File

@ -23,23 +23,30 @@
#include <memory>
@implementation RTCPeerConnectionFactory {
std::unique_ptr<rtc::Thread> _signalingThread;
std::unique_ptr<rtc::Thread> _networkThread;
std::unique_ptr<rtc::Thread> _workerThread;
std::unique_ptr<rtc::Thread> _signalingThread;
}
@synthesize nativeFactory = _nativeFactory;
- (instancetype)init {
if ((self = [super init])) {
_signalingThread.reset(new rtc::Thread());
BOOL result = _signalingThread->Start();
NSAssert(result, @"Failed to start signaling thread.");
_workerThread.reset(new rtc::Thread());
_networkThread = rtc::Thread::CreateWithSocketServer();
BOOL result = _networkThread->Start();
NSAssert(result, @"Failed to start network thread.");
_workerThread = rtc::Thread::Create();
result = _workerThread->Start();
NSAssert(result, @"Failed to start worker thread.");
_signalingThread = rtc::Thread::Create();
result = _signalingThread->Start();
NSAssert(result, @"Failed to start signaling thread.");
_nativeFactory = webrtc::CreatePeerConnectionFactory(
_workerThread.get(), _signalingThread.get(), nullptr, nullptr, nullptr);
_networkThread.get(), _workerThread.get(), _signalingThread.get(),
nullptr, nullptr, nullptr);
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
}
return self;