From 41b0798e1171a105404f6bc9dcb591cdc77d659f Mon Sep 17 00:00:00 2001 From: deadbeef Date: Tue, 1 Dec 2015 15:01:24 -0800 Subject: [PATCH] Adding CreatePeerConnection method that uses new PC Initialize method. This will let us transition to the new Initialize method in Chromium, and then get rid of the old one. Review URL: https://codereview.webrtc.org/1462253002 Cr-Commit-Position: refs/heads/master@{#10860} --- talk/app/webrtc/peerconnectionfactory.cc | 54 +++++++++++++++++++- talk/app/webrtc/peerconnectionfactory.h | 16 ++++++ talk/app/webrtc/peerconnectionfactoryproxy.h | 25 ++++++++- talk/app/webrtc/peerconnectioninterface.h | 30 ++++++++--- 4 files changed, 113 insertions(+), 12 deletions(-) diff --git a/talk/app/webrtc/peerconnectionfactory.cc b/talk/app/webrtc/peerconnectionfactory.cc index b46b4b68d3..672355085a 100644 --- a/talk/app/webrtc/peerconnectionfactory.cc +++ b/talk/app/webrtc/peerconnectionfactory.cc @@ -44,6 +44,8 @@ #include "talk/media/webrtc/webrtcvideoencoderfactory.h" #include "webrtc/base/bind.h" #include "webrtc/modules/audio_device/include/audio_device.h" +#include "webrtc/p2p/base/basicpacketsocketfactory.h" +#include "webrtc/p2p/client/basicportallocator.h" namespace webrtc { @@ -156,8 +158,11 @@ PeerConnectionFactory::~PeerConnectionFactory() { default_allocator_factory_ = nullptr; // Make sure |worker_thread_| and |signaling_thread_| outlive - // |dtls_identity_store_|. + // |dtls_identity_store_|, |default_socket_factory_| and + // |default_network_manager_|. dtls_identity_store_ = nullptr; + default_socket_factory_ = nullptr; + default_network_manager_ = nullptr; if (owns_ptrs_) { if (wraps_current_thread_) @@ -171,8 +176,20 @@ bool PeerConnectionFactory::Initialize() { rtc::InitRandom(rtc::Time()); default_allocator_factory_ = PortAllocatorFactory::Create(worker_thread_); - if (!default_allocator_factory_) + if (!default_allocator_factory_) { return false; + } + + default_network_manager_.reset(new rtc::BasicNetworkManager()); + if (!default_network_manager_) { + return false; + } + + default_socket_factory_.reset( + new rtc::BasicPacketSocketFactory(worker_thread_)); + if (!default_socket_factory_) { + return false; + } // TODO: Need to make sure only one VoE is created inside // WebRtcMediaEngine. @@ -268,6 +285,39 @@ PeerConnectionFactory::CreatePeerConnection( return PeerConnectionProxy::Create(signaling_thread(), pc); } +rtc::scoped_refptr +PeerConnectionFactory::CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + rtc::scoped_ptr allocator, + rtc::scoped_ptr dtls_identity_store, + PeerConnectionObserver* observer) { + RTC_DCHECK(signaling_thread_->IsCurrent()); + + if (!dtls_identity_store.get()) { + // Because |pc|->Initialize takes ownership of the store we need a new + // wrapper object that can be deleted without deleting the underlying + // |dtls_identity_store_|, protecting it from being deleted multiple times. + dtls_identity_store.reset( + new DtlsIdentityStoreWrapper(dtls_identity_store_)); + } + + if (!allocator) { + allocator.reset(new cricket::BasicPortAllocator( + default_network_manager_.get(), default_socket_factory_.get())); + } + default_network_manager_->set_network_ignore_mask( + options_.network_ignore_mask); + + rtc::scoped_refptr pc( + new rtc::RefCountedObject(this)); + if (!pc->Initialize(configuration, constraints, std::move(allocator), + std::move(dtls_identity_store), observer)) { + return nullptr; + } + return PeerConnectionProxy::Create(signaling_thread(), pc); +} + rtc::scoped_refptr PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) { RTC_DCHECK(signaling_thread_->IsCurrent()); diff --git a/talk/app/webrtc/peerconnectionfactory.h b/talk/app/webrtc/peerconnectionfactory.h index af4117a9d3..cad89d4ab5 100644 --- a/talk/app/webrtc/peerconnectionfactory.h +++ b/talk/app/webrtc/peerconnectionfactory.h @@ -39,6 +39,11 @@ #include "webrtc/base/scoped_ref_ptr.h" #include "webrtc/base/thread.h" +namespace rtc { +class BasicNetworkManager; +class BasicPacketSocketFactory; +} + namespace webrtc { typedef rtc::RefCountedObject @@ -51,6 +56,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { } // webrtc::PeerConnectionFactoryInterface override; + // TODO(deadbeef): Get rid of this overload once clients are moved to the + // new version. rtc::scoped_refptr CreatePeerConnection( const PeerConnectionInterface::RTCConfiguration& configuration, @@ -59,6 +66,13 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { rtc::scoped_ptr dtls_identity_store, PeerConnectionObserver* observer) override; + rtc::scoped_refptr CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + rtc::scoped_ptr allocator, + rtc::scoped_ptr dtls_identity_store, + PeerConnectionObserver* observer) override; + bool Initialize(); rtc::scoped_refptr @@ -119,6 +133,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { // injected any. In that case, video engine will use the internal SW decoder. rtc::scoped_ptr video_decoder_factory_; + rtc::scoped_ptr default_network_manager_; + rtc::scoped_ptr default_socket_factory_; rtc::scoped_refptr dtls_identity_store_; }; diff --git a/talk/app/webrtc/peerconnectionfactoryproxy.h b/talk/app/webrtc/peerconnectionfactoryproxy.h index 5e924df3a1..9013ea5038 100644 --- a/talk/app/webrtc/peerconnectionfactoryproxy.h +++ b/talk/app/webrtc/peerconnectionfactoryproxy.h @@ -47,9 +47,19 @@ BEGIN_PROXY_MAP(PeerConnectionFactory) rtc::scoped_ptr a4, PeerConnectionObserver* a5) override { return owner_thread_->Invoke>( - rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot, this, + rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot1, this, a1, a2, a3, a4.release(), a5)); } + rtc::scoped_refptr CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& a1, + const MediaConstraintsInterface* a2, + rtc::scoped_ptr a3, + rtc::scoped_ptr a4, + PeerConnectionObserver* a5) override { + return owner_thread_->Invoke>( + rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot2, this, + a1, a2, a3.release(), a4.release(), a5)); + } PROXY_METHOD1(rtc::scoped_refptr, CreateLocalMediaStream, const std::string&) PROXY_METHOD1(rtc::scoped_refptr, @@ -67,7 +77,7 @@ BEGIN_PROXY_MAP(PeerConnectionFactory) PROXY_METHOD0(void, StopRtcEventLog) private: - rtc::scoped_refptr CreatePeerConnection_ot( + rtc::scoped_refptr CreatePeerConnection_ot1( const PeerConnectionInterface::RTCConfiguration& a1, const MediaConstraintsInterface* a2, PortAllocatorFactoryInterface* a3, @@ -76,6 +86,17 @@ BEGIN_PROXY_MAP(PeerConnectionFactory) rtc::scoped_ptr ptr_a4(a4); return c_->CreatePeerConnection(a1, a2, a3, ptr_a4.Pass(), a5); } + + rtc::scoped_refptr CreatePeerConnection_ot2( + const PeerConnectionInterface::RTCConfiguration& a1, + const MediaConstraintsInterface* a2, + cricket::PortAllocator* a3, + DtlsIdentityStoreInterface* a4, + PeerConnectionObserver* a5) { + rtc::scoped_ptr ptr_a3(a3); + rtc::scoped_ptr ptr_a4(a4); + return c_->CreatePeerConnection(a1, a2, ptr_a3.Pass(), ptr_a4.Pass(), a5); + } END_PROXY() } // namespace webrtc diff --git a/talk/app/webrtc/peerconnectioninterface.h b/talk/app/webrtc/peerconnectioninterface.h index f0a79a638c..8e72547a44 100644 --- a/talk/app/webrtc/peerconnectioninterface.h +++ b/talk/app/webrtc/peerconnectioninterface.h @@ -86,6 +86,7 @@ #include "webrtc/base/rtccertificate.h" #include "webrtc/base/sslstreamadapter.h" #include "webrtc/base/socketaddress.h" +#include "webrtc/p2p/base/portallocator.h" namespace rtc { class SSLIdentity; @@ -93,7 +94,6 @@ class Thread; } namespace cricket { -class PortAllocator; class WebRtcVideoDecoderFactory; class WebRtcVideoEncoderFactory; } @@ -565,13 +565,27 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { virtual void SetOptions(const Options& options) = 0; - virtual rtc::scoped_refptr - CreatePeerConnection( - const PeerConnectionInterface::RTCConfiguration& configuration, - const MediaConstraintsInterface* constraints, - PortAllocatorFactoryInterface* allocator_factory, - rtc::scoped_ptr dtls_identity_store, - PeerConnectionObserver* observer) = 0; + // TODO(deadbeef): Remove this overload of CreatePeerConnection once clients + // are moved to the new version. + virtual rtc::scoped_refptr CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + PortAllocatorFactoryInterface* allocator_factory, + rtc::scoped_ptr dtls_identity_store, + PeerConnectionObserver* observer) { + return nullptr; + } + + // TODO(deadbeef): Make this pure virtual once it's implemented by all + // subclasses. + virtual rtc::scoped_refptr CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + rtc::scoped_ptr allocator, + rtc::scoped_ptr dtls_identity_store, + PeerConnectionObserver* observer) { + return nullptr; + } // TODO(hbos): Remove below version after clients are updated to above method. // In latest W3C WebRTC draft, PC constructor will take RTCConfiguration,