blob: 07bff7bca2f09203dddb8df55f7a2f2abbb0d4d2 [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
Steve Anton36b29d12017-10-30 09:57:42 -070013#include <string>
Steve Anton97a9f762017-10-06 10:14:03 -070014#include <utility>
15
Karl Wiberg918f50c2018-07-05 11:40:33 +020016#include "absl/memory/memory.h"
Steve Anton97a9f762017-10-06 10:14:03 -070017#include "api/jsepsessiondescription.h"
Steve Anton97a9f762017-10-06 10:14:03 -070018
19namespace webrtc {
20
21std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
22 const SessionDescriptionInterface* sdesc) {
23 RTC_DCHECK(sdesc);
Steve Antona3a92c22017-12-07 10:27:41 -080024 return CloneSessionDescriptionAsType(sdesc, sdesc->GetType());
Steve Anton8d3444d2017-10-20 15:30:51 -070025}
26
27std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
28 const SessionDescriptionInterface* sdesc,
Steve Antona3a92c22017-12-07 10:27:41 -080029 SdpType type) {
Steve Anton8d3444d2017-10-20 15:30:51 -070030 RTC_DCHECK(sdesc);
Karl Wiberg918f50c2018-07-05 11:40:33 +020031 auto clone = absl::make_unique<JsepSessionDescription>(type);
Steve Anton97a9f762017-10-06 10:14:03 -070032 clone->Initialize(sdesc->description()->Copy(), sdesc->session_id(),
Steve Antona3a92c22017-12-07 10:27:41 -080033 sdesc->session_version());
Steve Anton97a9f762017-10-06 10:14:03 -070034 // 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
40bool 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
52bool SdpContentsNone(SdpContentPredicate pred,
53 const cricket::SessionDescription* desc) {
54 return SdpContentsAll(std::not2(pred), desc);
55}
56
57void 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