Move sessiondescription.h/cc from p2p/base to pc/

SDP is a detail of PeerConnection and is not used by anything in p2p, so
it belongs in the pc/ directory. This also allows
MediaContentDescription to be inlined in the future.

Bug: webrtc:8620
Change-Id: I38b65ede9942e29eb15035ab29f2be988da1e5ce
Reviewed-on: https://webrtc-review.googlesource.com/33781
Reviewed-by: Niklas Enbom <niklas.enbom@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21376}
This commit is contained in:
Steve Anton 2017-12-19 14:26:11 -08:00 committed by Commit Bot
parent 36193c3756
commit 4ab68eec96
15 changed files with 230 additions and 207 deletions

View file

@ -32,7 +32,6 @@ CPPLINT_BLACKLIST = [
'modules/media_file', 'modules/media_file',
'modules/utility', 'modules/utility',
'modules/video_capture', 'modules/video_capture',
'p2p/base/sessiondescription.cc',
'p2p/base/session.cc', 'p2p/base/session.cc',
'p2p/base/session.h', 'p2p/base/session.h',
'p2p/base/pseudotcp.cc', 'p2p/base/pseudotcp.cc',

View file

@ -27,7 +27,6 @@
#include "media/base/streamparams.h" #include "media/base/streamparams.h"
#include "media/engine/webrtcvideoengine.h" #include "media/engine/webrtcvideoengine.h"
#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/include/audio_processing.h"
#include "p2p/base/sessiondescription.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/copyonwritebuffer.h" #include "rtc_base/copyonwritebuffer.h"
#include "rtc_base/networkroute.h" #include "rtc_base/networkroute.h"

View file

@ -57,8 +57,6 @@ rtc_static_library("rtc_p2p") {
"base/relayport.h", "base/relayport.h",
"base/session.cc", "base/session.cc",
"base/session.h", "base/session.h",
"base/sessiondescription.cc",
"base/sessiondescription.h",
"base/stun.cc", "base/stun.cc",
"base/stun.h", "base/stun.h",
"base/stunport.cc", "base/stunport.cc",

View file

@ -2,3 +2,11 @@ include_rules = [
"+net", "+net",
"+system_wrappers", "+system_wrappers",
] ]
specific_include_rules = {
# TODO(steveanton): Remove this forwarding header once downstream projects
# have updated to include the file in its new location.
"sessiondescription\.h": [
"+pc/sessiondescription.h",
],
}

View file

@ -11,182 +11,8 @@
#ifndef P2P_BASE_SESSIONDESCRIPTION_H_ #ifndef P2P_BASE_SESSIONDESCRIPTION_H_
#define P2P_BASE_SESSIONDESCRIPTION_H_ #define P2P_BASE_SESSIONDESCRIPTION_H_
#include <string> // TODO(steveanton): Remove this forwarding header once downstream projects
#include <vector> // have updated to include the file in its new location.
#include "pc/sessiondescription.h"
#include "p2p/base/transportinfo.h"
#include "rtc_base/constructormagic.h"
namespace cricket {
// Describes a session content. Individual content types inherit from
// this class. Analagous to a <jingle><content><description> or
// <session><description>.
class ContentDescription {
public:
virtual ~ContentDescription() {}
virtual ContentDescription* Copy() const = 0;
};
// Analagous to a <jingle><content> or <session><description>.
// name = name of <content name="...">
// type = xmlns of <content>
struct ContentInfo {
ContentInfo() {}
ContentInfo(const std::string& name,
const std::string& type,
ContentDescription* description)
: name(name), type(type), description(description) {}
ContentInfo(const std::string& name,
const std::string& type,
bool rejected,
ContentDescription* description) :
name(name), type(type), rejected(rejected), description(description) {}
ContentInfo(const std::string& name,
const std::string& type,
bool rejected,
bool bundle_only,
ContentDescription* description)
: name(name),
type(type),
rejected(rejected),
bundle_only(bundle_only),
description(description) {}
std::string name;
std::string type;
bool rejected = false;
bool bundle_only = false;
ContentDescription* description = nullptr;
};
typedef std::vector<std::string> ContentNames;
// This class provides a mechanism to aggregate different media contents into a
// group. This group can also be shared with the peers in a pre-defined format.
// GroupInfo should be populated only with the |content_name| of the
// MediaDescription.
class ContentGroup {
public:
explicit ContentGroup(const std::string& semantics);
ContentGroup(const ContentGroup&);
ContentGroup(ContentGroup&&);
ContentGroup& operator=(const ContentGroup&);
ContentGroup& operator=(ContentGroup&&);
~ContentGroup();
const std::string& semantics() const { return semantics_; }
const ContentNames& content_names() const { return content_names_; }
const std::string* FirstContentName() const;
bool HasContentName(const std::string& content_name) const;
void AddContentName(const std::string& content_name);
bool RemoveContentName(const std::string& content_name);
private:
std::string semantics_;
ContentNames content_names_;
};
typedef std::vector<ContentInfo> ContentInfos;
typedef std::vector<ContentGroup> ContentGroups;
const ContentInfo* FindContentInfoByName(
const ContentInfos& contents, const std::string& name);
const ContentInfo* FindContentInfoByType(
const ContentInfos& contents, const std::string& type);
// Describes a collection of contents, each with its own name and
// type. Analogous to a <jingle> or <session> stanza. Assumes that
// contents are unique be name, but doesn't enforce that.
class SessionDescription {
public:
SessionDescription();
explicit SessionDescription(const ContentInfos& contents);
SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
SessionDescription(const ContentInfos& contents,
const TransportInfos& transports,
const ContentGroups& groups);
~SessionDescription();
SessionDescription* Copy() const;
// Content accessors.
const ContentInfos& contents() const { return contents_; }
ContentInfos& contents() { return contents_; }
const ContentInfo* GetContentByName(const std::string& name) const;
ContentInfo* GetContentByName(const std::string& name);
const ContentDescription* GetContentDescriptionByName(
const std::string& name) const;
ContentDescription* GetContentDescriptionByName(const std::string& name);
const ContentInfo* FirstContentByType(const std::string& type) const;
const ContentInfo* FirstContent() const;
// Content mutators.
// Adds a content to this description. Takes ownership of ContentDescription*.
void AddContent(const std::string& name,
const std::string& type,
ContentDescription* description);
void AddContent(const std::string& name,
const std::string& type,
bool rejected,
ContentDescription* description);
void AddContent(const std::string& name,
const std::string& type,
bool rejected,
bool bundle_only,
ContentDescription* description);
bool RemoveContentByName(const std::string& name);
// Transport accessors.
const TransportInfos& transport_infos() const { return transport_infos_; }
TransportInfos& transport_infos() { return transport_infos_; }
const TransportInfo* GetTransportInfoByName(
const std::string& name) const;
TransportInfo* GetTransportInfoByName(const std::string& name);
const TransportDescription* GetTransportDescriptionByName(
const std::string& name) const {
const TransportInfo* tinfo = GetTransportInfoByName(name);
return tinfo ? &tinfo->description : NULL;
}
// Transport mutators.
void set_transport_infos(const TransportInfos& transport_infos) {
transport_infos_ = transport_infos;
}
// Adds a TransportInfo to this description.
// Returns false if a TransportInfo with the same name already exists.
bool AddTransportInfo(const TransportInfo& transport_info);
bool RemoveTransportInfoByName(const std::string& name);
// Group accessors.
const ContentGroups& groups() const { return content_groups_; }
const ContentGroup* GetGroupByName(const std::string& name) const;
bool HasGroup(const std::string& name) const;
// Group mutators.
void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
// Remove the first group with the same semantics specified by |name|.
void RemoveGroupByName(const std::string& name);
// Global attributes.
void set_msid_supported(bool supported) { msid_supported_ = supported; }
bool msid_supported() const { return msid_supported_; }
private:
SessionDescription(const SessionDescription&);
ContentInfos contents_;
TransportInfos transport_infos_;
ContentGroups content_groups_;
bool msid_supported_ = true;
};
// Indicates whether a ContentDescription was sent by the local client
// or received from the remote client.
enum ContentSource {
CS_LOCAL, CS_REMOTE
};
} // namespace cricket
#endif // P2P_BASE_SESSIONDESCRIPTION_H_ #endif // P2P_BASE_SESSIONDESCRIPTION_H_

View file

@ -56,6 +56,8 @@ rtc_static_library("rtc_pc_base") {
"rtptransport.h", "rtptransport.h",
"rtptransportinternal.h", "rtptransportinternal.h",
"rtptransportinternaladapter.h", "rtptransportinternaladapter.h",
"sessiondescription.cc",
"sessiondescription.h",
"srtpfilter.cc", "srtpfilter.cc",
"srtpfilter.h", "srtpfilter.h",
"srtpsession.cc", "srtpsession.cc",

View file

@ -16,8 +16,8 @@
#include "api/jsepsessiondescription.h" #include "api/jsepsessiondescription.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/port.h" #include "p2p/base/port.h"
#include "p2p/base/sessiondescription.h"
#include "pc/mediasession.h" #include "pc/mediasession.h"
#include "pc/sessiondescription.h"
#include "pc/webrtcsdp.h" #include "pc/webrtcsdp.h"
#include "rtc_base/gunit.h" #include "rtc_base/gunit.h"
#include "rtc_base/ptr_util.h" #include "rtc_base/ptr_util.h"

View file

@ -21,8 +21,8 @@
#include "api/optional.h" #include "api/optional.h"
#include "p2p/base/dtlstransport.h" #include "p2p/base/dtlstransport.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/sessiondescription.h"
#include "p2p/base/transportinfo.h" #include "p2p/base/transportinfo.h"
#include "pc/sessiondescription.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"
#include "rtc_base/messagequeue.h" #include "rtc_base/messagequeue.h"
#include "rtc_base/rtccertificate.h" #include "rtc_base/rtccertificate.h"

View file

@ -26,9 +26,9 @@
#include "media/base/mediaconstants.h" #include "media/base/mediaconstants.h"
#include "media/base/mediaengine.h" // For DataChannelType #include "media/base/mediaengine.h" // For DataChannelType
#include "media/base/streamparams.h" #include "media/base/streamparams.h"
#include "p2p/base/sessiondescription.h"
#include "p2p/base/transportdescriptionfactory.h" #include "p2p/base/transportdescriptionfactory.h"
#include "pc/jseptransport.h" #include "pc/jseptransport.h"
#include "pc/sessiondescription.h"
namespace cricket { namespace cricket {

View file

@ -33,7 +33,6 @@
#include "media/engine/fakewebrtcvideoengine.h" #include "media/engine/fakewebrtcvideoengine.h"
#include "p2p/base/p2pconstants.h" #include "p2p/base/p2pconstants.h"
#include "p2p/base/portinterface.h" #include "p2p/base/portinterface.h"
#include "p2p/base/sessiondescription.h"
#include "p2p/base/teststunserver.h" #include "p2p/base/teststunserver.h"
#include "p2p/base/testturncustomizer.h" #include "p2p/base/testturncustomizer.h"
#include "p2p/base/testturnserver.h" #include "p2p/base/testturnserver.h"
@ -43,6 +42,7 @@
#include "pc/mediasession.h" #include "pc/mediasession.h"
#include "pc/peerconnection.h" #include "pc/peerconnection.h"
#include "pc/peerconnectionfactory.h" #include "pc/peerconnectionfactory.h"
#include "pc/sessiondescription.h"
#include "pc/test/fakeaudiocapturemodule.h" #include "pc/test/fakeaudiocapturemodule.h"
#include "pc/test/fakeperiodicvideocapturer.h" #include "pc/test/fakeperiodicvideocapturer.h"
#include "pc/test/fakertccertificategenerator.h" #include "pc/test/fakertccertificategenerator.h"

View file

@ -11,7 +11,7 @@
#ifndef PC_RTCPMUXFILTER_H_ #ifndef PC_RTCPMUXFILTER_H_
#define PC_RTCPMUXFILTER_H_ #define PC_RTCPMUXFILTER_H_
#include "p2p/base/sessiondescription.h" #include "pc/sessiondescription.h"
namespace cricket { namespace cricket {

View file

@ -16,7 +16,7 @@
#include <string> #include <string>
#include "api/jsep.h" #include "api/jsep.h"
#include "p2p/base/sessiondescription.h" #include "pc/sessiondescription.h"
namespace webrtc { namespace webrtc {

View file

@ -8,23 +8,26 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "p2p/base/sessiondescription.h" #include "pc/sessiondescription.h"
namespace cricket { namespace cricket {
namespace {
ContentInfo* FindContentInfoByName( ContentInfo* FindContentInfoByName(ContentInfos* contents,
ContentInfos& contents, const std::string& name) { const std::string& name) {
for (ContentInfos::iterator content = contents.begin(); RTC_DCHECK(contents);
content != contents.end(); ++content) { for (ContentInfo& content : *contents) {
if (content->name == name) { if (content.name == name) {
return &(*content); return &content;
} }
} }
return NULL; return nullptr;
} }
const ContentInfo* FindContentInfoByName( } // namespace
const ContentInfos& contents, const std::string& name) {
const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
const std::string& name) {
for (ContentInfos::const_iterator content = contents.begin(); for (ContentInfos::const_iterator content = contents.begin();
content != contents.end(); ++content) { content != contents.end(); ++content) {
if (content->name == name) { if (content->name == name) {
@ -34,8 +37,8 @@ const ContentInfo* FindContentInfoByName(
return NULL; return NULL;
} }
const ContentInfo* FindContentInfoByType( const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
const ContentInfos& contents, const std::string& type) { const std::string& type) {
for (ContentInfos::const_iterator content = contents.begin(); for (ContentInfos::const_iterator content = contents.begin();
content != contents.end(); ++content) { content != contents.end(); ++content) {
if (content->type == type) { if (content->type == type) {
@ -70,8 +73,8 @@ void ContentGroup::AddContentName(const std::string& content_name) {
} }
bool ContentGroup::RemoveContentName(const std::string& content_name) { bool ContentGroup::RemoveContentName(const std::string& content_name) {
ContentNames::iterator iter = std::find( ContentNames::iterator iter =
content_names_.begin(), content_names_.end(), content_name); std::find(content_names_.begin(), content_names_.end(), content_name);
if (iter == content_names_.end()) { if (iter == content_names_.end()) {
return false; return false;
} }
@ -119,9 +122,8 @@ const ContentInfo* SessionDescription::GetContentByName(
return FindContentInfoByName(contents_, name); return FindContentInfoByName(contents_, name);
} }
ContentInfo* SessionDescription::GetContentByName( ContentInfo* SessionDescription::GetContentByName(const std::string& name) {
const std::string& name) { return FindContentInfoByName(&contents_, name);
return FindContentInfoByName(contents_, name);
} }
const ContentDescription* SessionDescription::GetContentDescriptionByName( const ContentDescription* SessionDescription::GetContentDescriptionByName(
@ -136,7 +138,7 @@ const ContentDescription* SessionDescription::GetContentDescriptionByName(
ContentDescription* SessionDescription::GetContentDescriptionByName( ContentDescription* SessionDescription::GetContentDescriptionByName(
const std::string& name) { const std::string& name) {
ContentInfo* cinfo = FindContentInfoByName(contents_, name); ContentInfo* cinfo = FindContentInfoByName(&contents_, name);
if (cinfo == NULL) { if (cinfo == NULL) {
return NULL; return NULL;
} }

189
pc/sessiondescription.h Normal file
View file

@ -0,0 +1,189 @@
/*
* Copyright 2004 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_SESSIONDESCRIPTION_H_
#define PC_SESSIONDESCRIPTION_H_
#include <string>
#include <vector>
#include "p2p/base/transportinfo.h"
#include "rtc_base/constructormagic.h"
namespace cricket {
// Describes a session content. Individual content types inherit from
// this class. Analagous to a <jingle><content><description> or
// <session><description>.
class ContentDescription {
public:
virtual ~ContentDescription() {}
virtual ContentDescription* Copy() const = 0;
};
// Analagous to a <jingle><content> or <session><description>.
// name = name of <content name="...">
// type = xmlns of <content>
struct ContentInfo {
ContentInfo() {}
ContentInfo(const std::string& name,
const std::string& type,
ContentDescription* description)
: name(name), type(type), description(description) {}
ContentInfo(const std::string& name,
const std::string& type,
bool rejected,
ContentDescription* description)
: name(name), type(type), rejected(rejected), description(description) {}
ContentInfo(const std::string& name,
const std::string& type,
bool rejected,
bool bundle_only,
ContentDescription* description)
: name(name),
type(type),
rejected(rejected),
bundle_only(bundle_only),
description(description) {}
std::string name;
std::string type;
bool rejected = false;
bool bundle_only = false;
ContentDescription* description = nullptr;
};
typedef std::vector<std::string> ContentNames;
// This class provides a mechanism to aggregate different media contents into a
// group. This group can also be shared with the peers in a pre-defined format.
// GroupInfo should be populated only with the |content_name| of the
// MediaDescription.
class ContentGroup {
public:
explicit ContentGroup(const std::string& semantics);
ContentGroup(const ContentGroup&);
ContentGroup(ContentGroup&&);
ContentGroup& operator=(const ContentGroup&);
ContentGroup& operator=(ContentGroup&&);
~ContentGroup();
const std::string& semantics() const { return semantics_; }
const ContentNames& content_names() const { return content_names_; }
const std::string* FirstContentName() const;
bool HasContentName(const std::string& content_name) const;
void AddContentName(const std::string& content_name);
bool RemoveContentName(const std::string& content_name);
private:
std::string semantics_;
ContentNames content_names_;
};
typedef std::vector<ContentInfo> ContentInfos;
typedef std::vector<ContentGroup> ContentGroups;
const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
const std::string& name);
const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
const std::string& type);
// Describes a collection of contents, each with its own name and
// type. Analogous to a <jingle> or <session> stanza. Assumes that
// contents are unique be name, but doesn't enforce that.
class SessionDescription {
public:
SessionDescription();
explicit SessionDescription(const ContentInfos& contents);
SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
SessionDescription(const ContentInfos& contents,
const TransportInfos& transports,
const ContentGroups& groups);
~SessionDescription();
SessionDescription* Copy() const;
// Content accessors.
const ContentInfos& contents() const { return contents_; }
ContentInfos& contents() { return contents_; }
const ContentInfo* GetContentByName(const std::string& name) const;
ContentInfo* GetContentByName(const std::string& name);
const ContentDescription* GetContentDescriptionByName(
const std::string& name) const;
ContentDescription* GetContentDescriptionByName(const std::string& name);
const ContentInfo* FirstContentByType(const std::string& type) const;
const ContentInfo* FirstContent() const;
// Content mutators.
// Adds a content to this description. Takes ownership of ContentDescription*.
void AddContent(const std::string& name,
const std::string& type,
ContentDescription* description);
void AddContent(const std::string& name,
const std::string& type,
bool rejected,
ContentDescription* description);
void AddContent(const std::string& name,
const std::string& type,
bool rejected,
bool bundle_only,
ContentDescription* description);
bool RemoveContentByName(const std::string& name);
// Transport accessors.
const TransportInfos& transport_infos() const { return transport_infos_; }
TransportInfos& transport_infos() { return transport_infos_; }
const TransportInfo* GetTransportInfoByName(const std::string& name) const;
TransportInfo* GetTransportInfoByName(const std::string& name);
const TransportDescription* GetTransportDescriptionByName(
const std::string& name) const {
const TransportInfo* tinfo = GetTransportInfoByName(name);
return tinfo ? &tinfo->description : NULL;
}
// Transport mutators.
void set_transport_infos(const TransportInfos& transport_infos) {
transport_infos_ = transport_infos;
}
// Adds a TransportInfo to this description.
// Returns false if a TransportInfo with the same name already exists.
bool AddTransportInfo(const TransportInfo& transport_info);
bool RemoveTransportInfoByName(const std::string& name);
// Group accessors.
const ContentGroups& groups() const { return content_groups_; }
const ContentGroup* GetGroupByName(const std::string& name) const;
bool HasGroup(const std::string& name) const;
// Group mutators.
void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
// Remove the first group with the same semantics specified by |name|.
void RemoveGroupByName(const std::string& name);
// Global attributes.
void set_msid_supported(bool supported) { msid_supported_ = supported; }
bool msid_supported() const { return msid_supported_; }
private:
SessionDescription(const SessionDescription&);
ContentInfos contents_;
TransportInfos transport_infos_;
ContentGroups content_groups_;
bool msid_supported_ = true;
};
// Indicates whether a ContentDescription was sent by the local client
// or received from the remote client.
enum ContentSource { CS_LOCAL, CS_REMOTE };
} // namespace cricket
#endif // PC_SESSIONDESCRIPTION_H_

View file

@ -19,7 +19,7 @@
#include "api/cryptoparams.h" #include "api/cryptoparams.h"
#include "api/optional.h" #include "api/optional.h"
#include "p2p/base/sessiondescription.h" #include "pc/sessiondescription.h"
#include "rtc_base/basictypes.h" #include "rtc_base/basictypes.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/constructormagic.h" #include "rtc_base/constructormagic.h"