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}
This commit is contained in:
deadbeef
2015-12-01 15:01:24 -08:00
committed by Commit bot
parent 62a91ee1b1
commit 41b0798e11
4 changed files with 113 additions and 12 deletions

View File

@ -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<PeerConnectionInterface>
PeerConnectionFactory::CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
rtc::scoped_ptr<cricket::PortAllocator> allocator,
rtc::scoped_ptr<DtlsIdentityStoreInterface> 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<PeerConnection> pc(
new rtc::RefCountedObject<PeerConnection>(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<MediaStreamInterface>
PeerConnectionFactory::CreateLocalMediaStream(const std::string& label) {
RTC_DCHECK(signaling_thread_->IsCurrent());

View File

@ -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<DtlsIdentityStoreImpl>
@ -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<PeerConnectionInterface>
CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
@ -59,6 +66,13 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
PeerConnectionObserver* observer) override;
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
rtc::scoped_ptr<cricket::PortAllocator> allocator,
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
PeerConnectionObserver* observer) override;
bool Initialize();
rtc::scoped_refptr<MediaStreamInterface>
@ -119,6 +133,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
// injected any. In that case, video engine will use the internal SW decoder.
rtc::scoped_ptr<cricket::WebRtcVideoDecoderFactory>
video_decoder_factory_;
rtc::scoped_ptr<rtc::BasicNetworkManager> default_network_manager_;
rtc::scoped_ptr<rtc::BasicPacketSocketFactory> default_socket_factory_;
rtc::scoped_refptr<RefCountedDtlsIdentityStore> dtls_identity_store_;
};

View File

@ -47,9 +47,19 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
rtc::scoped_ptr<DtlsIdentityStoreInterface> a4,
PeerConnectionObserver* a5) override {
return owner_thread_->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot, this,
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot1, this,
a1, a2, a3, a4.release(), a5));
}
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& a1,
const MediaConstraintsInterface* a2,
rtc::scoped_ptr<cricket::PortAllocator> a3,
rtc::scoped_ptr<DtlsIdentityStoreInterface> a4,
PeerConnectionObserver* a5) override {
return owner_thread_->Invoke<rtc::scoped_refptr<PeerConnectionInterface>>(
rtc::Bind(&PeerConnectionFactoryProxy::CreatePeerConnection_ot2, this,
a1, a2, a3.release(), a4.release(), a5));
}
PROXY_METHOD1(rtc::scoped_refptr<MediaStreamInterface>,
CreateLocalMediaStream, const std::string&)
PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>,
@ -67,7 +77,7 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
PROXY_METHOD0(void, StopRtcEventLog)
private:
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot(
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot1(
const PeerConnectionInterface::RTCConfiguration& a1,
const MediaConstraintsInterface* a2,
PortAllocatorFactoryInterface* a3,
@ -76,6 +86,17 @@ BEGIN_PROXY_MAP(PeerConnectionFactory)
rtc::scoped_ptr<DtlsIdentityStoreInterface> ptr_a4(a4);
return c_->CreatePeerConnection(a1, a2, a3, ptr_a4.Pass(), a5);
}
rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection_ot2(
const PeerConnectionInterface::RTCConfiguration& a1,
const MediaConstraintsInterface* a2,
cricket::PortAllocator* a3,
DtlsIdentityStoreInterface* a4,
PeerConnectionObserver* a5) {
rtc::scoped_ptr<cricket::PortAllocator> ptr_a3(a3);
rtc::scoped_ptr<DtlsIdentityStoreInterface> ptr_a4(a4);
return c_->CreatePeerConnection(a1, a2, ptr_a3.Pass(), ptr_a4.Pass(), a5);
}
END_PROXY()
} // namespace webrtc

View File

@ -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<PeerConnectionInterface>
CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
PortAllocatorFactoryInterface* allocator_factory,
rtc::scoped_ptr<DtlsIdentityStoreInterface> 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<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
PortAllocatorFactoryInterface* allocator_factory,
rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
PeerConnectionObserver* observer) {
return nullptr;
}
// TODO(deadbeef): Make this pure virtual once it's implemented by all
// subclasses.
virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
rtc::scoped_ptr<cricket::PortAllocator> allocator,
rtc::scoped_ptr<DtlsIdentityStoreInterface> 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,