| 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/sdp_utils.h" |
| 12 |
| 13 | #include <utility> |
| 14 | #include <vector> |
| 15 |
| 16 | #include "api/jsep_session_description.h" |
| 17 | #include "rtc_base/checks.h" |
| 18 |
| 19 | namespace webrtc { |
| 20 |
| 21 | std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription( |
| 22 | const SessionDescriptionInterface* sdesc) { |
| 23 | RTC_DCHECK(sdesc); |
| 24 | return CloneSessionDescriptionAsType(sdesc, sdesc->GetType()); |
| 25 | } |
| 26 |
| 27 | std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType( |
| 28 | const SessionDescriptionInterface* sdesc, |
| 29 | SdpType type) { |
| 30 | RTC_DCHECK(sdesc); |
| 31 | auto clone = std::make_unique<JsepSessionDescription>(type); |
| 32 | if (sdesc->description()) { |
| 33 | clone->Initialize(sdesc->description()->Clone(), sdesc->session_id(), |
| 34 | sdesc->session_version()); |
| 35 | } |
| 36 | // 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 |
| 42 | bool 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 |
| 54 | bool SdpContentsNone(SdpContentPredicate pred, |
| 55 | const cricket::SessionDescription* desc) { |
| 56 | 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); |
| 62 | } |
| 63 |
| 64 | void 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 |
| 74 |