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.

73 lines
2.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2017 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 "pc/sdp_utils.h"
  11. #include <memory>
  12. #include <string>
  13. #include <utility>
  14. #include "api/jsep_session_description.h"
  15. namespace webrtc {
  16. std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
  17. const SessionDescriptionInterface* sdesc) {
  18. RTC_DCHECK(sdesc);
  19. return CloneSessionDescriptionAsType(sdesc, sdesc->GetType());
  20. }
  21. std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
  22. const SessionDescriptionInterface* sdesc,
  23. SdpType type) {
  24. RTC_DCHECK(sdesc);
  25. auto clone = std::make_unique<JsepSessionDescription>(type);
  26. if (sdesc->description()) {
  27. clone->Initialize(sdesc->description()->Clone(), sdesc->session_id(),
  28. sdesc->session_version());
  29. }
  30. // As of writing, our version of GCC does not allow returning a unique_ptr of
  31. // a subclass as a unique_ptr of a base class. To get around this, we need to
  32. // std::move the return value.
  33. return std::move(clone);
  34. }
  35. bool SdpContentsAll(SdpContentPredicate pred,
  36. const cricket::SessionDescription* desc) {
  37. RTC_DCHECK(desc);
  38. for (const auto& content : desc->contents()) {
  39. const auto* transport_info = desc->GetTransportInfoByName(content.name);
  40. if (!pred(&content, transport_info)) {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
  46. bool SdpContentsNone(SdpContentPredicate pred,
  47. const cricket::SessionDescription* desc) {
  48. return SdpContentsAll(
  49. [pred](const cricket::ContentInfo* content_info,
  50. const cricket::TransportInfo* transport_info) {
  51. return !pred(content_info, transport_info);
  52. },
  53. desc);
  54. }
  55. void SdpContentsForEach(SdpContentMutator fn,
  56. cricket::SessionDescription* desc) {
  57. RTC_DCHECK(desc);
  58. for (auto& content : desc->contents()) {
  59. auto* transport_info = desc->GetTransportInfoByName(content.name);
  60. fn(&content, transport_info);
  61. }
  62. }
  63. } // namespace webrtc