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