aboutsummaryrefslogtreecommitdiff
path: root/pc
diff options
context:
space:
mode:
authorBenjamin Wright <benwright@webrtc.org>2018-05-02 13:46:31 -0700
committerCommit Bot <commit-bot@chromium.org>2018-05-02 21:43:47 +0000
commit6f7e6d6ff3533557ef99a0ceb01850f1fef071b3 (patch)
tree1182c431abccd7766251aced5b654177fbda3ad8 /pc
parent2199580590342381d07b215613be82964ab44871 (diff)
downloadwebrtc-6f7e6d6ff3533557ef99a0ceb01850f1fef071b3.tar.gz
Created PeerConnectionDependencies to avoid creating new CreatePeerConnection overloads.
Currently CreatePeerConnection takes 3 parameters. This is going to expand to four with a new change. Every time a new parameter is added, we need to deprecate the old method, switch clients to the new one, update fake/mock classes and tests, and so on, which is a cumbersome process. To address this, this CL introduces a PeerConnectionDependencies structure to encapsulate all mandatory and optional dependencies (where a dependency is defined as non trivial executable code that an API user may want to provide to the native API). This allows adding a new injectable dependency by simply adding a new field to the struct, avoiding the hassle described above. You may think we could use RTCConfiguration for this. But since RTCConfiguration is both passed in and out of the PeerConnection (using GetConfiguration/SetConfiguration), it can't carry unique_ptrs. And we don't want to inject dependencies via raw pointers, since this could lead to lifetime management bugs, where the dependency is deleted before the PeerConnection is done using it. Bug: webrtc:7913 Change-Id: I38c3f4ce4f26b37e6fe219d1eeca271294b40db8 Reviewed-on: https://webrtc-review.googlesource.com/73663 Commit-Queue: Benjamin Wright <benwright@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23084}
Diffstat (limited to 'pc')
-rw-r--r--pc/peerconnectionfactory.cc38
-rw-r--r--pc/peerconnectionfactory.h4
2 files changed, 31 insertions, 11 deletions
diff --git a/pc/peerconnectionfactory.cc b/pc/peerconnectionfactory.cc
index a7075efdd6..b6865ceff2 100644
--- a/pc/peerconnectionfactory.cc
+++ b/pc/peerconnectionfactory.cc
@@ -264,22 +264,35 @@ PeerConnectionFactory::CreatePeerConnection(
std::unique_ptr<cricket::PortAllocator> allocator,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
PeerConnectionObserver* observer) {
+ // Convert the legacy API into the new depnedency structure.
+ PeerConnectionDependencies dependencies(observer);
+ dependencies.allocator = std::move(allocator);
+ dependencies.cert_generator = std::move(cert_generator);
+ // Pass that into the new API.
+ return CreatePeerConnection(configuration, std::move(dependencies));
+}
+
+rtc::scoped_refptr<PeerConnectionInterface>
+PeerConnectionFactory::CreatePeerConnection(
+ const PeerConnectionInterface::RTCConfiguration& configuration,
+ PeerConnectionDependencies dependencies) {
RTC_DCHECK(signaling_thread_->IsCurrent());
- if (!cert_generator.get()) {
- // No certificate generator specified, use the default one.
- cert_generator.reset(
- new rtc::RTCCertificateGenerator(signaling_thread_, network_thread_));
+ // Set internal defaults if optional dependencies are not set.
+ if (!dependencies.cert_generator) {
+ dependencies.cert_generator = rtc::MakeUnique<rtc::RTCCertificateGenerator>(
+ signaling_thread_, network_thread_);
}
-
- if (!allocator) {
- allocator.reset(new cricket::BasicPortAllocator(
+ if (!dependencies.allocator) {
+ dependencies.allocator.reset(new cricket::BasicPortAllocator(
default_network_manager_.get(), default_socket_factory_.get(),
configuration.turn_customizer));
}
+
network_thread_->Invoke<void>(
- RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
- allocator.get(), options_.network_ignore_mask));
+ RTC_FROM_HERE,
+ rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
+ dependencies.allocator.get(), options_.network_ignore_mask));
std::unique_ptr<RtcEventLog> event_log =
worker_thread_->Invoke<std::unique_ptr<RtcEventLog>>(
@@ -294,8 +307,11 @@ PeerConnectionFactory::CreatePeerConnection(
new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
std::move(call)));
- if (!pc->Initialize(configuration, std::move(allocator),
- std::move(cert_generator), observer)) {
+ // TODO(benwright) Update initialize to take the entire dependencies
+ // structure.
+ if (!pc->Initialize(configuration, std::move(dependencies.allocator),
+ std::move(dependencies.cert_generator),
+ dependencies.observer)) {
return nullptr;
}
return PeerConnectionProxy::Create(signaling_thread(), pc);
diff --git a/pc/peerconnectionfactory.h b/pc/peerconnectionfactory.h
index f58542f42e..6fb3c24f84 100644
--- a/pc/peerconnectionfactory.h
+++ b/pc/peerconnectionfactory.h
@@ -56,6 +56,10 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
PeerConnectionObserver* observer) override;
+ rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
+ const PeerConnectionInterface::RTCConfiguration& configuration,
+ PeerConnectionDependencies dependencies) override;
+
bool Initialize();
rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(