Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [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 | |
| 11 | #include "pc/sdputils.h" |
| 12 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 13 | #include <string> |
Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [diff] [blame] | 14 | #include <utility> |
| 15 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 16 | #include "absl/memory/memory.h" |
Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [diff] [blame] | 17 | #include "api/jsepsessiondescription.h" |
Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [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 10:27:41 -0800 | [diff] [blame] | 24 | return CloneSessionDescriptionAsType(sdesc, sdesc->GetType()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType( |
| 28 | const SessionDescriptionInterface* sdesc, |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 29 | SdpType type) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 30 | RTC_DCHECK(sdesc); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 31 | auto clone = absl::make_unique<JsepSessionDescription>(type); |
Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [diff] [blame] | 32 | clone->Initialize(sdesc->description()->Copy(), sdesc->session_id(), |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 33 | sdesc->session_version()); |
Steve Anton | 97a9f76 | 2017-10-06 10:14:03 -0700 | [diff] [blame] | 34 | // As of writing, our version of GCC does not allow returning a unique_ptr of |
| 35 | // a subclass as a unique_ptr of a base class. To get around this, we need to |
| 36 | // std::move the return value. |
| 37 | return std::move(clone); |
| 38 | } |
| 39 | |
| 40 | bool SdpContentsAll(SdpContentPredicate pred, |
| 41 | const cricket::SessionDescription* desc) { |
| 42 | RTC_DCHECK(desc); |
| 43 | for (const auto& content : desc->contents()) { |
| 44 | const auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 45 | if (!pred(&content, transport_info)) { |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | bool SdpContentsNone(SdpContentPredicate pred, |
| 53 | const cricket::SessionDescription* desc) { |
| 54 | return SdpContentsAll(std::not2(pred), desc); |
| 55 | } |
| 56 | |
| 57 | void SdpContentsForEach(SdpContentMutator fn, |
| 58 | cricket::SessionDescription* desc) { |
| 59 | RTC_DCHECK(desc); |
| 60 | for (auto& content : desc->contents()) { |
| 61 | auto* transport_info = desc->GetTransportInfoByName(content.name); |
| 62 | fn(&content, transport_info); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace webrtc |