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