1 /* 2 * Copyright 2012 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 // TODO(deadbeef): Move this out of api/; it's an implementation detail and 12 // shouldn't be used externally. 13 14 #ifndef API_JSEPICECANDIDATE_H_ 15 #define API_JSEPICECANDIDATE_H_ 16 17 #include <string> 18 #include <utility> 19 #include <vector> 20 21 #include "api/candidate.h" 22 #include "api/jsep.h" 23 #include "rtc_base/constructormagic.h" 24 25 namespace webrtc { 26 27 // Implementation of IceCandidateInterface. 28 class JsepIceCandidate : public IceCandidateInterface { 29 public: 30 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index); 31 JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index, 32 const cricket::Candidate& candidate); 33 ~JsepIceCandidate(); 34 // |err| may be null. 35 bool Initialize(const std::string& sdp, SdpParseError* err); SetCandidate(const cricket::Candidate & candidate)36 void SetCandidate(const cricket::Candidate& candidate) { 37 candidate_ = candidate; 38 } 39 sdp_mid()40 virtual std::string sdp_mid() const { return sdp_mid_; } sdp_mline_index()41 virtual int sdp_mline_index() const { return sdp_mline_index_; } candidate()42 virtual const cricket::Candidate& candidate() const { 43 return candidate_; 44 } 45 server_url()46 virtual std::string server_url() const { return candidate_.url(); } 47 48 virtual bool ToString(std::string* out) const; 49 50 private: 51 std::string sdp_mid_; 52 int sdp_mline_index_; 53 cricket::Candidate candidate_; 54 55 RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate); 56 }; 57 58 // Implementation of IceCandidateCollection which stores JsepIceCandidates. 59 class JsepCandidateCollection : public IceCandidateCollection { 60 public: JsepCandidateCollection()61 JsepCandidateCollection() {} 62 // Move constructor is defined so that a vector of JsepCandidateCollections 63 // can be resized. JsepCandidateCollection(JsepCandidateCollection && o)64 JsepCandidateCollection(JsepCandidateCollection&& o) 65 : candidates_(std::move(o.candidates_)) {} 66 ~JsepCandidateCollection(); count()67 virtual size_t count() const { 68 return candidates_.size(); 69 } 70 virtual bool HasCandidate(const IceCandidateInterface* candidate) const; 71 // Adds and takes ownership of the JsepIceCandidate. 72 // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is 73 // more clear. add(JsepIceCandidate * candidate)74 virtual void add(JsepIceCandidate* candidate) { 75 candidates_.push_back(candidate); 76 } at(size_t index)77 virtual const IceCandidateInterface* at(size_t index) const { 78 return candidates_[index]; 79 } 80 // Removes the candidate that has a matching address and protocol. 81 // 82 // Returns the number of candidates that were removed. 83 size_t remove(const cricket::Candidate& candidate); 84 85 private: 86 std::vector<JsepIceCandidate*> candidates_; 87 88 RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection); 89 }; 90 91 } // namespace webrtc 92 93 #endif // API_JSEPICECANDIDATE_H_ 94