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