Reland "Clean up libjingle API dependencies."
This is a reland of 9185aca9ce1f66e983d9a5e797cab77a64cc46b0
> Original change's description:
> > > Clean up libjingle API dependencies.
> > >
> > > This CL moves candidate.h into the public API, since it has
> > > been implicitly included before.
> > >
> > > This is a straightforward way of solving the circular
> > > dependencies involving that file. For instance,
> > > libjingle_peerconnection_api includes candidate.h from
> > > jsepicecandidate.h, but _api can't depend on rtc_p2p, which
> > > depends on _api. In fact, _api can't depend on much at all
> > > since it's a very high level abstraction; instead, things
> > > should depend on it.
> > >
> > > Furthermore, we have the case where deprecated headers
> > > include headers in internal modules. I just have to turn
> > > off include checking for those, but that's not a big deal.
> > >
> > > This CL punts the problem of callfactoryinterface.h being
> > > implicitly included, and pulling in most of the call
> > > module with it. This should be addressed in a follow-up
> > > CL.
> Bug: webrtc:7504
> Change-Id: Icae0ba1a0488550e2871cc65e66d3661707aa5b6
> Reviewed-on: https://webrtc-review.googlesource.com/6460
> Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20156}
TBR=deadbeef@webrtc.org
Bug: webrtc:7504
Change-Id: Ic6598ac2af9355b60bbd289c86dc75e0ae9fed2e
Reviewed-on: https://webrtc-review.googlesource.com/6801
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20167}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 86a63e4..2b7e6123 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -34,12 +34,9 @@
}
rtc_static_library("libjingle_peerconnection_api") {
- # Cannot have GN check enabled since that would introduce dependency cycles
- # TODO(kjellander): Remove (bugs.webrtc.org/7504)
- check_includes = false
cflags = []
sources = [
- "datachannel.h",
+ "candidate.h",
"datachannelinterface.h",
"dtmfsenderinterface.h",
"jsep.h",
@@ -47,17 +44,13 @@
"jsepsessiondescription.h",
"mediaconstraintsinterface.cc",
"mediaconstraintsinterface.h",
- "mediastream.h",
"mediastreaminterface.cc",
- "mediastreaminterface.h",
"mediastreamproxy.h",
- "mediastreamtrack.h",
"mediastreamtrackproxy.h",
"mediatypes.cc",
"mediatypes.h",
"notifier.h",
"peerconnectionfactoryproxy.h",
- "peerconnectioninterface.h",
"peerconnectionproxy.h",
"proxy.h",
"rtcerror.cc",
@@ -65,15 +58,11 @@
"rtpparameters.cc",
"rtpparameters.h",
"rtpreceiverinterface.h",
- "rtpsender.h",
"rtpsenderinterface.h",
"statstypes.cc",
"statstypes.h",
- "streamcollection.h",
"umametrics.h",
"videosourceproxy.h",
- "videotracksource.h",
- "webrtcsdp.h",
]
if (!build_with_chromium && is_clang) {
@@ -81,7 +70,17 @@
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
}
+ public_deps = [
+ ":libjingle_api_deprecated_headers",
+ ":mediastream_interface_and_implicit_video_frame_api",
+ ":peerconnection_and_implicit_call_api",
+ ]
+
deps = [
+ # Basically, don't add stuff here. You might break sensitive downstream
+ # targets like pnacl. API should not depend on anything, really. All these
+ # should go away, in time.
+ ":optional",
":rtc_stats_api",
"..:webrtc_common",
"../rtc_base:rtc_base",
@@ -97,6 +96,44 @@
}
}
+rtc_source_set("peerconnection_and_implicit_call_api") {
+ # The peerconnectioninterface.h file pulls in call/callfactoryinterface.h
+ # and the entire call module with it. We need to either get rid of this
+ # dependency or pull most of call/ into the API. For now, silence the warnings
+ # this creates since it creates a circular dependency (call very much depends
+ # on API). See bugs.webrtc.org/7504.
+ check_includes = false
+ sources = [
+ "peerconnectioninterface.h",
+ ]
+}
+
+rtc_source_set("mediastream_interface_and_implicit_video_frame_api") {
+ # The mediastreaminterface.h file pulls in in video_frame.h, but the
+ # system_wrappers dependency that comes with that breaks pnacl downstream.
+ # TODO(phoglund): solve this (see bugs.webrtc.org/7504).
+ check_includes = false
+ sources = [
+ "mediastreaminterface.h",
+ ]
+}
+
+rtc_source_set("libjingle_api_deprecated_headers") {
+ # We need to include headers from undeclared targets here, since they cause
+ # circular dependencies. These deprecated headers are going away anyway.
+ # See http://bugs.webrtc.org/5883.
+ check_includes = false
+ sources = [
+ "datachannel.h",
+ "mediastream.h",
+ "mediastreamtrack.h",
+ "rtpsender.h",
+ "streamcollection.h",
+ "videotracksource.h",
+ "webrtcsdp.h",
+ ]
+}
+
rtc_source_set("ortc_api") {
check_includes = false # TODO(deadbeef): Remove (bugs.webrtc.org/6828)
sources = [
diff --git a/api/candidate.h b/api/candidate.h
new file mode 100644
index 0000000..78b2082
--- /dev/null
+++ b/api/candidate.h
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef API_CANDIDATE_H_
+#define API_CANDIDATE_H_
+
+#include <limits.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <string>
+
+#include "rtc_base/checks.h"
+#include "rtc_base/helpers.h"
+#include "rtc_base/network_constants.h"
+#include "rtc_base/socketaddress.h"
+
+namespace cricket {
+
+// Candidate for ICE based connection discovery.
+// TODO(phoglund): remove things in here that are not needed in the public API.
+
+class Candidate {
+ public:
+ // TODO(pthatcher): Match the ordering and param list as per RFC 5245
+ // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1
+ Candidate()
+ : id_(rtc::CreateRandomString(8)),
+ component_(0),
+ priority_(0),
+ network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
+ generation_(0),
+ network_id_(0),
+ network_cost_(0) {}
+
+ Candidate(int component,
+ const std::string& protocol,
+ const rtc::SocketAddress& address,
+ uint32_t priority,
+ const std::string& username,
+ const std::string& password,
+ const std::string& type,
+ uint32_t generation,
+ const std::string& foundation,
+ uint16_t network_id = 0,
+ uint16_t network_cost = 0)
+ : id_(rtc::CreateRandomString(8)),
+ component_(component),
+ protocol_(protocol),
+ address_(address),
+ priority_(priority),
+ username_(username),
+ password_(password),
+ type_(type),
+ network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
+ generation_(generation),
+ foundation_(foundation),
+ network_id_(network_id),
+ network_cost_(network_cost) {}
+
+ const std::string & id() const { return id_; }
+ void set_id(const std::string & id) { id_ = id; }
+
+ int component() const { return component_; }
+ void set_component(int component) { component_ = component; }
+
+ const std::string & protocol() const { return protocol_; }
+ void set_protocol(const std::string & protocol) { protocol_ = protocol; }
+
+ // The protocol used to talk to relay.
+ const std::string& relay_protocol() const { return relay_protocol_; }
+ void set_relay_protocol(const std::string& protocol) {
+ relay_protocol_ = protocol;
+ }
+
+ const rtc::SocketAddress & address() const { return address_; }
+ void set_address(const rtc::SocketAddress & address) {
+ address_ = address;
+ }
+
+ uint32_t priority() const { return priority_; }
+ void set_priority(const uint32_t priority) { priority_ = priority; }
+
+ // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc
+ // doesn't use it.
+ // Maps old preference (which was 0.0-1.0) to match priority (which
+ // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see
+ // https://docs.google.com/a/google.com/document/d/
+ // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit
+ float preference() const {
+ // The preference value is clamped to two decimal precision.
+ return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0);
+ }
+
+ // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc
+ // doesn't use it.
+ void set_preference(float preference) {
+ // Limiting priority to UINT_MAX when value exceeds uint32_t max.
+ // This can happen for e.g. when preference = 3.
+ uint64_t prio_val = static_cast<uint64_t>(preference * 127) << 24;
+ priority_ = static_cast<uint32_t>(
+ std::min(prio_val, static_cast<uint64_t>(UINT_MAX)));
+ }
+
+ // TODO(honghaiz): Change to usernameFragment or ufrag.
+ const std::string & username() const { return username_; }
+ void set_username(const std::string & username) { username_ = username; }
+
+ const std::string & password() const { return password_; }
+ void set_password(const std::string & password) { password_ = password; }
+
+ const std::string & type() const { return type_; }
+ void set_type(const std::string & type) { type_ = type; }
+
+ const std::string & network_name() const { return network_name_; }
+ void set_network_name(const std::string & network_name) {
+ network_name_ = network_name;
+ }
+
+ rtc::AdapterType network_type() const { return network_type_; }
+ void set_network_type(rtc::AdapterType network_type) {
+ network_type_ = network_type;
+ }
+
+ // Candidates in a new generation replace those in the old generation.
+ uint32_t generation() const { return generation_; }
+ void set_generation(uint32_t generation) { generation_ = generation; }
+ const std::string generation_str() const {
+ std::ostringstream ost;
+ ost << generation_;
+ return ost.str();
+ }
+ void set_generation_str(const std::string& str) {
+ std::istringstream ist(str);
+ ist >> generation_;
+ }
+
+ // |network_cost| measures the cost/penalty of using this candidate. A network
+ // cost of 0 indicates this candidate can be used freely. A value of
+ // rtc::kNetworkCostMax indicates it should be used only as the last resort.
+ void set_network_cost(uint16_t network_cost) {
+ RTC_DCHECK_LE(network_cost, rtc::kNetworkCostMax);
+ network_cost_ = network_cost;
+ }
+ uint16_t network_cost() const { return network_cost_; }
+
+ // An ID assigned to the network hosting the candidate.
+ uint16_t network_id() const { return network_id_; }
+ void set_network_id(uint16_t network_id) { network_id_ = network_id; }
+
+ const std::string& foundation() const {
+ return foundation_;
+ }
+ void set_foundation(const std::string& foundation) {
+ foundation_ = foundation;
+ }
+
+ const rtc::SocketAddress & related_address() const {
+ return related_address_;
+ }
+ void set_related_address(
+ const rtc::SocketAddress & related_address) {
+ related_address_ = related_address;
+ }
+ const std::string& tcptype() const { return tcptype_; }
+ void set_tcptype(const std::string& tcptype) {
+ tcptype_ = tcptype;
+ }
+
+ // The name of the transport channel of this candidate.
+ // TODO(phoglund): remove.
+ const std::string& transport_name() const { return transport_name_; }
+ void set_transport_name(const std::string& transport_name) {
+ transport_name_ = transport_name;
+ }
+
+ // The URL of the ICE server which this candidate is gathered from.
+ const std::string& url() const { return url_; }
+ void set_url(const std::string& url) { url_ = url; }
+
+ // Determines whether this candidate is equivalent to the given one.
+ bool IsEquivalent(const Candidate& c) const {
+ // We ignore the network name, since that is just debug information, and
+ // the priority and the network cost, since they should be the same if the
+ // rest are.
+ return (component_ == c.component_) && (protocol_ == c.protocol_) &&
+ (address_ == c.address_) && (username_ == c.username_) &&
+ (password_ == c.password_) && (type_ == c.type_) &&
+ (generation_ == c.generation_) && (foundation_ == c.foundation_) &&
+ (related_address_ == c.related_address_) &&
+ (network_id_ == c.network_id_);
+ }
+
+ // Determines whether this candidate can be considered equivalent to the
+ // given one when looking for a matching candidate to remove.
+ bool MatchesForRemoval(const Candidate& c) const {
+ return component_ == c.component_ && protocol_ == c.protocol_ &&
+ address_ == c.address_;
+ }
+
+ std::string ToString() const {
+ return ToStringInternal(false);
+ }
+
+ std::string ToSensitiveString() const {
+ return ToStringInternal(true);
+ }
+
+ uint32_t GetPriority(uint32_t type_preference,
+ int network_adapter_preference,
+ int relay_preference) const {
+ // RFC 5245 - 4.1.2.1.
+ // priority = (2^24)*(type preference) +
+ // (2^8)*(local preference) +
+ // (2^0)*(256 - component ID)
+
+ // |local_preference| length is 2 bytes, 0-65535 inclusive.
+ // In our implemenation we will partion local_preference into
+ // 0 1
+ // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // | NIC Pref | Addr Pref |
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired.
+ // Addr Pref - Address preference value as per RFC 3484.
+ // local preference = (NIC Type << 8 | Addr_Pref) - relay preference.
+
+ int addr_pref = IPAddressPrecedence(address_.ipaddr());
+ int local_preference = ((network_adapter_preference << 8) | addr_pref) +
+ relay_preference;
+
+ return (type_preference << 24) |
+ (local_preference << 8) |
+ (256 - component_);
+ }
+
+ bool operator==(const Candidate& o) const {
+ return id_ == o.id_ && component_ == o.component_ &&
+ protocol_ == o.protocol_ && relay_protocol_ == o.relay_protocol_ &&
+ address_ == o.address_ && priority_ == o.priority_ &&
+ username_ == o.username_ && password_ == o.password_ &&
+ type_ == o.type_ && network_name_ == o.network_name_ &&
+ network_type_ == o.network_type_ && generation_ == o.generation_ &&
+ foundation_ == o.foundation_ &&
+ related_address_ == o.related_address_ && tcptype_ == o.tcptype_ &&
+ transport_name_ == o.transport_name_ && network_id_ == o.network_id_;
+ }
+ bool operator!=(const Candidate& o) const { return !(*this == o); }
+
+ private:
+ std::string ToStringInternal(bool sensitive) const {
+ std::ostringstream ost;
+ std::string address = sensitive ? address_.ToSensitiveString() :
+ address_.ToString();
+ ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_
+ << ":" << protocol_ << ":" << priority_ << ":" << address << ":"
+ << type_ << ":" << related_address_ << ":" << username_ << ":"
+ << password_ << ":" << network_id_ << ":" << network_cost_ << ":"
+ << generation_ << "]";
+ return ost.str();
+ }
+
+ std::string id_;
+ int component_;
+ std::string protocol_;
+ std::string relay_protocol_;
+ rtc::SocketAddress address_;
+ uint32_t priority_;
+ std::string username_;
+ std::string password_;
+ std::string type_;
+ std::string network_name_;
+ rtc::AdapterType network_type_;
+ uint32_t generation_;
+ std::string foundation_;
+ rtc::SocketAddress related_address_;
+ std::string tcptype_;
+ std::string transport_name_;
+ uint16_t network_id_;
+ uint16_t network_cost_;
+ std::string url_;
+};
+
+} // namespace cricket
+
+#endif // API_CANDIDATE_H_
diff --git a/api/jsepicecandidate.h b/api/jsepicecandidate.h
index 2965e86..dae6121 100644
--- a/api/jsepicecandidate.h
+++ b/api/jsepicecandidate.h
@@ -18,8 +18,8 @@
#include <utility>
#include <vector>
+#include "api/candidate.h"
#include "api/jsep.h"
-#include "p2p/base/candidate.h"
#include "rtc_base/constructormagic.h"
namespace webrtc {
diff --git a/api/jsepsessiondescription.h b/api/jsepsessiondescription.h
index 21adfee..6b115ee 100644
--- a/api/jsepsessiondescription.h
+++ b/api/jsepsessiondescription.h
@@ -18,9 +18,9 @@
#include <string>
#include <vector>
+#include "api/candidate.h"
#include "api/jsep.h"
#include "api/jsepicecandidate.h"
-#include "p2p/base/candidate.h"
#include "rtc_base/constructormagic.h"
namespace cricket {
diff --git a/api/mediastreaminterface.h b/api/mediastreaminterface.h
index 4e5fde1..fa074a0 100644
--- a/api/mediastreaminterface.h
+++ b/api/mediastreaminterface.h
@@ -27,7 +27,6 @@
// TODO(zhihuang): Remove unrelated headers once downstream applications stop
// relying on them; they were previously transitively included by
// mediachannel.h, which is no longer a dependency of this file.
-#include "media/base/streamparams.h"
#include "media/base/videosinkinterface.h"
#include "media/base/videosourceinterface.h"
#include "rtc_base/ratetracker.h"
diff --git a/p2p/base/candidate.h b/p2p/base/candidate.h
index 87f24d2..ea7d2c9 100644
--- a/p2p/base/candidate.h
+++ b/p2p/base/candidate.h
@@ -8,300 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef P2P_BASE_CANDIDATE_H_
-#define P2P_BASE_CANDIDATE_H_
+// TODO(phoglund): remove this file after downstream projects are updated.
+// See bugs.webrtc.org/7504.
-#include <limits.h>
-#include <math.h>
-#include <stdint.h>
+#ifndef P2P_CANDIDATE_H_
+#define P2P_CANDIDATE_H_
-#include <algorithm>
-#include <iomanip>
-#include <sstream>
-#include <string>
+#include "api/candidate.h"
-#include "p2p/base/p2pconstants.h"
-#include "rtc_base/checks.h"
-#include "rtc_base/helpers.h"
-#include "rtc_base/network.h"
-#include "rtc_base/socketaddress.h"
-
-namespace cricket {
-
-// Candidate for ICE based connection discovery.
-
-class Candidate {
- public:
- // TODO: Match the ordering and param list as per RFC 5245
- // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1
- Candidate()
- : id_(rtc::CreateRandomString(8)),
- component_(0),
- priority_(0),
- network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
- generation_(0),
- network_id_(0),
- network_cost_(0) {}
-
- Candidate(int component,
- const std::string& protocol,
- const rtc::SocketAddress& address,
- uint32_t priority,
- const std::string& username,
- const std::string& password,
- const std::string& type,
- uint32_t generation,
- const std::string& foundation,
- uint16_t network_id = 0,
- uint16_t network_cost = 0)
- : id_(rtc::CreateRandomString(8)),
- component_(component),
- protocol_(protocol),
- address_(address),
- priority_(priority),
- username_(username),
- password_(password),
- type_(type),
- network_type_(rtc::ADAPTER_TYPE_UNKNOWN),
- generation_(generation),
- foundation_(foundation),
- network_id_(network_id),
- network_cost_(network_cost) {}
-
- const std::string & id() const { return id_; }
- void set_id(const std::string & id) { id_ = id; }
-
- int component() const { return component_; }
- void set_component(int component) { component_ = component; }
-
- const std::string & protocol() const { return protocol_; }
- void set_protocol(const std::string & protocol) { protocol_ = protocol; }
-
- // The protocol used to talk to relay.
- const std::string& relay_protocol() const { return relay_protocol_; }
- void set_relay_protocol(const std::string& protocol) {
- relay_protocol_ = protocol;
- }
-
- const rtc::SocketAddress & address() const { return address_; }
- void set_address(const rtc::SocketAddress & address) {
- address_ = address;
- }
-
- uint32_t priority() const { return priority_; }
- void set_priority(const uint32_t priority) { priority_ = priority; }
-
- // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc
- // doesn't use it.
- // Maps old preference (which was 0.0-1.0) to match priority (which
- // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see
- // https://docs.google.com/a/google.com/document/d/
- // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit
- float preference() const {
- // The preference value is clamped to two decimal precision.
- return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0);
- }
-
- // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc
- // doesn't use it.
- void set_preference(float preference) {
- // Limiting priority to UINT_MAX when value exceeds uint32_t max.
- // This can happen for e.g. when preference = 3.
- uint64_t prio_val = static_cast<uint64_t>(preference * 127) << 24;
- priority_ = static_cast<uint32_t>(
- std::min(prio_val, static_cast<uint64_t>(UINT_MAX)));
- }
-
- // TODO(honghaiz): Change to usernameFragment or ufrag.
- const std::string & username() const { return username_; }
- void set_username(const std::string & username) { username_ = username; }
-
- const std::string & password() const { return password_; }
- void set_password(const std::string & password) { password_ = password; }
-
- const std::string & type() const { return type_; }
- void set_type(const std::string & type) { type_ = type; }
-
- const std::string & network_name() const { return network_name_; }
- void set_network_name(const std::string & network_name) {
- network_name_ = network_name;
- }
-
- rtc::AdapterType network_type() const { return network_type_; }
- void set_network_type(rtc::AdapterType network_type) {
- network_type_ = network_type;
- }
-
- // Candidates in a new generation replace those in the old generation.
- uint32_t generation() const { return generation_; }
- void set_generation(uint32_t generation) { generation_ = generation; }
- const std::string generation_str() const {
- std::ostringstream ost;
- ost << generation_;
- return ost.str();
- }
- void set_generation_str(const std::string& str) {
- std::istringstream ist(str);
- ist >> generation_;
- }
-
- // |network_cost| measures the cost/penalty of using this candidate. A network
- // cost of 0 indicates this candidate can be used freely. A value of
- // rtc::kNetworkCostMax indicates it should be used only as the last resort.
- void set_network_cost(uint16_t network_cost) {
- RTC_DCHECK_LE(network_cost, rtc::kNetworkCostMax);
- network_cost_ = network_cost;
- }
- uint16_t network_cost() const { return network_cost_; }
-
- // An ID assigned to the network hosting the candidate.
- uint16_t network_id() const { return network_id_; }
- void set_network_id(uint16_t network_id) { network_id_ = network_id; }
-
- const std::string& foundation() const {
- return foundation_;
- }
- void set_foundation(const std::string& foundation) {
- foundation_ = foundation;
- }
-
- const rtc::SocketAddress & related_address() const {
- return related_address_;
- }
- void set_related_address(
- const rtc::SocketAddress & related_address) {
- related_address_ = related_address;
- }
- const std::string& tcptype() const { return tcptype_; }
- void set_tcptype(const std::string& tcptype){
- tcptype_ = tcptype;
- }
-
- // The name of the transport channel of this candidate.
- const std::string& transport_name() const { return transport_name_; }
- void set_transport_name(const std::string& transport_name) {
- transport_name_ = transport_name;
- }
-
- // The URL of the ICE server which this candidate is gathered from.
- const std::string& url() const { return url_; }
- void set_url(const std::string& url) { url_ = url; }
-
- // Determines whether this candidate is equivalent to the given one.
- bool IsEquivalent(const Candidate& c) const {
- // We ignore the network name, since that is just debug information, and
- // the priority and the network cost, since they should be the same if the
- // rest are.
- return (component_ == c.component_) && (protocol_ == c.protocol_) &&
- (address_ == c.address_) && (username_ == c.username_) &&
- (password_ == c.password_) && (type_ == c.type_) &&
- (generation_ == c.generation_) && (foundation_ == c.foundation_) &&
- (related_address_ == c.related_address_) &&
- (network_id_ == c.network_id_);
- }
-
- // Determines whether this candidate can be considered equivalent to the
- // given one when looking for a matching candidate to remove.
- bool MatchesForRemoval(const Candidate& c) const {
- return component_ == c.component_ && protocol_ == c.protocol_ &&
- address_ == c.address_;
- }
-
- std::string ToString() const {
- return ToStringInternal(false);
- }
-
- std::string ToSensitiveString() const {
- return ToStringInternal(true);
- }
-
- uint32_t GetPriority(uint32_t type_preference,
- int network_adapter_preference,
- int relay_preference) const {
- // RFC 5245 - 4.1.2.1.
- // priority = (2^24)*(type preference) +
- // (2^8)*(local preference) +
- // (2^0)*(256 - component ID)
-
- // |local_preference| length is 2 bytes, 0-65535 inclusive.
- // In our implemenation we will partion local_preference into
- // 0 1
- // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // | NIC Pref | Addr Pref |
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired.
- // Addr Pref - Address preference value as per RFC 3484.
- // local preference = (NIC Type << 8 | Addr_Pref) - relay preference.
-
- int addr_pref = IPAddressPrecedence(address_.ipaddr());
- int local_preference = ((network_adapter_preference << 8) | addr_pref) +
- relay_preference;
-
- return (type_preference << 24) |
- (local_preference << 8) |
- (256 - component_);
- }
-
- bool operator==(const Candidate& o) const {
- return id_ == o.id_ && component_ == o.component_ &&
- protocol_ == o.protocol_ && relay_protocol_ == o.relay_protocol_ &&
- address_ == o.address_ && priority_ == o.priority_ &&
- username_ == o.username_ && password_ == o.password_ &&
- type_ == o.type_ && network_name_ == o.network_name_ &&
- network_type_ == o.network_type_ && generation_ == o.generation_ &&
- foundation_ == o.foundation_ &&
- related_address_ == o.related_address_ && tcptype_ == o.tcptype_ &&
- transport_name_ == o.transport_name_ && network_id_ == o.network_id_;
- }
- bool operator!=(const Candidate& o) const { return !(*this == o); }
-
- private:
- std::string ToStringInternal(bool sensitive) const {
- std::ostringstream ost;
- std::string address = sensitive ? address_.ToSensitiveString() :
- address_.ToString();
- ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_
- << ":" << protocol_ << ":" << priority_ << ":" << address << ":"
- << type_ << ":" << related_address_ << ":" << username_ << ":"
- << password_ << ":" << network_id_ << ":" << network_cost_ << ":"
- << generation_ << "]";
- return ost.str();
- }
-
- std::string id_;
- int component_;
- std::string protocol_;
- std::string relay_protocol_;
- rtc::SocketAddress address_;
- uint32_t priority_;
- std::string username_;
- std::string password_;
- std::string type_;
- std::string network_name_;
- rtc::AdapterType network_type_;
- uint32_t generation_;
- std::string foundation_;
- rtc::SocketAddress related_address_;
- std::string tcptype_;
- std::string transport_name_;
- uint16_t network_id_;
- uint16_t network_cost_;
- std::string url_;
-};
-
-// Used during parsing and writing to map component to channel name
-// and back. This is primarily for converting old G-ICE candidate
-// signalling to new ICE candidate classes.
-class CandidateTranslator {
- public:
- virtual ~CandidateTranslator() {}
- virtual bool GetChannelNameFromComponent(
- int component, std::string* channel_name) const = 0;
- virtual bool GetComponentFromChannelName(
- const std::string& channel_name, int* component) const = 0;
-};
-
-} // namespace cricket
-
-#endif // P2P_BASE_CANDIDATE_H_
+#endif // P2P_CANDIDATE_H_
diff --git a/p2p/base/fakecandidatepair.h b/p2p/base/fakecandidatepair.h
index 1738789..c49ac47 100644
--- a/p2p/base/fakecandidatepair.h
+++ b/p2p/base/fakecandidatepair.h
@@ -13,7 +13,7 @@
#include <memory>
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h"
namespace cricket {
diff --git a/p2p/base/icetransportinternal.h b/p2p/base/icetransportinternal.h
index 5c67df9..48f8806 100644
--- a/p2p/base/icetransportinternal.h
+++ b/p2p/base/icetransportinternal.h
@@ -13,7 +13,7 @@
#include <string>
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h"
#include "p2p/base/jseptransport.h"
#include "p2p/base/packettransportinternal.h"
diff --git a/p2p/base/jseptransport.cc b/p2p/base/jseptransport.cc
index 74094fa..fbb6287 100644
--- a/p2p/base/jseptransport.cc
+++ b/p2p/base/jseptransport.cc
@@ -13,7 +13,7 @@
#include <memory>
#include <utility> // for std::pair
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/dtlstransport.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/p2ptransportchannel.h"
diff --git a/p2p/base/jseptransport.h b/p2p/base/jseptransport.h
index 3486342..4cf9695 100644
--- a/p2p/base/jseptransport.h
+++ b/p2p/base/jseptransport.h
@@ -16,8 +16,8 @@
#include <string>
#include <vector>
+#include "api/candidate.h"
#include "api/optional.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/sessiondescription.h"
#include "p2p/base/transportinfo.h"
diff --git a/p2p/base/p2ptransportchannel.cc b/p2p/base/p2ptransportchannel.cc
index 44f8eee..c02bac7 100644
--- a/p2p/base/p2ptransportchannel.cc
+++ b/p2p/base/p2ptransportchannel.cc
@@ -14,8 +14,8 @@
#include <iterator>
#include <set>
+#include "api/candidate.h"
#include "api/umametrics.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/candidatepairinterface.h"
#include "p2p/base/common.h"
#include "p2p/base/relayport.h" // For RELAY_PORT_TYPE.
diff --git a/p2p/base/p2ptransportchannel.h b/p2p/base/p2ptransportchannel.h
index b6a84be..56ca57e 100644
--- a/p2p/base/p2ptransportchannel.h
+++ b/p2p/base/p2ptransportchannel.h
@@ -26,7 +26,7 @@
#include <string>
#include <vector>
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/candidatepairinterface.h"
#include "p2p/base/icetransportinternal.h"
#include "p2p/base/portallocator.h"
diff --git a/p2p/base/port.h b/p2p/base/port.h
index 65f4d79..61fd750 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -17,8 +17,8 @@
#include <string>
#include <vector>
+#include "api/candidate.h"
#include "api/optional.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/candidatepairinterface.h"
#include "p2p/base/jseptransport.h"
#include "p2p/base/packetlossestimator.h"
diff --git a/p2p/base/transportinfo.h b/p2p/base/transportinfo.h
index 3657b8d..3502423 100644
--- a/p2p/base/transportinfo.h
+++ b/p2p/base/transportinfo.h
@@ -14,7 +14,7 @@
#include <string>
#include <vector>
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/transportdescription.h"
#include "rtc_base/helpers.h"
diff --git a/pc/jsepsessiondescription_unittest.cc b/pc/jsepsessiondescription_unittest.cc
index 781b596..8e3c10f 100644
--- a/pc/jsepsessiondescription_unittest.cc
+++ b/pc/jsepsessiondescription_unittest.cc
@@ -11,10 +11,10 @@
#include <memory>
#include <string>
+#include "api/candidate.h"
#include "api/jsepicecandidate.h"
#include "api/jsepsessiondescription.h"
#include "api/webrtcsdp.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/sessiondescription.h"
#include "pc/mediasession.h"
diff --git a/pc/rtcstatscollector.cc b/pc/rtcstatscollector.cc
index b282e7d..36a4d6e 100644
--- a/pc/rtcstatscollector.cc
+++ b/pc/rtcstatscollector.cc
@@ -15,10 +15,10 @@
#include <utility>
#include <vector>
+#include "api/candidate.h"
#include "api/mediastreaminterface.h"
#include "api/peerconnectioninterface.h"
#include "media/base/mediachannel.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/port.h"
#include "pc/peerconnection.h"
diff --git a/pc/transportcontroller.h b/pc/transportcontroller.h
index f8cfc0c..be8dd8a 100644
--- a/pc/transportcontroller.h
+++ b/pc/transportcontroller.h
@@ -16,7 +16,7 @@
#include <string>
#include <vector>
-#include "p2p/base/candidate.h"
+#include "api/candidate.h"
#include "p2p/base/dtlstransport.h"
#include "p2p/base/jseptransport.h"
#include "p2p/base/p2ptransportchannel.h"
diff --git a/pc/webrtcsdp.cc b/pc/webrtcsdp.cc
index 648d78c..47e4298 100644
--- a/pc/webrtcsdp.cc
+++ b/pc/webrtcsdp.cc
@@ -20,6 +20,7 @@
#include <unordered_map>
#include <vector>
+#include "api/candidate.h"
#include "api/jsepicecandidate.h"
#include "api/jsepsessiondescription.h"
// for RtpExtension
@@ -29,7 +30,6 @@
#include "media/base/mediaconstants.h"
#include "media/base/rtputils.h"
#include "media/sctp/sctptransportinternal.h"
-#include "p2p/base/candidate.h"
#include "p2p/base/p2pconstants.h"
#include "p2p/base/port.h"
#include "pc/mediasession.h"
diff --git a/pc/webrtcsession.h b/pc/webrtcsession.h
index 44b64b8..284c601 100644
--- a/pc/webrtcsession.h
+++ b/pc/webrtcsession.h
@@ -16,11 +16,11 @@
#include <string>
#include <vector>
+#include "api/candidate.h"
#include "api/optional.h"
#include "api/peerconnectioninterface.h"
#include "api/statstypes.h"
#include "call/call.h"
-#include "p2p/base/candidate.h"
#include "pc/datachannel.h"
#include "pc/mediasession.h"
#include "pc/transportcontroller.h"
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 4167ad1..8c3000e 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -526,6 +526,7 @@
"nethelpers.h",
"network.cc",
"network.h",
+ "network_constants.h",
"networkmonitor.cc",
"networkmonitor.h",
"nullsocketserver.cc",
diff --git a/rtc_base/network.h b/rtc_base/network.h
index b3b43d8..6bddf46 100644
--- a/rtc_base/network.h
+++ b/rtc_base/network.h
@@ -38,12 +38,6 @@
class NetworkMonitorInterface;
class Thread;
-static const uint16_t kNetworkCostMax = 999;
-static const uint16_t kNetworkCostHigh = 900;
-static const uint16_t kNetworkCostUnknown = 50;
-static const uint16_t kNetworkCostLow = 10;
-static const uint16_t kNetworkCostMin = 0;
-
// By default, ignore loopback interfaces on the host.
const int kDefaultNetworkIgnoreMask = ADAPTER_TYPE_LOOPBACK;
diff --git a/rtc_base/network_constants.h b/rtc_base/network_constants.h
new file mode 100644
index 0000000..b4c8bea
--- /dev/null
+++ b/rtc_base/network_constants.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_NETWORK_CONSTANTS_H_
+#define RTC_BASE_NETWORK_CONSTANTS_H_
+
+#include <stdint.h>
+
+namespace rtc {
+
+static const uint16_t kNetworkCostMax = 999;
+static const uint16_t kNetworkCostHigh = 900;
+static const uint16_t kNetworkCostUnknown = 50;
+static const uint16_t kNetworkCostLow = 10;
+static const uint16_t kNetworkCostMin = 0;
+
+enum AdapterType {
+ // This enum resembles the one in Chromium net::ConnectionType.
+ ADAPTER_TYPE_UNKNOWN = 0,
+ ADAPTER_TYPE_ETHERNET = 1 << 0,
+ ADAPTER_TYPE_WIFI = 1 << 1,
+ ADAPTER_TYPE_CELLULAR = 1 << 2,
+ ADAPTER_TYPE_VPN = 1 << 3,
+ ADAPTER_TYPE_LOOPBACK = 1 << 4
+};
+
+} // namespace rtc
+
+#endif // RTC_BASE_NETWORK_CONSTANTS_H_
diff --git a/rtc_base/networkmonitor.h b/rtc_base/networkmonitor.h
index d98b803..254b225 100644
--- a/rtc_base/networkmonitor.h
+++ b/rtc_base/networkmonitor.h
@@ -12,6 +12,7 @@
#define RTC_BASE_NETWORKMONITOR_H_
#include "rtc_base/logging.h"
+#include "rtc_base/network_constants.h"
#include "rtc_base/sigslot.h"
#include "rtc_base/thread.h"
@@ -27,16 +28,6 @@
NETWORK_CHANGED = -4
};
-enum AdapterType {
- // This enum resembles the one in Chromium net::ConnectionType.
- ADAPTER_TYPE_UNKNOWN = 0,
- ADAPTER_TYPE_ETHERNET = 1 << 0,
- ADAPTER_TYPE_WIFI = 1 << 1,
- ADAPTER_TYPE_CELLULAR = 1 << 2,
- ADAPTER_TYPE_VPN = 1 << 3,
- ADAPTER_TYPE_LOOPBACK = 1 << 4
-};
-
class NetworkBinderInterface {
public:
// Binds a socket to the network that is attached to |address| so that all