henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 11 | // TODO(deadbeef): Move this out of api/; it's an implementation detail and |
| 12 | // shouldn't be used externally. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 14 | #ifndef API_JSEPICECANDIDATE_H_ |
| 15 | #define API_JSEPICECANDIDATE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 16 | |
| 17 | #include <string> |
oprypin | 803dc29 | 2017-02-01 09:55:59 | [diff] [blame] | 18 | #include <utility> |
| 19 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | |
Patrik Höglund | e2d6a06 | 2017-10-05 12:53:33 | [diff] [blame] | 21 | #include "api/candidate.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 22 | #include "api/jsep.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "rtc_base/constructormagic.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 27 | // Implementation of IceCandidateInterface. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 28 | class JsepIceCandidate : public IceCandidateInterface { |
| 29 | public: |
| 30 | JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame^] | 31 | JsepIceCandidate(const std::string& sdp_mid, |
| 32 | int sdp_mline_index, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 33 | const cricket::Candidate& candidate); |
| 34 | ~JsepIceCandidate(); |
deadbeef | 8d60a94 | 2017-02-27 22:47:33 | [diff] [blame] | 35 | // |err| may be null. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 36 | bool Initialize(const std::string& sdp, SdpParseError* err); |
| 37 | void SetCandidate(const cricket::Candidate& candidate) { |
| 38 | candidate_ = candidate; |
| 39 | } |
| 40 | |
| 41 | virtual std::string sdp_mid() const { return sdp_mid_; } |
| 42 | virtual int sdp_mline_index() const { return sdp_mline_index_; } |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame^] | 43 | virtual const cricket::Candidate& candidate() const { return candidate_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 44 | |
zhihuang | d7e771d | 2017-02-16 19:29:39 | [diff] [blame] | 45 | virtual std::string server_url() const { return candidate_.url(); } |
| 46 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 47 | virtual bool ToString(std::string* out) const; |
| 48 | |
| 49 | private: |
| 50 | std::string sdp_mid_; |
| 51 | int sdp_mline_index_; |
| 52 | cricket::Candidate candidate_; |
| 53 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 54 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 55 | }; |
| 56 | |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 57 | // Implementation of IceCandidateCollection which stores JsepIceCandidates. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 58 | class JsepCandidateCollection : public IceCandidateCollection { |
| 59 | public: |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 60 | JsepCandidateCollection() {} |
| 61 | // Move constructor is defined so that a vector of JsepCandidateCollections |
| 62 | // can be resized. |
| 63 | JsepCandidateCollection(JsepCandidateCollection&& o) |
| 64 | : candidates_(std::move(o.candidates_)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 65 | ~JsepCandidateCollection(); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame^] | 66 | virtual size_t count() const { return candidates_.size(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 67 | virtual bool HasCandidate(const IceCandidateInterface* candidate) const; |
| 68 | // Adds and takes ownership of the JsepIceCandidate. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 69 | // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is |
| 70 | // more clear. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 71 | virtual void add(JsepIceCandidate* candidate) { |
| 72 | candidates_.push_back(candidate); |
| 73 | } |
| 74 | virtual const IceCandidateInterface* at(size_t index) const { |
| 75 | return candidates_[index]; |
| 76 | } |
Honghai Zhang | 7fb69db | 2016-03-14 18:59:18 | [diff] [blame] | 77 | // Removes the candidate that has a matching address and protocol. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 78 | // |
Honghai Zhang | 7fb69db | 2016-03-14 18:59:18 | [diff] [blame] | 79 | // Returns the number of candidates that were removed. |
| 80 | size_t remove(const cricket::Candidate& candidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | std::vector<JsepIceCandidate*> candidates_; |
deadbeef | 9d3584c | 2016-02-17 01:54:10 | [diff] [blame] | 84 | |
| 85 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // namespace webrtc |
| 89 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 90 | #endif // API_JSEPICECANDIDATE_H_ |