blob: 9339fdb874a05dbf74bca7564985b3aa53e94f41 [file] [log] [blame]
Steve Anton97a9f762017-10-06 10:14:03 -07001/*
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
18namespace webrtc {
19
20std::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
32bool 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
44bool SdpContentsNone(SdpContentPredicate pred,
45 const cricket::SessionDescription* desc) {
46 return SdpContentsAll(std::not2(pred), desc);
47}
48
49void 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