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