blob: 33283868f6fe3b9170642c010a8fdf6b6d5d2efd [file] [log] [blame]
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +02001/*
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 Anton10542f22019-01-11 09:11:00 -080011#include "api/jsep_ice_candidate.h"
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <utility>
14
Steve Antona59dcc32019-03-25 13:53:07 -070015#include "absl/algorithm/container.h"
16
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020017namespace webrtc {
18
19std::string JsepIceCandidate::sdp_mid() const {
20 return sdp_mid_;
21}
22
23int JsepIceCandidate::sdp_mline_index() const {
24 return sdp_mline_index_;
25}
26
27const cricket::Candidate& JsepIceCandidate::candidate() const {
28 return candidate_;
29}
30
31std::string JsepIceCandidate::server_url() const {
32 return candidate_.url();
33}
34
35JsepCandidateCollection::JsepCandidateCollection() = default;
36
37JsepCandidateCollection::JsepCandidateCollection(JsepCandidateCollection&& o)
38 : candidates_(std::move(o.candidates_)) {}
39
40size_t JsepCandidateCollection::count() const {
41 return candidates_.size();
42}
43
44void JsepCandidateCollection::add(JsepIceCandidate* candidate) {
45 candidates_.push_back(candidate);
46}
47
48const IceCandidateInterface* JsepCandidateCollection::at(size_t index) const {
49 return candidates_[index];
50}
51
52JsepCandidateCollection::~JsepCandidateCollection() {
53 for (std::vector<JsepIceCandidate*>::iterator it = candidates_.begin();
54 it != candidates_.end(); ++it) {
55 delete *it;
56 }
57}
58
59bool 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
74size_t JsepCandidateCollection::remove(const cricket::Candidate& candidate) {
Steve Antona59dcc32019-03-25 13:53:07 -070075 auto iter = absl::c_find_if(candidates_, [&](JsepIceCandidate* c) {
76 return candidate.MatchesForRemoval(c->candidate());
77 });
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +020078 if (iter != candidates_.end()) {
79 delete *iter;
80 candidates_.erase(iter);
81 return 1;
82 }
83 return 0;
84}
85
86} // namespace webrtc