webrtc_m130/pc/sdputils.cc
Steve Anton 8d3444df2d Reland "Rewrite WebRtcSession media tests as PeerConnection tests"
This is a reland of 3df5dcac9b339ba4d3f4969602f094c2c8035b51
Original change's description:
> Rewrite WebRtcSession media tests as PeerConnection tests
> 
> Bug: webrtc:8222
> Change-Id: I782a3227e30de70eb8f6c26a48723cb3510a84ad
> Reviewed-on: https://webrtc-review.googlesource.com/6640
> Commit-Queue: Steve Anton <steveanton@webrtc.org>
> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20364}

Bug: webrtc:8222
Change-Id: I0a5398170d469eb9223bc781bfb417a85a72a2d2
Reviewed-on: https://webrtc-review.googlesource.com/14380
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20377}
2017-10-21 01:38:14 +00:00

66 lines
2.1 KiB
C++

/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "pc/sdputils.h"
#include <utility>
#include "api/jsepsessiondescription.h"
#include "rtc_base/ptr_util.h"
namespace webrtc {
std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
const SessionDescriptionInterface* sdesc) {
RTC_DCHECK(sdesc);
return CloneSessionDescriptionAsType(sdesc, sdesc->type());
}
std::unique_ptr<SessionDescriptionInterface> CloneSessionDescriptionAsType(
const SessionDescriptionInterface* sdesc,
const std::string& type) {
RTC_DCHECK(sdesc);
auto clone = rtc::MakeUnique<JsepSessionDescription>(type);
clone->Initialize(sdesc->description()->Copy(), sdesc->session_id(),
sdesc->session_version());
// As of writing, our version of GCC does not allow returning a unique_ptr of
// a subclass as a unique_ptr of a base class. To get around this, we need to
// std::move the return value.
return std::move(clone);
}
bool SdpContentsAll(SdpContentPredicate pred,
const cricket::SessionDescription* desc) {
RTC_DCHECK(desc);
for (const auto& content : desc->contents()) {
const auto* transport_info = desc->GetTransportInfoByName(content.name);
if (!pred(&content, transport_info)) {
return false;
}
}
return true;
}
bool SdpContentsNone(SdpContentPredicate pred,
const cricket::SessionDescription* desc) {
return SdpContentsAll(std::not2(pred), desc);
}
void SdpContentsForEach(SdpContentMutator fn,
cricket::SessionDescription* desc) {
RTC_DCHECK(desc);
for (auto& content : desc->contents()) {
auto* transport_info = desc->GetTransportInfoByName(content.name);
fn(&content, transport_info);
}
}
} // namespace webrtc