blob: 565722c51991e99cef152448e70452afa8b8a15a [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef P2P_BASE_SESSIONDESCRIPTION_H_
12#define P2P_BASE_SESSIONDESCRIPTION_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
14#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "p2p/base/transportinfo.h"
18#include "rtc_base/constructormagic.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000019
20namespace cricket {
21
22// Describes a session content. Individual content types inherit from
23// this class. Analagous to a <jingle><content><description> or
24// <session><description>.
25class ContentDescription {
26 public:
27 virtual ~ContentDescription() {}
28 virtual ContentDescription* Copy() const = 0;
29};
30
31// Analagous to a <jingle><content> or <session><description>.
32// name = name of <content name="...">
33// type = xmlns of <content>
34struct ContentInfo {
deadbeef25ed4352016-12-12 18:37:36 -080035 ContentInfo() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000036 ContentInfo(const std::string& name,
37 const std::string& type,
deadbeef25ed4352016-12-12 18:37:36 -080038 ContentDescription* description)
39 : name(name), type(type), description(description) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000040 ContentInfo(const std::string& name,
41 const std::string& type,
42 bool rejected,
43 ContentDescription* description) :
44 name(name), type(type), rejected(rejected), description(description) {}
deadbeef25ed4352016-12-12 18:37:36 -080045 ContentInfo(const std::string& name,
46 const std::string& type,
47 bool rejected,
48 bool bundle_only,
49 ContentDescription* description)
50 : name(name),
51 type(type),
52 rejected(rejected),
53 bundle_only(bundle_only),
54 description(description) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000055 std::string name;
56 std::string type;
deadbeef25ed4352016-12-12 18:37:36 -080057 bool rejected = false;
58 bool bundle_only = false;
59 ContentDescription* description = nullptr;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000060};
61
62typedef std::vector<std::string> ContentNames;
63
64// This class provides a mechanism to aggregate different media contents into a
65// group. This group can also be shared with the peers in a pre-defined format.
66// GroupInfo should be populated only with the |content_name| of the
67// MediaDescription.
68class ContentGroup {
69 public:
Steve Antond3ea9992017-10-31 12:38:23 -070070 explicit ContentGroup(const std::string& semantics);
71 ContentGroup(const ContentGroup&);
72 ContentGroup(ContentGroup&&);
73 ContentGroup& operator=(const ContentGroup&);
74 ContentGroup& operator=(ContentGroup&&);
75 ~ContentGroup();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000076
77 const std::string& semantics() const { return semantics_; }
78 const ContentNames& content_names() const { return content_names_; }
79
80 const std::string* FirstContentName() const;
81 bool HasContentName(const std::string& content_name) const;
82 void AddContentName(const std::string& content_name);
83 bool RemoveContentName(const std::string& content_name);
84
85 private:
86 std::string semantics_;
87 ContentNames content_names_;
88};
89
90typedef std::vector<ContentInfo> ContentInfos;
91typedef std::vector<ContentGroup> ContentGroups;
92
93const ContentInfo* FindContentInfoByName(
94 const ContentInfos& contents, const std::string& name);
95const ContentInfo* FindContentInfoByType(
96 const ContentInfos& contents, const std::string& type);
97
98// Describes a collection of contents, each with its own name and
99// type. Analogous to a <jingle> or <session> stanza. Assumes that
100// contents are unique be name, but doesn't enforce that.
101class SessionDescription {
102 public:
Steve Antond3ea9992017-10-31 12:38:23 -0700103 SessionDescription();
104 explicit SessionDescription(const ContentInfos& contents);
105 SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000106 SessionDescription(const ContentInfos& contents,
107 const TransportInfos& transports,
Steve Antond3ea9992017-10-31 12:38:23 -0700108 const ContentGroups& groups);
109 ~SessionDescription();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000110
111 SessionDescription* Copy() const;
112
113 // Content accessors.
114 const ContentInfos& contents() const { return contents_; }
115 ContentInfos& contents() { return contents_; }
116 const ContentInfo* GetContentByName(const std::string& name) const;
117 ContentInfo* GetContentByName(const std::string& name);
118 const ContentDescription* GetContentDescriptionByName(
119 const std::string& name) const;
120 ContentDescription* GetContentDescriptionByName(const std::string& name);
121 const ContentInfo* FirstContentByType(const std::string& type) const;
122 const ContentInfo* FirstContent() const;
123
124 // Content mutators.
125 // Adds a content to this description. Takes ownership of ContentDescription*.
126 void AddContent(const std::string& name,
127 const std::string& type,
128 ContentDescription* description);
129 void AddContent(const std::string& name,
130 const std::string& type,
131 bool rejected,
132 ContentDescription* description);
deadbeef25ed4352016-12-12 18:37:36 -0800133 void AddContent(const std::string& name,
134 const std::string& type,
135 bool rejected,
136 bool bundle_only,
137 ContentDescription* description);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000138 bool RemoveContentByName(const std::string& name);
139
140 // Transport accessors.
141 const TransportInfos& transport_infos() const { return transport_infos_; }
142 TransportInfos& transport_infos() { return transport_infos_; }
143 const TransportInfo* GetTransportInfoByName(
144 const std::string& name) const;
145 TransportInfo* GetTransportInfoByName(const std::string& name);
146 const TransportDescription* GetTransportDescriptionByName(
147 const std::string& name) const {
148 const TransportInfo* tinfo = GetTransportInfoByName(name);
149 return tinfo ? &tinfo->description : NULL;
150 }
151
152 // Transport mutators.
153 void set_transport_infos(const TransportInfos& transport_infos) {
154 transport_infos_ = transport_infos;
155 }
156 // Adds a TransportInfo to this description.
157 // Returns false if a TransportInfo with the same name already exists.
158 bool AddTransportInfo(const TransportInfo& transport_info);
159 bool RemoveTransportInfoByName(const std::string& name);
160
161 // Group accessors.
162 const ContentGroups& groups() const { return content_groups_; }
163 const ContentGroup* GetGroupByName(const std::string& name) const;
164 bool HasGroup(const std::string& name) const;
165
166 // Group mutators.
167 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
168 // Remove the first group with the same semantics specified by |name|.
169 void RemoveGroupByName(const std::string& name);
170
deadbeefc80741f2015-10-22 13:14:45 -0700171 // Global attributes.
172 void set_msid_supported(bool supported) { msid_supported_ = supported; }
173 bool msid_supported() const { return msid_supported_; }
174
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000175 private:
Steve Antond3ea9992017-10-31 12:38:23 -0700176 SessionDescription(const SessionDescription&);
177
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000178 ContentInfos contents_;
179 TransportInfos transport_infos_;
180 ContentGroups content_groups_;
deadbeefc80741f2015-10-22 13:14:45 -0700181 bool msid_supported_ = true;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000182};
183
184// Indicates whether a ContentDescription was an offer or an answer, as
185// described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE
186// indicates a jingle update message which contains a subset of a full
187// session description
188enum ContentAction {
189 CA_OFFER, CA_PRANSWER, CA_ANSWER, CA_UPDATE
190};
191
192// Indicates whether a ContentDescription was sent by the local client
193// or received from the remote client.
194enum ContentSource {
195 CS_LOCAL, CS_REMOTE
196};
197
198} // namespace cricket
199
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200200#endif // P2P_BASE_SESSIONDESCRIPTION_H_