1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright 2012 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Move this out of api/; it's an implementation detail and 12*d9f75844SAndroid Build Coastguard Worker // shouldn't be used externally. 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #ifndef API_JSEP_ICE_CANDIDATE_H_ 15*d9f75844SAndroid Build Coastguard Worker #define API_JSEP_ICE_CANDIDATE_H_ 16*d9f75844SAndroid Build Coastguard Worker 17*d9f75844SAndroid Build Coastguard Worker #include <stddef.h> 18*d9f75844SAndroid Build Coastguard Worker 19*d9f75844SAndroid Build Coastguard Worker #include <memory> 20*d9f75844SAndroid Build Coastguard Worker #include <string> 21*d9f75844SAndroid Build Coastguard Worker #include <vector> 22*d9f75844SAndroid Build Coastguard Worker 23*d9f75844SAndroid Build Coastguard Worker #include "api/candidate.h" 24*d9f75844SAndroid Build Coastguard Worker #include "api/jsep.h" 25*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/rtc_export.h" 26*d9f75844SAndroid Build Coastguard Worker 27*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 28*d9f75844SAndroid Build Coastguard Worker 29*d9f75844SAndroid Build Coastguard Worker // Implementation of IceCandidateInterface. 30*d9f75844SAndroid Build Coastguard Worker class RTC_EXPORT JsepIceCandidate : public IceCandidateInterface { 31*d9f75844SAndroid Build Coastguard Worker public: 32*d9f75844SAndroid Build Coastguard Worker JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index); 33*d9f75844SAndroid Build Coastguard Worker JsepIceCandidate(const std::string& sdp_mid, 34*d9f75844SAndroid Build Coastguard Worker int sdp_mline_index, 35*d9f75844SAndroid Build Coastguard Worker const cricket::Candidate& candidate); 36*d9f75844SAndroid Build Coastguard Worker JsepIceCandidate(const JsepIceCandidate&) = delete; 37*d9f75844SAndroid Build Coastguard Worker JsepIceCandidate& operator=(const JsepIceCandidate&) = delete; 38*d9f75844SAndroid Build Coastguard Worker ~JsepIceCandidate() override; 39*d9f75844SAndroid Build Coastguard Worker // `err` may be null. 40*d9f75844SAndroid Build Coastguard Worker bool Initialize(const std::string& sdp, SdpParseError* err); SetCandidate(const cricket::Candidate & candidate)41*d9f75844SAndroid Build Coastguard Worker void SetCandidate(const cricket::Candidate& candidate) { 42*d9f75844SAndroid Build Coastguard Worker candidate_ = candidate; 43*d9f75844SAndroid Build Coastguard Worker } 44*d9f75844SAndroid Build Coastguard Worker 45*d9f75844SAndroid Build Coastguard Worker std::string sdp_mid() const override; 46*d9f75844SAndroid Build Coastguard Worker int sdp_mline_index() const override; 47*d9f75844SAndroid Build Coastguard Worker const cricket::Candidate& candidate() const override; 48*d9f75844SAndroid Build Coastguard Worker 49*d9f75844SAndroid Build Coastguard Worker std::string server_url() const override; 50*d9f75844SAndroid Build Coastguard Worker 51*d9f75844SAndroid Build Coastguard Worker bool ToString(std::string* out) const override; 52*d9f75844SAndroid Build Coastguard Worker 53*d9f75844SAndroid Build Coastguard Worker private: 54*d9f75844SAndroid Build Coastguard Worker std::string sdp_mid_; 55*d9f75844SAndroid Build Coastguard Worker int sdp_mline_index_; 56*d9f75844SAndroid Build Coastguard Worker cricket::Candidate candidate_; 57*d9f75844SAndroid Build Coastguard Worker }; 58*d9f75844SAndroid Build Coastguard Worker 59*d9f75844SAndroid Build Coastguard Worker // Implementation of IceCandidateCollection which stores JsepIceCandidates. 60*d9f75844SAndroid Build Coastguard Worker class JsepCandidateCollection : public IceCandidateCollection { 61*d9f75844SAndroid Build Coastguard Worker public: 62*d9f75844SAndroid Build Coastguard Worker JsepCandidateCollection(); 63*d9f75844SAndroid Build Coastguard Worker // Move constructor is defined so that a vector of JsepCandidateCollections 64*d9f75844SAndroid Build Coastguard Worker // can be resized. 65*d9f75844SAndroid Build Coastguard Worker JsepCandidateCollection(JsepCandidateCollection&& o); 66*d9f75844SAndroid Build Coastguard Worker 67*d9f75844SAndroid Build Coastguard Worker JsepCandidateCollection(const JsepCandidateCollection&) = delete; 68*d9f75844SAndroid Build Coastguard Worker JsepCandidateCollection& operator=(const JsepCandidateCollection&) = delete; 69*d9f75844SAndroid Build Coastguard Worker 70*d9f75844SAndroid Build Coastguard Worker // Returns a copy of the candidate collection. 71*d9f75844SAndroid Build Coastguard Worker JsepCandidateCollection Clone() const; 72*d9f75844SAndroid Build Coastguard Worker size_t count() const override; 73*d9f75844SAndroid Build Coastguard Worker bool HasCandidate(const IceCandidateInterface* candidate) const override; 74*d9f75844SAndroid Build Coastguard Worker // Adds and takes ownership of the JsepIceCandidate. 75*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is 76*d9f75844SAndroid Build Coastguard Worker // more clear. 77*d9f75844SAndroid Build Coastguard Worker virtual void add(JsepIceCandidate* candidate); 78*d9f75844SAndroid Build Coastguard Worker const IceCandidateInterface* at(size_t index) const override; 79*d9f75844SAndroid Build Coastguard Worker // Removes the candidate that has a matching address and protocol. 80*d9f75844SAndroid Build Coastguard Worker // 81*d9f75844SAndroid Build Coastguard Worker // Returns the number of candidates that were removed. 82*d9f75844SAndroid Build Coastguard Worker size_t remove(const cricket::Candidate& candidate); 83*d9f75844SAndroid Build Coastguard Worker 84*d9f75844SAndroid Build Coastguard Worker private: 85*d9f75844SAndroid Build Coastguard Worker std::vector<std::unique_ptr<JsepIceCandidate>> candidates_; 86*d9f75844SAndroid Build Coastguard Worker }; 87*d9f75844SAndroid Build Coastguard Worker 88*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 89*d9f75844SAndroid Build Coastguard Worker 90*d9f75844SAndroid Build Coastguard Worker #endif // API_JSEP_ICE_CANDIDATE_H_ 91