xref: /aosp_15_r20/external/webrtc/pc/sdp_utils.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2017 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #include "pc/sdp_utils.h"
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include <utility>
14*d9f75844SAndroid Build Coastguard Worker #include <vector>
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #include "api/jsep_session_description.h"
17*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h"
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
20*d9f75844SAndroid Build Coastguard Worker 
CloneSessionDescription(const SessionDescriptionInterface * sdesc)21*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
22*d9f75844SAndroid Build Coastguard Worker     const SessionDescriptionInterface* sdesc) {
23*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK(sdesc);
24*d9f75844SAndroid Build Coastguard Worker   return CloneSessionDescriptionAsType(sdesc, sdesc->GetType());
25*d9f75844SAndroid Build Coastguard Worker }
26*d9f75844SAndroid Build Coastguard Worker 
CloneSessionDescriptionAsType(const SessionDescriptionInterface * sdesc,SdpType type)27*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
28*d9f75844SAndroid Build Coastguard Worker     const SessionDescriptionInterface* sdesc,
29*d9f75844SAndroid Build Coastguard Worker     SdpType type) {
30*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK(sdesc);
31*d9f75844SAndroid Build Coastguard Worker   auto clone = std::make_unique<JsepSessionDescription>(type);
32*d9f75844SAndroid Build Coastguard Worker   if (sdesc->description()) {
33*d9f75844SAndroid Build Coastguard Worker     clone->Initialize(sdesc->description()->Clone(), sdesc->session_id(),
34*d9f75844SAndroid Build Coastguard Worker                       sdesc->session_version());
35*d9f75844SAndroid Build Coastguard Worker   }
36*d9f75844SAndroid Build Coastguard Worker   // As of writing, our version of GCC does not allow returning a unique_ptr of
37*d9f75844SAndroid Build Coastguard Worker   // a subclass as a unique_ptr of a base class. To get around this, we need to
38*d9f75844SAndroid Build Coastguard Worker   // std::move the return value.
39*d9f75844SAndroid Build Coastguard Worker   return std::move(clone);
40*d9f75844SAndroid Build Coastguard Worker }
41*d9f75844SAndroid Build Coastguard Worker 
SdpContentsAll(SdpContentPredicate pred,const cricket::SessionDescription * desc)42*d9f75844SAndroid Build Coastguard Worker bool SdpContentsAll(SdpContentPredicate pred,
43*d9f75844SAndroid Build Coastguard Worker                     const cricket::SessionDescription* desc) {
44*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK(desc);
45*d9f75844SAndroid Build Coastguard Worker   for (const auto& content : desc->contents()) {
46*d9f75844SAndroid Build Coastguard Worker     const auto* transport_info = desc->GetTransportInfoByName(content.name);
47*d9f75844SAndroid Build Coastguard Worker     if (!pred(&content, transport_info)) {
48*d9f75844SAndroid Build Coastguard Worker       return false;
49*d9f75844SAndroid Build Coastguard Worker     }
50*d9f75844SAndroid Build Coastguard Worker   }
51*d9f75844SAndroid Build Coastguard Worker   return true;
52*d9f75844SAndroid Build Coastguard Worker }
53*d9f75844SAndroid Build Coastguard Worker 
SdpContentsNone(SdpContentPredicate pred,const cricket::SessionDescription * desc)54*d9f75844SAndroid Build Coastguard Worker bool SdpContentsNone(SdpContentPredicate pred,
55*d9f75844SAndroid Build Coastguard Worker                      const cricket::SessionDescription* desc) {
56*d9f75844SAndroid Build Coastguard Worker   return SdpContentsAll(
57*d9f75844SAndroid Build Coastguard Worker       [pred](const cricket::ContentInfo* content_info,
58*d9f75844SAndroid Build Coastguard Worker              const cricket::TransportInfo* transport_info) {
59*d9f75844SAndroid Build Coastguard Worker         return !pred(content_info, transport_info);
60*d9f75844SAndroid Build Coastguard Worker       },
61*d9f75844SAndroid Build Coastguard Worker       desc);
62*d9f75844SAndroid Build Coastguard Worker }
63*d9f75844SAndroid Build Coastguard Worker 
SdpContentsForEach(SdpContentMutator fn,cricket::SessionDescription * desc)64*d9f75844SAndroid Build Coastguard Worker void SdpContentsForEach(SdpContentMutator fn,
65*d9f75844SAndroid Build Coastguard Worker                         cricket::SessionDescription* desc) {
66*d9f75844SAndroid Build Coastguard Worker   RTC_DCHECK(desc);
67*d9f75844SAndroid Build Coastguard Worker   for (auto& content : desc->contents()) {
68*d9f75844SAndroid Build Coastguard Worker     auto* transport_info = desc->GetTransportInfoByName(content.name);
69*d9f75844SAndroid Build Coastguard Worker     fn(&content, transport_info);
70*d9f75844SAndroid Build Coastguard Worker   }
71*d9f75844SAndroid Build Coastguard Worker }
72*d9f75844SAndroid Build Coastguard Worker 
73*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
74