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 | |
| 11 | // Implements the IceCandidateInterface. |
| 12 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 13 | #ifndef WEBRTC_API_JSEPICECANDIDATE_H_ |
| 14 | #define WEBRTC_API_JSEPICECANDIDATE_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | |
| 16 | #include <string> |
| 17 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 18 | #include "webrtc/api/jsep.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 19 | #include "webrtc/base/constructormagic.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 20 | #include "webrtc/p2p/base/candidate.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class JsepIceCandidate : public IceCandidateInterface { |
| 25 | public: |
| 26 | JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index); |
| 27 | JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index, |
| 28 | const cricket::Candidate& candidate); |
| 29 | ~JsepIceCandidate(); |
| 30 | // |error| can be NULL if don't care about the failure reason. |
| 31 | bool Initialize(const std::string& sdp, SdpParseError* err); |
| 32 | void SetCandidate(const cricket::Candidate& candidate) { |
| 33 | candidate_ = candidate; |
| 34 | } |
| 35 | |
| 36 | virtual std::string sdp_mid() const { return sdp_mid_; } |
| 37 | virtual int sdp_mline_index() const { return sdp_mline_index_; } |
| 38 | virtual const cricket::Candidate& candidate() const { |
| 39 | return candidate_; |
| 40 | } |
| 41 | |
| 42 | virtual bool ToString(std::string* out) const; |
| 43 | |
| 44 | private: |
| 45 | std::string sdp_mid_; |
| 46 | int sdp_mline_index_; |
| 47 | cricket::Candidate candidate_; |
| 48 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 49 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | // Implementation of IceCandidateCollection. |
| 53 | // This implementation stores JsepIceCandidates. |
| 54 | class JsepCandidateCollection : public IceCandidateCollection { |
| 55 | public: |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 56 | JsepCandidateCollection() {} |
| 57 | // Move constructor is defined so that a vector of JsepCandidateCollections |
| 58 | // can be resized. |
| 59 | JsepCandidateCollection(JsepCandidateCollection&& o) |
| 60 | : candidates_(std::move(o.candidates_)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | ~JsepCandidateCollection(); |
| 62 | virtual size_t count() const { |
| 63 | return candidates_.size(); |
| 64 | } |
| 65 | virtual bool HasCandidate(const IceCandidateInterface* candidate) const; |
| 66 | // Adds and takes ownership of the JsepIceCandidate. |
| 67 | virtual void add(JsepIceCandidate* candidate) { |
| 68 | candidates_.push_back(candidate); |
| 69 | } |
| 70 | virtual const IceCandidateInterface* at(size_t index) const { |
| 71 | return candidates_[index]; |
| 72 | } |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame^] | 73 | // Removes the candidate that has a matching address and protocol. |
| 74 | // Returns the number of candidates that were removed. |
| 75 | size_t remove(const cricket::Candidate& candidate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | std::vector<JsepIceCandidate*> candidates_; |
deadbeef | 9d3584c | 2016-02-16 17:54:10 -0800 | [diff] [blame] | 79 | |
| 80 | RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace webrtc |
| 84 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 85 | #endif // WEBRTC_API_JSEPICECANDIDATE_H_ |