You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2018 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. #include "api/jsep_ice_candidate.h"
  11. #include <memory>
  12. #include <utility>
  13. #include "absl/algorithm/container.h"
  14. #include "absl/memory/memory.h"
  15. namespace webrtc {
  16. std::string JsepIceCandidate::sdp_mid() const {
  17. return sdp_mid_;
  18. }
  19. int JsepIceCandidate::sdp_mline_index() const {
  20. return sdp_mline_index_;
  21. }
  22. const cricket::Candidate& JsepIceCandidate::candidate() const {
  23. return candidate_;
  24. }
  25. std::string JsepIceCandidate::server_url() const {
  26. return candidate_.url();
  27. }
  28. JsepCandidateCollection::JsepCandidateCollection() = default;
  29. JsepCandidateCollection::JsepCandidateCollection(JsepCandidateCollection&& o)
  30. : candidates_(std::move(o.candidates_)) {}
  31. size_t JsepCandidateCollection::count() const {
  32. return candidates_.size();
  33. }
  34. void JsepCandidateCollection::add(JsepIceCandidate* candidate) {
  35. candidates_.push_back(absl::WrapUnique(candidate));
  36. }
  37. const IceCandidateInterface* JsepCandidateCollection::at(size_t index) const {
  38. return candidates_[index].get();
  39. }
  40. bool JsepCandidateCollection::HasCandidate(
  41. const IceCandidateInterface* candidate) const {
  42. return absl::c_any_of(
  43. candidates_, [&](const std::unique_ptr<JsepIceCandidate>& entry) {
  44. return entry->sdp_mid() == candidate->sdp_mid() &&
  45. entry->sdp_mline_index() == candidate->sdp_mline_index() &&
  46. entry->candidate().IsEquivalent(candidate->candidate());
  47. });
  48. }
  49. size_t JsepCandidateCollection::remove(const cricket::Candidate& candidate) {
  50. auto iter = absl::c_find_if(
  51. candidates_, [&](const std::unique_ptr<JsepIceCandidate>& c) {
  52. return candidate.MatchesForRemoval(c->candidate());
  53. });
  54. if (iter != candidates_.end()) {
  55. candidates_.erase(iter);
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. } // namespace webrtc