Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 bool type_supported = false; | 31 bool type_supported = false; |
| 32 for (size_t i = 0; i < arraysize(kSupportedTypes); ++i) { | 32 for (size_t i = 0; i < arraysize(kSupportedTypes); ++i) { |
| 33 if (kSupportedTypes[i] == type) { | 33 if (kSupportedTypes[i] == type) { |
| 34 type_supported = true; | 34 type_supported = true; |
| 35 break; | 35 break; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 return type_supported; | 38 return type_supported; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // RFC 5245 | |
| 42 // It is RECOMMENDED that default candidates be chosen based on the | |
| 43 // likelihood of those candidates to work with the peer that is being | |
| 44 // contacted. It is RECOMMENDED that relayed > reflexive > host. | |
| 45 static const int kPreferenceUnknown = 0; | |
| 46 static const int kPreferenceHost = 1; | |
| 47 static const int kPreferenceReflexive = 2; | |
| 48 static const int kPreferenceRelayed = 3; | |
| 49 | |
| 50 static const char kDummyAddress[] = "0.0.0.0"; | |
| 51 static const int kDummyPort = 9; | |
| 52 | |
| 53 static int GetCandidatePreferenceFromType(const std::string& type) { | |
| 54 int preference = kPreferenceUnknown; | |
| 55 if (type == cricket::LOCAL_PORT_TYPE) { | |
| 56 preference = kPreferenceHost; | |
| 57 } else if (type == cricket::STUN_PORT_TYPE) { | |
| 58 preference = kPreferenceReflexive; | |
| 59 } else if (type == cricket::RELAY_PORT_TYPE) { | |
| 60 preference = kPreferenceRelayed; | |
| 61 } else { | |
| 62 RTC_NOTREACHED(); | |
| 63 } | |
| 64 return preference; | |
| 65 } | |
| 66 | |
| 67 // Update the connection address for the MediaContentDescription based on the | |
| 68 // candidates. | |
| 69 static void UpdateConnectionAddress( | |
| 70 cricket::ContentDescription* content_description, | |
|
Taylor Brandstetter
2017/03/21 16:10:30
nit: const parameters appear first in the paramete
| |
| 71 const JsepCandidateCollection& candidate_collection) { | |
| 72 int port = kDummyPort; | |
| 73 std::string ip = kDummyAddress; | |
| 74 int current_preference = kPreferenceUnknown; | |
| 75 int current_family = AF_UNSPEC; | |
| 76 for (size_t i = 0; i < candidate_collection.count(); ++i) { | |
| 77 const IceCandidateInterface* jsep_candidate = candidate_collection.at(i); | |
| 78 if (jsep_candidate->candidate().component() != | |
| 79 cricket::ICE_CANDIDATE_COMPONENT_RTP) { | |
| 80 continue; | |
| 81 } | |
| 82 // Default destination should be UDP only. | |
| 83 if (jsep_candidate->candidate().protocol() != cricket::UDP_PROTOCOL_NAME) { | |
| 84 continue; | |
| 85 } | |
| 86 const int preference = | |
| 87 GetCandidatePreferenceFromType(jsep_candidate->candidate().type()); | |
| 88 const int family = jsep_candidate->candidate().address().ipaddr().family(); | |
| 89 // See if this candidate is more preferable then the current one if it's the | |
| 90 // same family. Or if the current family is IPv4 already so we could safely | |
| 91 // ignore all IPv6 ones. WebRTC bug 4269. | |
| 92 // http://code.google.com/p/webrtc/issues/detail?id=4269 | |
| 93 if ((preference <= current_preference && current_family == family) || | |
| 94 (current_family == AF_INET && family == AF_INET6)) { | |
| 95 continue; | |
| 96 } | |
| 97 current_preference = preference; | |
| 98 current_family = family; | |
| 99 port = jsep_candidate->candidate().address().port(); | |
| 100 ip = jsep_candidate->candidate().address().ipaddr().ToString(); | |
| 101 } | |
| 102 rtc::SocketAddress connection_addr; | |
| 103 connection_addr.SetIP(ip); | |
| 104 connection_addr.SetPort(port); | |
| 105 static_cast<cricket::MediaContentDescription*>(content_description) | |
| 106 ->set_connection_address(connection_addr); | |
| 107 } | |
| 108 | |
| 41 const char SessionDescriptionInterface::kOffer[] = "offer"; | 109 const char SessionDescriptionInterface::kOffer[] = "offer"; |
| 42 const char SessionDescriptionInterface::kPrAnswer[] = "pranswer"; | 110 const char SessionDescriptionInterface::kPrAnswer[] = "pranswer"; |
| 43 const char SessionDescriptionInterface::kAnswer[] = "answer"; | 111 const char SessionDescriptionInterface::kAnswer[] = "answer"; |
| 44 | 112 |
| 45 const int JsepSessionDescription::kDefaultVideoCodecId = 100; | 113 const int JsepSessionDescription::kDefaultVideoCodecId = 100; |
| 46 const char JsepSessionDescription::kDefaultVideoCodecName[] = "VP8"; | 114 const char JsepSessionDescription::kDefaultVideoCodecName[] = "VP8"; |
| 47 | 115 |
| 48 SessionDescriptionInterface* CreateSessionDescription(const std::string& type, | 116 SessionDescriptionInterface* CreateSessionDescription(const std::string& type, |
| 49 const std::string& sdp, | 117 const std::string& sdp, |
| 50 SdpParseError* error) { | 118 SdpParseError* error) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 } | 177 } |
| 110 if (updated_candidate.password().empty()) { | 178 if (updated_candidate.password().empty()) { |
| 111 updated_candidate.set_password(transport_info->description.ice_pwd); | 179 updated_candidate.set_password(transport_info->description.ice_pwd); |
| 112 } | 180 } |
| 113 | 181 |
| 114 std::unique_ptr<JsepIceCandidate> updated_candidate_wrapper( | 182 std::unique_ptr<JsepIceCandidate> updated_candidate_wrapper( |
| 115 new JsepIceCandidate(candidate->sdp_mid(), | 183 new JsepIceCandidate(candidate->sdp_mid(), |
| 116 static_cast<int>(mediasection_index), | 184 static_cast<int>(mediasection_index), |
| 117 updated_candidate)); | 185 updated_candidate)); |
| 118 if (!candidate_collection_[mediasection_index].HasCandidate( | 186 if (!candidate_collection_[mediasection_index].HasCandidate( |
| 119 updated_candidate_wrapper.get())) | 187 updated_candidate_wrapper.get())) { |
| 120 candidate_collection_[mediasection_index].add( | 188 candidate_collection_[mediasection_index].add( |
| 121 updated_candidate_wrapper.release()); | 189 updated_candidate_wrapper.release()); |
| 190 UpdateConnectionAddress( | |
| 191 description_->contents()[mediasection_index].description, | |
| 192 candidate_collection_[mediasection_index]); | |
| 193 } | |
| 122 | 194 |
| 123 return true; | 195 return true; |
| 124 } | 196 } |
| 125 | 197 |
| 126 size_t JsepSessionDescription::RemoveCandidates( | 198 size_t JsepSessionDescription::RemoveCandidates( |
| 127 const std::vector<cricket::Candidate>& candidates) { | 199 const std::vector<cricket::Candidate>& candidates) { |
| 128 size_t num_removed = 0; | 200 size_t num_removed = 0; |
| 129 for (auto& candidate : candidates) { | 201 for (auto& candidate : candidates) { |
| 130 int mediasection_index = GetMediasectionIndex(candidate); | 202 int mediasection_index = GetMediasectionIndex(candidate); |
| 131 if (mediasection_index < 0) { | 203 if (mediasection_index < 0) { |
| 132 // Not found. | 204 // Not found. |
| 133 continue; | 205 continue; |
| 134 } | 206 } |
| 135 num_removed += candidate_collection_[mediasection_index].remove(candidate); | 207 num_removed += candidate_collection_[mediasection_index].remove(candidate); |
| 208 UpdateConnectionAddress( | |
| 209 description_->contents()[mediasection_index].description, | |
| 210 candidate_collection_[mediasection_index]); | |
| 136 } | 211 } |
| 137 return num_removed; | 212 return num_removed; |
| 138 } | 213 } |
| 139 | 214 |
| 140 size_t JsepSessionDescription::number_of_mediasections() const { | 215 size_t JsepSessionDescription::number_of_mediasections() const { |
| 141 if (!description_) | 216 if (!description_) |
| 142 return 0; | 217 return 0; |
| 143 return description_->contents().size(); | 218 return description_->contents().size(); |
| 144 } | 219 } |
| 145 | 220 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 const std::string& transport_name = candidate.transport_name(); | 265 const std::string& transport_name = candidate.transport_name(); |
| 191 for (size_t i = 0; i < description_->contents().size(); ++i) { | 266 for (size_t i = 0; i < description_->contents().size(); ++i) { |
| 192 if (transport_name == description_->contents().at(i).name) { | 267 if (transport_name == description_->contents().at(i).name) { |
| 193 return static_cast<int>(i); | 268 return static_cast<int>(i); |
| 194 } | 269 } |
| 195 } | 270 } |
| 196 return -1; | 271 return -1; |
| 197 } | 272 } |
| 198 | 273 |
| 199 } // namespace webrtc | 274 } // namespace webrtc |
| OLD | NEW |