jsep_ice_candidate.h 2.8 KB

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