Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "pc/sdp_utils.h" |
Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 12 | |
| 13 | #include <utility> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 14 | #include <vector> |
Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 15 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 16 | #include "api/jsep_session_description.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 17 | #include "rtc_base/checks.h" |
Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription( |
| 22 | const SessionDescriptionInterface* sdesc) { |
| 23 | RTC_DCHECK(sdesc); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 24 | return CloneSessionDescriptionAsType(sdesc, sdesc->GetType()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType( |
| 28 | const SessionDescriptionInterface* sdesc, |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 29 | SdpType type) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 30 | RTC_DCHECK(sdesc); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 31 | auto clone = std::make_unique<JsepSessionDescription>(type); |
Eldar Rello | 5ab79e6 | 2019-10-09 15:29:44 | [diff] [blame] | 32 | if (sdesc->description()) { |
| 33 | clone->Initialize(sdesc->description()->Clone(), sdesc->session_id(), |
| 34 | sdesc->session_version()); |
| 35 | } |
Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 36 | // As of writing, our version of GCC does not allow returning a unique_ptr of |
| 37 | // a subclass as a unique_ptr of a base class. To get around this, we need to |
| 38 | // std::move the return value. |
| 39 | return std::move(clone); |
| 40 | } |
| 41 | |
| 42 | bool SdpContentsAll(SdpContentPredicate pred, |
| 43 | const cricket::SessionDescription* desc) { |
| 44 | RTC_DCHECK(desc); |
| 45 | for (const auto& content : desc->contents()) { |
| 46 | const auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 47 | if (!pred(&content, transport_info)) { |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | bool SdpContentsNone(SdpContentPredicate pred, |
| 55 | const cricket::SessionDescription* desc) { |
tzik | 4e2d76c | 2019-03-20 04:43:33 | [diff] [blame] | 56 | return SdpContentsAll( |
| 57 | [pred](const cricket::ContentInfo* content_info, |
| 58 | const cricket::TransportInfo* transport_info) { |
| 59 | return !pred(content_info, transport_info); |
| 60 | }, |
| 61 | desc); |
Steve Anton | 97a9f76 | 2017-10-06 17:14:03 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void SdpContentsForEach(SdpContentMutator fn, |
| 65 | cricket::SessionDescription* desc) { |
| 66 | RTC_DCHECK(desc); |
| 67 | for (auto& content : desc->contents()) { |
| 68 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 69 | fn(&content, transport_info); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } // namespace webrtc |