Commit c563e691 authored by deadbeef's avatar deadbeef Committed by Commit bot
Browse files

Reland of Removing references to webrtc::PortAllocatorFactoryInterface.

Relanding after fixing conflict with:
https://codereview.chromium.org/1506383004

Original description:

Now using a new CreatePeerConnection method that takes a
PortAllocator as input. This removes the need for some
boilerplate code and code duplication between webrtc and chromium.
It also fixes an issue with TURN candidate priorities.

BUG=webrtc:5209

Review URL: https://codereview.chromium.org/1516163002

Cr-Commit-Position: refs/heads/master@{#365085}
parent 0fa944d5
......@@ -136,87 +136,6 @@ void HarmonizeConstraintsAndEffects(RTCMediaConstraints* constraints,
}
}
class P2PPortAllocatorFactory
: public rtc::RefCountedObject<webrtc::PortAllocatorFactoryInterface> {
public:
P2PPortAllocatorFactory(
scoped_ptr<media::MediaPermission> media_permission,
const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher,
rtc::NetworkManager* network_manager,
rtc::PacketSocketFactory* socket_factory,
const P2PPortAllocator::Config& config,
const GURL& origin,
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
: media_permission_(media_permission.Pass()),
socket_dispatcher_(socket_dispatcher),
network_manager_(network_manager),
socket_factory_(socket_factory),
config_(config),
origin_(origin),
task_runner_(task_runner) {}
cricket::PortAllocator* CreatePortAllocator(
const std::vector<StunConfiguration>& stun_servers,
const std::vector<TurnConfiguration>& turn_configurations) override {
P2PPortAllocator::Config config = config_;
for (size_t i = 0; i < stun_servers.size(); ++i) {
config.stun_servers.insert(rtc::SocketAddress(
stun_servers[i].server.hostname(),
stun_servers[i].server.port()));
}
for (size_t i = 0; i < turn_configurations.size(); ++i) {
P2PPortAllocator::Config::RelayServerConfig relay_config;
relay_config.server_address = turn_configurations[i].server.hostname();
relay_config.port = turn_configurations[i].server.port();
relay_config.username = turn_configurations[i].username;
relay_config.password = turn_configurations[i].password;
relay_config.transport_type = turn_configurations[i].transport_type;
relay_config.secure = turn_configurations[i].secure;
config.relays.push_back(relay_config);
}
scoped_ptr<rtc::NetworkManager> network_manager;
if (config.enable_multiple_routes) {
media::MediaPermission* media_permission = media_permission_.get();
FilteringNetworkManager* filtering_network_manager =
new FilteringNetworkManager(network_manager_, origin_,
media_permission_.Pass());
if (media_permission) {
// Start permission check earlier to reduce any impact to call set up
// time. It's safe to use Unretained here since both destructor and
// Initialize can only be called on the worker thread.
task_runner_->PostTask(
FROM_HERE, base::Bind(&FilteringNetworkManager::Initialize,
base::Unretained(filtering_network_manager)));
}
network_manager.reset(filtering_network_manager);
} else {
network_manager.reset(new EmptyNetworkManager(network_manager_));
}
return new P2PPortAllocator(socket_dispatcher_, network_manager.Pass(),
socket_factory_, config, origin_, task_runner_);
}
protected:
~P2PPortAllocatorFactory() override {}
private:
// Ownership of |media_permission_| will be passed to FilteringNetworkManager
// during CreatePortAllocator.
scoped_ptr<media::MediaPermission> media_permission_;
scoped_refptr<P2PSocketDispatcher> socket_dispatcher_;
rtc::NetworkManager* network_manager_;
rtc::PacketSocketFactory* socket_factory_;
P2PPortAllocator::Config config_;
GURL origin_;
// This is the worker thread where |media_permission_| and |network_manager_|
// live on.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
};
PeerConnectionDependencyFactory::PeerConnectionDependencyFactory(
P2PSocketDispatcher* p2p_socket_dispatcher)
: network_manager_(NULL),
......@@ -541,14 +460,30 @@ PeerConnectionDependencyFactory::CreatePeerConnection(
const GURL& requesting_origin =
GURL(web_frame->document().url().spec()).GetOrigin();
scoped_refptr<P2PPortAllocatorFactory> pa_factory =
new P2PPortAllocatorFactory(
media_permission.Pass(), p2p_socket_dispatcher_, network_manager_,
socket_factory_.get(), port_config, requesting_origin,
chrome_worker_thread_.task_runner());
scoped_ptr<rtc::NetworkManager> network_manager;
if (port_config.enable_multiple_routes) {
media::MediaPermission* media_permission_ptr = media_permission.get();
FilteringNetworkManager* filtering_network_manager =
new FilteringNetworkManager(network_manager_, requesting_origin,
std::move(media_permission));
if (media_permission_ptr) {
// Start permission check earlier to reduce any impact to call set up
// time. It's safe to use Unretained here since both destructor and
// Initialize can only be called on the worker thread.
chrome_worker_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(&FilteringNetworkManager::Initialize,
base::Unretained(filtering_network_manager)));
}
network_manager.reset(filtering_network_manager);
} else {
network_manager.reset(new EmptyNetworkManager(network_manager_));
}
rtc::scoped_ptr<P2PPortAllocator> port_allocator(new P2PPortAllocator(
p2p_socket_dispatcher_, std::move(network_manager), socket_factory_.get(),
port_config, requesting_origin, chrome_worker_thread_.task_runner()));
return GetPcFactory()
->CreatePeerConnection(config, constraints, pa_factory.get(),
->CreatePeerConnection(config, constraints, std::move(port_allocator),
std::move(identity_store), observer)
.get();
}
......
......@@ -45,7 +45,8 @@ class FilteringNetworkManager : public rtc::NetworkManagerBase,
CONTENT_EXPORT ~FilteringNetworkManager() override;
// Check mic/camera permission. This is called by P2PPortAllocatorFactory.
// Check mic/camera permission.
// This is called by PeerConnectionDependencyFactory.
CONTENT_EXPORT void Initialize();
// rtc::NetworkManager:
......
......@@ -11,18 +11,6 @@
namespace content {
P2PPortAllocator::Config::Config() {}
P2PPortAllocator::Config::~Config() {
}
P2PPortAllocator::Config::RelayServerConfig::RelayServerConfig()
: port(0) {
}
P2PPortAllocator::Config::RelayServerConfig::~RelayServerConfig() {
}
P2PPortAllocator::P2PPortAllocator(
const scoped_refptr<P2PSocketDispatcher>& socket_dispatcher,
scoped_ptr<rtc::NetworkManager> network_manager,
......@@ -37,10 +25,12 @@ P2PPortAllocator::P2PPortAllocator(
origin_(origin),
network_manager_task_runner_(task_runner) {
uint32 flags = 0;
if (!config_.enable_multiple_routes)
if (!config_.enable_multiple_routes) {
flags |= cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION;
if (!config_.enable_default_local_candidate)
}
if (!config_.enable_default_local_candidate) {
flags |= cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE;
}
if (!config_.enable_nonproxied_udp) {
flags |= cricket::PORTALLOCATOR_DISABLE_UDP |
cricket::PORTALLOCATOR_DISABLE_STUN |
......@@ -65,61 +55,4 @@ P2PPortAllocator::~P2PPortAllocator() {
network_manager_.release());
}
cricket::PortAllocatorSession* P2PPortAllocator::CreateSessionInternal(
const std::string& content_name,
int component,
const std::string& ice_username_fragment,
const std::string& ice_password) {
return new P2PPortAllocatorSession(
this, content_name, component, ice_username_fragment, ice_password);
}
P2PPortAllocatorSession::P2PPortAllocatorSession(
P2PPortAllocator* allocator,
const std::string& content_name,
int component,
const std::string& ice_username_fragment,
const std::string& ice_password)
: cricket::BasicPortAllocatorSession(allocator,
content_name,
component,
ice_username_fragment,
ice_password),
allocator_(allocator) {
}
P2PPortAllocatorSession::~P2PPortAllocatorSession() {
}
void P2PPortAllocatorSession::GetPortConfigurations() {
const P2PPortAllocator::Config& config = allocator_->config_;
cricket::PortConfiguration* port_config = new cricket::PortConfiguration(
config.stun_servers, std::string(), std::string());
for (size_t i = 0; i < config.relays.size(); ++i) {
cricket::RelayCredentials credentials(config.relays[i].username,
config.relays[i].password);
cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
cricket::ProtocolType protocol;
if (!cricket::StringToProto(config.relays[i].transport_type.c_str(),
&protocol)) {
DLOG(WARNING) << "Ignoring TURN server "
<< config.relays[i].server_address << ". "
<< "Reason= Incorrect "
<< config.relays[i].transport_type
<< " transport parameter.";
continue;
}
relay_server.ports.push_back(cricket::ProtocolAddress(
rtc::SocketAddress(config.relays[i].server_address,
config.relays[i].port),
protocol,
config.relays[i].secure));
relay_server.credentials = credentials;
port_config->AddRelay(relay_server);
}
ConfigReady(port_config);
}
} // namespace content
......@@ -12,31 +12,11 @@
namespace content {
class P2PPortAllocatorSession;
class P2PSocketDispatcher;
class P2PPortAllocator : public cricket::BasicPortAllocator {
public:
struct Config {
Config();
~Config();
struct RelayServerConfig {
RelayServerConfig();
~RelayServerConfig();
std::string username;
std::string password;
std::string server_address;
int port;
std::string transport_type;
bool secure;
};
std::set<rtc::SocketAddress> stun_servers;
std::vector<RelayServerConfig> relays;
// Enable non-proxied UDP-based transport when set to true. When set to
// false, it effectively disables all UDP traffic until UDP-supporting proxy
// RETURN is available in the future.
......@@ -64,14 +44,7 @@ class P2PPortAllocator : public cricket::BasicPortAllocator {
const scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~P2PPortAllocator() override;
cricket::PortAllocatorSession* CreateSessionInternal(
const std::string& content_name,
int component,
const std::string& ice_username_fragment,
const std::string& ice_password) override;
private:
friend class P2PPortAllocatorSession;
scoped_ptr<rtc::NetworkManager> network_manager_;
scoped_refptr<P2PSocketDispatcher> socket_dispatcher_;
Config config_;
......@@ -85,26 +58,6 @@ class P2PPortAllocator : public cricket::BasicPortAllocator {
DISALLOW_COPY_AND_ASSIGN(P2PPortAllocator);
};
class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession {
public:
P2PPortAllocatorSession(
P2PPortAllocator* allocator,
const std::string& content_name,
int component,
const std::string& ice_username_fragment,
const std::string& ice_password);
~P2PPortAllocatorSession() override;
protected:
// Overrides for cricket::BasicPortAllocatorSession.
void GetPortConfigurations() override;
private:
P2PPortAllocator* allocator_;
DISALLOW_COPY_AND_ASSIGN(P2PPortAllocatorSession);
};
} // namespace content
#endif // CONTENT_RENDERER_P2P_PORT_ALLOCATOR_H_
......@@ -12,7 +12,7 @@
#include "net/url_request/url_request_context_getter.h"
#include "remoting/host/client_session.h"
#include "remoting/proto/control.pb.h"
#include "remoting/protocol/chromium_port_allocator_factory.h"
#include "remoting/protocol/chromium_port_allocator.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/webrtc_video_capturer_adapter.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
......@@ -50,8 +50,9 @@ const char kVideoLabel[] = "cast_video_label";
const char kStreamLabel[] = "stream_label";
// Default STUN server used to construct
// webrtc::PeerConnectionInterface::RTCConfiguration for the PeerConnection.
const char kDefaultStunURI[] = "stun:stun.l.google.com:19302";
// ChromiumPortAllocator for the PeerConnection.
const char kDefaultStunHost[] = "stun.l.google.com";
const int kDefaultStunPort = 19302;
const char kWorkerThreadName[] = "CastExtensionSessionWorkerThread";
......@@ -481,13 +482,6 @@ bool CastExtensionSession::InitializePeerConnection() {
VLOG(1) << "Created PeerConnectionFactory successfully.";
webrtc::PeerConnectionInterface::IceServers servers;
webrtc::PeerConnectionInterface::IceServer server;
server.uri = kDefaultStunURI;
servers.push_back(server);
webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
rtc_config.servers = servers;
// DTLS-SRTP is the preferred encryption method. If set to kValueFalse, the
// peer connection uses SDES. Disabling SDES as well will cause the peer
// connection to fail to connect.
......@@ -497,12 +491,17 @@ bool CastExtensionSession::InitializePeerConnection() {
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
webrtc::MediaConstraintsInterface::kValueTrue);
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory = protocol::ChromiumPortAllocatorFactory::Create(
network_settings_, url_request_context_getter_);
rtc::scoped_ptr<protocol::ChromiumPortAllocator> port_allocator(
protocol::ChromiumPortAllocator::Create(url_request_context_getter_,
network_settings_)
.release());
std::vector<rtc::SocketAddress> stun_hosts;
stun_hosts.push_back(rtc::SocketAddress(kDefaultStunHost, kDefaultStunPort));
port_allocator->SetStunHosts(stun_hosts);
webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
peer_connection_ = peer_conn_factory_->CreatePeerConnection(
rtc_config, &constraints, port_allocator_factory, nullptr, this);
rtc_config, &constraints, port_allocator.Pass(), nullptr, this);
if (!peer_connection_.get()) {
CleanupPeerConnection();
......
......@@ -198,7 +198,7 @@ class CastExtensionSession : public HostExtensionSession,
rtc::scoped_refptr<CastCreateSessionDescriptionObserver>
create_session_desc_observer_;
// Parameters passed to ChromiumPortAllocatorFactory on creation.
// Parameters passed to ChromiumPortAllocator on creation.
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
const protocol::NetworkSettings& network_settings_;
......
......@@ -1501,8 +1501,8 @@ void HostProcess::StartHost() {
#if !defined(NDEBUG)
network_settings.flags = protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING;
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory = protocol::ChromiumPortAllocatorFactory::Create(
scoped_ptr<protocol::PortAllocatorFactory> port_allocator_factory =
protocol::ChromiumPortAllocatorFactory::Create(
network_settings, context_->url_request_context_getter());
jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop();
......@@ -1514,7 +1514,8 @@ void HostProcess::StartHost() {
scoped_ptr<protocol::TransportFactory> transport_factory(
new protocol::WebrtcTransportFactory(
jingle_glue::JingleThreadWrapper::current(), signal_strategy_.get(),
port_allocator_factory, protocol::TransportRole::SERVER));
std::move(port_allocator_factory),
protocol::TransportRole::SERVER));
session_manager.reset(
new protocol::JingleSessionManager(transport_factory.Pass()));
......
......@@ -9,12 +9,9 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context_getter.h"
#include "third_party/webrtc/p2p/client/httpportallocator.h"
namespace net {
class URLRequestContextGetter;
} // namespace net
namespace remoting {
namespace protocol {
......
......@@ -20,33 +20,17 @@ ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {}
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
ChromiumPortAllocatorFactory::Create(
scoped_ptr<PortAllocatorFactory> ChromiumPortAllocatorFactory::Create(
const NetworkSettings& network_settings,
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
rtc::RefCountedObject<ChromiumPortAllocatorFactory>* allocator_factory =
new rtc::RefCountedObject<ChromiumPortAllocatorFactory>(
network_settings, url_request_context_getter);
return allocator_factory;
return scoped_ptr<PortAllocatorFactory>(new ChromiumPortAllocatorFactory(
network_settings, url_request_context_getter));
}
cricket::PortAllocator* ChromiumPortAllocatorFactory::CreatePortAllocator(
const std::vector<StunConfiguration>& stun_servers,
const std::vector<TurnConfiguration>& turn_configurations) {
cricket::PortAllocator* ChromiumPortAllocatorFactory::CreatePortAllocator() {
scoped_ptr<ChromiumPortAllocator> port_allocator(
ChromiumPortAllocator::Create(url_request_context_getter_,
network_settings_));
std::vector<rtc::SocketAddress> stun_hosts;
for (auto stun_it = stun_servers.begin(); stun_it != stun_servers.end();
++stun_it) {
stun_hosts.push_back(stun_it->server);
}
port_allocator->SetStunHosts(stun_hosts);
// TODO(aiguha): Figure out how to translate |turn_configurations| into
// turn hosts so we can set |port_allocator|'s relay hosts.
return port_allocator.release();
}
......
......@@ -7,8 +7,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/protocol/network_settings.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
#include "remoting/protocol/port_allocator_factory.h"
namespace net {
class URLRequestContextGetter;
......@@ -17,17 +18,14 @@ class URLRequestContextGetter;
namespace remoting {
namespace protocol {
class ChromiumPortAllocatorFactory
: public webrtc::PortAllocatorFactoryInterface {
class ChromiumPortAllocatorFactory : public PortAllocatorFactory {
public:
static rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> Create(
static scoped_ptr<PortAllocatorFactory> Create(
const NetworkSettings& network_settings,
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
// webrtc::PortAllocatorFactoryInterface implementation.
cricket::PortAllocator* CreatePortAllocator(
const std::vector<StunConfiguration>& stun_servers,
const std::vector<TurnConfiguration>& turn_configurations) override;
// PortAllocatorFactory implementation.
cricket::PortAllocator* CreatePortAllocator() override;
protected:
ChromiumPortAllocatorFactory(
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_FACTORY_H_
#define REMOTING_PROTOCOL_PORT_ALLOCATOR_FACTORY_H_
#include "third_party/webrtc/p2p/base/portallocator.h"
namespace remoting {
namespace protocol {
// Factory class used for creating cricket::PortAllocator that is used
// for ICE negotiation.
class PortAllocatorFactory {
public:
virtual cricket::PortAllocator* CreatePortAllocator() = 0;
virtual ~PortAllocatorFactory() {}
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_FACTORY_H_
......@@ -99,11 +99,9 @@ class SetSessionDescriptionObserver
} // namespace
WebrtcTransport::WebrtcTransport(
rtc::Thread* worker_thread,
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory,
TransportRole role)
WebrtcTransport::WebrtcTransport(rtc::Thread* worker_thread,
PortAllocatorFactory* port_allocator_factory,
TransportRole role)
: port_allocator_factory_(port_allocator_factory),
role_(role),
worker_thread_(worker_thread),
......@@ -138,8 +136,11 @@ void WebrtcTransport::Start(EventHandler* event_handler,
constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
webrtc::MediaConstraintsInterface::kValueTrue);
rtc::scoped_ptr<cricket::PortAllocator> port_allocator(
port_allocator_factory_->CreatePortAllocator());
peer_connection_ = peer_connection_factory_->CreatePeerConnection(
rtc_config, &constraints, port_allocator_factory_, nullptr, this);
rtc_config, &constraints, std::move(port_allocator), nullptr, this);
data_stream_adapter_.Initialize(peer_connection_,
role_ == TransportRole::SERVER);
......@@ -488,19 +489,18 @@ void WebrtcTransport::AddPendingCandidatesIfPossible() {
WebrtcTransportFactory::WebrtcTransportFactory(
rtc::Thread* worker_thread,
SignalStrategy* signal_strategy,
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory,
scoped_ptr<PortAllocatorFactory> port_allocator_factory,
TransportRole role)
: worker_thread_(worker_thread),
signal_strategy_(signal_strategy),
port_allocator_factory_(port_allocator_factory),
port_allocator_factory_(std::move(port_allocator_factory)),
role_(role) {}
WebrtcTransportFactory::~WebrtcTransportFactory() {}
scoped_ptr<Transport> WebrtcTransportFactory::CreateTransport() {
return make_scoped_ptr(
new WebrtcTransport(worker_thread_, port_allocator_factory_, role_));
return make_scoped_ptr(new WebrtcTransport(
worker_thread_, port_allocator_factory_.get(), role_));
}
} // namespace protocol
......
......@@ -6,11 +6,13 @@
#define REMOTING_PROTOCOL_WEBRTC_TRANSPORT_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "remoting/protocol/port_allocator_factory.h"
#include "remoting/protocol/transport.h"
#include "remoting/protocol/webrtc_data_stream_adapter.h"
#include "remoting/signaling/signal_strategy.h"
......@@ -27,8 +29,7 @@ class WebrtcTransport : public Transport,
public webrtc::PeerConnectionObserver {
public:
WebrtcTransport(rtc::Thread* worker_thread,
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory,
PortAllocatorFactory* port_allocator_factory,
TransportRole role);
~WebrtcTransport() override;
......@@ -79,8 +80,7 @@ class WebrtcTransport : public Transport,
base::ThreadChecker thread_checker_;
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory_;
PortAllocatorFactory* port_allocator_factory_;
TransportRole role_;
EventHandler* event_handler_ = nullptr;
rtc::Thread* worker_thread_;
......@@ -113,8 +113,7 @@ class WebrtcTransportFactory : public TransportFactory {
WebrtcTransportFactory(
rtc::Thread* worker_thread,
SignalStrategy* signal_strategy,
rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
port_allocator_factory,
scoped_ptr<PortAllocatorFactory> port_allocator_factory,
TransportRole role);
~WebrtcTransportFactory() override;