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