Add sdputils.h with useful functions for working with session descriptions
Bug: webrtc:8222 Change-Id: Iedeb65dad493721c5a4eddab254097171dfdb522 Reviewed-on: https://webrtc-review.googlesource.com/7120 Commit-Queue: Steve Anton <steveanton@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20192}
This commit is contained in:
parent
82eb3c4309
commit
97a9f76bce
@ -139,6 +139,8 @@ rtc_static_library("peerconnection") {
|
||||
"rtpsender.h",
|
||||
"sctputils.cc",
|
||||
"sctputils.h",
|
||||
"sdputils.cc",
|
||||
"sdputils.h",
|
||||
"statscollector.cc",
|
||||
"statscollector.h",
|
||||
"streamcollection.h",
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#include "api/jsepsessiondescription.h"
|
||||
#include "media/base/fakevideocapturer.h"
|
||||
#include "pc/sdputils.h"
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "rtc_base/ptr_util.h"
|
||||
|
||||
@ -129,16 +130,6 @@ bool PeerConnectionWrapper::SetSdp(
|
||||
return observer->result();
|
||||
}
|
||||
|
||||
std::unique_ptr<SessionDescriptionInterface>
|
||||
PeerConnectionWrapper::CloneSessionDescription(
|
||||
const SessionDescriptionInterface* desc) {
|
||||
std::unique_ptr<JsepSessionDescription> clone(
|
||||
new JsepSessionDescription(desc->type()));
|
||||
RTC_DCHECK(clone->Initialize(desc->description()->Copy(), desc->session_id(),
|
||||
desc->session_version()));
|
||||
return clone;
|
||||
}
|
||||
|
||||
void PeerConnectionWrapper::AddAudioStream(const std::string& stream_label,
|
||||
const std::string& track_label) {
|
||||
auto stream = pc_factory()->CreateLocalMediaStream(stream_label);
|
||||
|
||||
@ -95,8 +95,6 @@ class PeerConnectionWrapper {
|
||||
std::unique_ptr<SessionDescriptionInterface> CreateSdp(
|
||||
std::function<void(CreateSessionDescriptionObserver*)> fn);
|
||||
bool SetSdp(std::function<void(SetSessionDescriptionObserver*)> fn);
|
||||
std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
|
||||
const SessionDescriptionInterface* desc);
|
||||
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_;
|
||||
rtc::scoped_refptr<PeerConnectionInterface> pc_;
|
||||
|
||||
58
pc/sdputils.cc
Normal file
58
pc/sdputils.cc
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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);
|
||||
auto clone = rtc::MakeUnique<JsepSessionDescription>(sdesc->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
|
||||
54
pc/sdputils.h
Normal file
54
pc/sdputils.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef PC_SDPUTILS_H_
|
||||
#define PC_SDPUTILS_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "api/jsep.h"
|
||||
#include "p2p/base/sessiondescription.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Returns a copy of the given session description.
|
||||
std::unique_ptr<SessionDescriptionInterface> CloneSessionDescription(
|
||||
const SessionDescriptionInterface* sdesc);
|
||||
|
||||
// Function that takes a single session description content with its
|
||||
// corresponding transport and produces a boolean.
|
||||
typedef std::function<bool(const cricket::ContentInfo*,
|
||||
const cricket::TransportInfo*)>
|
||||
SdpContentPredicate;
|
||||
|
||||
// Returns true if the predicate returns true for all contents in the given
|
||||
// session description.
|
||||
bool SdpContentsAll(SdpContentPredicate pred,
|
||||
const cricket::SessionDescription* desc);
|
||||
|
||||
// Returns true if the predicate returns true for none of the contents in the
|
||||
// given session description.
|
||||
bool SdpContentsNone(SdpContentPredicate pred,
|
||||
const cricket::SessionDescription* desc);
|
||||
|
||||
// Function that takes a single session description content with its
|
||||
// corresponding transport and can mutate the content and/or the transport.
|
||||
typedef std::function<void(cricket::ContentInfo*, cricket::TransportInfo*)>
|
||||
SdpContentMutator;
|
||||
|
||||
// Applies the mutator function over all contents in the given session
|
||||
// description.
|
||||
void SdpContentsForEach(SdpContentMutator fn,
|
||||
cricket::SessionDescription* desc);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // PC_SDPUTILS_H_
|
||||
Loading…
x
Reference in New Issue
Block a user