blob: b9ba2fea29aaaad62c0bcf832ba8683fc702ec04 [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
11#include "api/jsepicecandidate.h"
12
13namespace webrtc {
14
15std::string JsepIceCandidate::sdp_mid() const {
16 return sdp_mid_;
17}
18
19int JsepIceCandidate::sdp_mline_index() const {
20 return sdp_mline_index_;
21}
22
23const cricket::Candidate& JsepIceCandidate::candidate() const {
24 return candidate_;
25}
26
27std::string JsepIceCandidate::server_url() const {
28 return candidate_.url();
29}
30
31JsepCandidateCollection::JsepCandidateCollection() = default;
32
33JsepCandidateCollection::JsepCandidateCollection(JsepCandidateCollection&& o)
34 : candidates_(std::move(o.candidates_)) {}
35
36size_t JsepCandidateCollection::count() const {
37 return candidates_.size();
38}
39
40void JsepCandidateCollection::add(JsepIceCandidate* candidate) {
41 candidates_.push_back(candidate);
42}
43
44const IceCandidateInterface* JsepCandidateCollection::at(size_t index) const {
45 return candidates_[index];
46}
47
48JsepCandidateCollection::~JsepCandidateCollection() {
49 for (std::vector<JsepIceCandidate*>::iterator it = candidates_.begin();
50 it != candidates_.end(); ++it) {
51 delete *it;
52 }
53}
54
55bool JsepCandidateCollection::HasCandidate(
56 const IceCandidateInterface* candidate) const {
57 bool ret = false;
58 for (std::vector<JsepIceCandidate*>::const_iterator it = candidates_.begin();
59 it != candidates_.end(); ++it) {
60 if ((*it)->sdp_mid() == candidate->sdp_mid() &&
61 (*it)->sdp_mline_index() == candidate->sdp_mline_index() &&
62 (*it)->candidate().IsEquivalent(candidate->candidate())) {
63 ret = true;
64 break;
65 }
66 }
67 return ret;
68}
69
70size_t JsepCandidateCollection::remove(const cricket::Candidate& candidate) {
71 auto iter = std::find_if(candidates_.begin(), candidates_.end(),
72 [candidate](JsepIceCandidate* c) {
73 return candidate.MatchesForRemoval(c->candidate());
74 });
75 if (iter != candidates_.end()) {
76 delete *iter;
77 candidates_.erase(iter);
78 return 1;
79 }
80 return 0;
81}
82
83} // namespace webrtc