Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "api/jsep_ice_candidate.h" |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <utility> |
| 14 | |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
| 16 | |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | |
| 19 | std::string JsepIceCandidate::sdp_mid() const { |
| 20 | return sdp_mid_; |
| 21 | } |
| 22 | |
| 23 | int JsepIceCandidate::sdp_mline_index() const { |
| 24 | return sdp_mline_index_; |
| 25 | } |
| 26 | |
| 27 | const cricket::Candidate& JsepIceCandidate::candidate() const { |
| 28 | return candidate_; |
| 29 | } |
| 30 | |
| 31 | std::string JsepIceCandidate::server_url() const { |
| 32 | return candidate_.url(); |
| 33 | } |
| 34 | |
| 35 | JsepCandidateCollection::JsepCandidateCollection() = default; |
| 36 | |
| 37 | JsepCandidateCollection::JsepCandidateCollection(JsepCandidateCollection&& o) |
| 38 | : candidates_(std::move(o.candidates_)) {} |
| 39 | |
| 40 | size_t JsepCandidateCollection::count() const { |
| 41 | return candidates_.size(); |
| 42 | } |
| 43 | |
| 44 | void JsepCandidateCollection::add(JsepIceCandidate* candidate) { |
| 45 | candidates_.push_back(candidate); |
| 46 | } |
| 47 | |
| 48 | const IceCandidateInterface* JsepCandidateCollection::at(size_t index) const { |
| 49 | return candidates_[index]; |
| 50 | } |
| 51 | |
| 52 | JsepCandidateCollection::~JsepCandidateCollection() { |
| 53 | for (std::vector<JsepIceCandidate*>::iterator it = candidates_.begin(); |
| 54 | it != candidates_.end(); ++it) { |
| 55 | delete *it; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | bool JsepCandidateCollection::HasCandidate( |
| 60 | const IceCandidateInterface* candidate) const { |
| 61 | bool ret = false; |
| 62 | for (std::vector<JsepIceCandidate*>::const_iterator it = candidates_.begin(); |
| 63 | it != candidates_.end(); ++it) { |
| 64 | if ((*it)->sdp_mid() == candidate->sdp_mid() && |
| 65 | (*it)->sdp_mline_index() == candidate->sdp_mline_index() && |
| 66 | (*it)->candidate().IsEquivalent(candidate->candidate())) { |
| 67 | ret = true; |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | size_t JsepCandidateCollection::remove(const cricket::Candidate& candidate) { |
Steve Anton | a59dcc3 | 2019-03-25 13:53:07 -0700 | [diff] [blame] | 75 | auto iter = absl::c_find_if(candidates_, [&](JsepIceCandidate* c) { |
| 76 | return candidate.MatchesForRemoval(c->candidate()); |
| 77 | }); |
Mirko Bonadei | 2ffed6d | 2018-07-20 11:09:32 +0200 | [diff] [blame] | 78 | if (iter != candidates_.end()) { |
| 79 | delete *iter; |
| 80 | candidates_.erase(iter); |
| 81 | return 1; |
| 82 | } |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | } // namespace webrtc |