blob: 8932bea0338870165bf1f56f098499b61bacca1a [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);
Steve Anton8d3444d2017-10-20 15:30:51 -070023 return CloneSessionDescriptionAsType(sdesc, sdesc->type());
24}
25
26std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
27 const SessionDescriptionInterface* sdesc,
28 const std::string& type) {
29 RTC_DCHECK(sdesc);
30 auto clone = rtc::MakeUnique<JsepSessionDescription>(type);
Steve Anton97a9f762017-10-06 10:14:03 -070031 clone->Initialize(sdesc->description()->Copy(), sdesc->session_id(),
32 sdesc->session_version());
33 // As of writing, our version of GCC does not allow returning a unique_ptr of
34 // a subclass as a unique_ptr of a base class. To get around this, we need to
35 // std::move the return value.
36 return std::move(clone);
37}
38
39bool SdpContentsAll(SdpContentPredicate pred,
40 const cricket::SessionDescription* desc) {
41 RTC_DCHECK(desc);
42 for (const auto& content : desc->contents()) {
43 const auto* transport_info = desc->GetTransportInfoByName(content.name);
44 if (!pred(&content, transport_info)) {
45 return false;
46 }
47 }
48 return true;
49}
50
51bool SdpContentsNone(SdpContentPredicate pred,
52 const cricket::SessionDescription* desc) {
53 return SdpContentsAll(std::not2(pred), desc);
54}
55
56void SdpContentsForEach(SdpContentMutator fn,
57 cricket::SessionDescription* desc) {
58 RTC_DCHECK(desc);
59 for (auto& content : desc->contents()) {
60 auto* transport_info = desc->GetTransportInfoByName(content.name);
61 fn(&content, transport_info);
62 }
63}
64
65} // namespace webrtc