blob: ca61f0013f5163792fd24c4bec4609d6c5fd1b90 [file] [log] [blame]
Steve Anton97a9f762017-10-06 17:14:031/*
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
Steve Anton10542f22019-01-11 17:11:0011#include "pc/sdp_utils.h"
Steve Anton97a9f762017-10-06 17:14:0312
13#include <utility>
Harald Alvestrandc24a2182022-02-23 13:44:5914#include <vector>
Steve Anton97a9f762017-10-06 17:14:0315
Steve Anton10542f22019-01-11 17:11:0016#include "api/jsep_session_description.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0817#include "rtc_base/checks.h"
Steve Anton97a9f762017-10-06 17:14:0318
19namespace webrtc {
20
21std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
22 const SessionDescriptionInterface* sdesc) {
23 RTC_DCHECK(sdesc);
Steve Antona3a92c22017-12-07 18:27:4124 return CloneSessionDescriptionAsType(sdesc, sdesc->GetType());
Steve Anton8d3444d2017-10-20 22:30:5125}
26
27std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
28 const SessionDescriptionInterface* sdesc,
Steve Antona3a92c22017-12-07 18:27:4129 SdpType type) {
Steve Anton8d3444d2017-10-20 22:30:5130 RTC_DCHECK(sdesc);
Mirko Bonadei317a1f02019-09-17 15:06:1831 auto clone = std::make_unique<JsepSessionDescription>(type);
Eldar Rello5ab79e62019-10-09 15:29:4432 if (sdesc->description()) {
33 clone->Initialize(sdesc->description()->Clone(), sdesc->session_id(),
34 sdesc->session_version());
35 }
Steve Anton97a9f762017-10-06 17:14:0336 // As of writing, our version of GCC does not allow returning a unique_ptr of
37 // a subclass as a unique_ptr of a base class. To get around this, we need to
38 // std::move the return value.
39 return std::move(clone);
40}
41
42bool SdpContentsAll(SdpContentPredicate pred,
43 const cricket::SessionDescription* desc) {
44 RTC_DCHECK(desc);
45 for (const auto& content : desc->contents()) {
46 const auto* transport_info = desc->GetTransportInfoByName(content.name);
47 if (!pred(&content, transport_info)) {
48 return false;
49 }
50 }
51 return true;
52}
53
54bool SdpContentsNone(SdpContentPredicate pred,
55 const cricket::SessionDescription* desc) {
tzik4e2d76c2019-03-20 04:43:3356 return SdpContentsAll(
57 [pred](const cricket::ContentInfo* content_info,
58 const cricket::TransportInfo* transport_info) {
59 return !pred(content_info, transport_info);
60 },
61 desc);
Steve Anton97a9f762017-10-06 17:14:0362}
63
64void SdpContentsForEach(SdpContentMutator fn,
65 cricket::SessionDescription* desc) {
66 RTC_DCHECK(desc);
67 for (auto& content : desc->contents()) {
68 auto* transport_info = desc->GetTransportInfoByName(content.name);
69 fn(&content, transport_info);
70 }
71}
72
73} // namespace webrtc