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