blob: df9348d5814af05669ab135f9d6efe55649ff712 [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
11#ifndef WEBRTC_P2P_BASE_SESSIONDESCRIPTION_H_
12#define WEBRTC_P2P_BASE_SESSIONDESCRIPTION_H_
13
14#include <string>
15#include <vector>
16
zhihuang38989e52017-03-21 11:04:53 -070017#include "webrtc/p2p/base/transportinfo.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018#include "webrtc/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:
70 explicit ContentGroup(const std::string& semantics) :
71 semantics_(semantics) {}
72
73 const std::string& semantics() const { return semantics_; }
74 const ContentNames& content_names() const { return content_names_; }
75
76 const std::string* FirstContentName() const;
77 bool HasContentName(const std::string& content_name) const;
78 void AddContentName(const std::string& content_name);
79 bool RemoveContentName(const std::string& content_name);
80
81 private:
82 std::string semantics_;
83 ContentNames content_names_;
84};
85
86typedef std::vector<ContentInfo> ContentInfos;
87typedef std::vector<ContentGroup> ContentGroups;
88
89const ContentInfo* FindContentInfoByName(
90 const ContentInfos& contents, const std::string& name);
91const ContentInfo* FindContentInfoByType(
92 const ContentInfos& contents, const std::string& type);
93
94// Describes a collection of contents, each with its own name and
95// type. Analogous to a <jingle> or <session> stanza. Assumes that
96// contents are unique be name, but doesn't enforce that.
97class SessionDescription {
98 public:
99 SessionDescription() {}
100 explicit SessionDescription(const ContentInfos& contents) :
101 contents_(contents) {}
102 SessionDescription(const ContentInfos& contents,
103 const ContentGroups& groups) :
104 contents_(contents),
105 content_groups_(groups) {}
106 SessionDescription(const ContentInfos& contents,
107 const TransportInfos& transports,
108 const ContentGroups& groups) :
109 contents_(contents),
110 transport_infos_(transports),
111 content_groups_(groups) {}
112 ~SessionDescription() {
113 for (ContentInfos::iterator content = contents_.begin();
114 content != contents_.end(); ++content) {
115 delete content->description;
116 }
117 }
118
119 SessionDescription* Copy() const;
120
121 // Content accessors.
122 const ContentInfos& contents() const { return contents_; }
123 ContentInfos& contents() { return contents_; }
124 const ContentInfo* GetContentByName(const std::string& name) const;
125 ContentInfo* GetContentByName(const std::string& name);
126 const ContentDescription* GetContentDescriptionByName(
127 const std::string& name) const;
128 ContentDescription* GetContentDescriptionByName(const std::string& name);
129 const ContentInfo* FirstContentByType(const std::string& type) const;
130 const ContentInfo* FirstContent() const;
131
132 // Content mutators.
133 // Adds a content to this description. Takes ownership of ContentDescription*.
134 void AddContent(const std::string& name,
135 const std::string& type,
136 ContentDescription* description);
137 void AddContent(const std::string& name,
138 const std::string& type,
139 bool rejected,
140 ContentDescription* description);
deadbeef25ed4352016-12-12 18:37:36 -0800141 void AddContent(const std::string& name,
142 const std::string& type,
143 bool rejected,
144 bool bundle_only,
145 ContentDescription* description);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000146 bool RemoveContentByName(const std::string& name);
147
148 // Transport accessors.
149 const TransportInfos& transport_infos() const { return transport_infos_; }
150 TransportInfos& transport_infos() { return transport_infos_; }
151 const TransportInfo* GetTransportInfoByName(
152 const std::string& name) const;
153 TransportInfo* GetTransportInfoByName(const std::string& name);
154 const TransportDescription* GetTransportDescriptionByName(
155 const std::string& name) const {
156 const TransportInfo* tinfo = GetTransportInfoByName(name);
157 return tinfo ? &tinfo->description : NULL;
158 }
159
160 // Transport mutators.
161 void set_transport_infos(const TransportInfos& transport_infos) {
162 transport_infos_ = transport_infos;
163 }
164 // Adds a TransportInfo to this description.
165 // Returns false if a TransportInfo with the same name already exists.
166 bool AddTransportInfo(const TransportInfo& transport_info);
167 bool RemoveTransportInfoByName(const std::string& name);
168
169 // Group accessors.
170 const ContentGroups& groups() const { return content_groups_; }
171 const ContentGroup* GetGroupByName(const std::string& name) const;
172 bool HasGroup(const std::string& name) const;
173
174 // Group mutators.
175 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
176 // Remove the first group with the same semantics specified by |name|.
177 void RemoveGroupByName(const std::string& name);
178
deadbeefc80741f2015-10-22 13:14:45 -0700179 // Global attributes.
180 void set_msid_supported(bool supported) { msid_supported_ = supported; }
181 bool msid_supported() const { return msid_supported_; }
182
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000183 private:
184 ContentInfos contents_;
185 TransportInfos transport_infos_;
186 ContentGroups content_groups_;
deadbeefc80741f2015-10-22 13:14:45 -0700187 bool msid_supported_ = true;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000188};
189
190// Indicates whether a ContentDescription was an offer or an answer, as
191// described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE
192// indicates a jingle update message which contains a subset of a full
193// session description
194enum ContentAction {
195 CA_OFFER, CA_PRANSWER, CA_ANSWER, CA_UPDATE
196};
197
198// Indicates whether a ContentDescription was sent by the local client
199// or received from the remote client.
200enum ContentSource {
201 CS_LOCAL, CS_REMOTE
202};
203
204} // namespace cricket
205
206#endif // WEBRTC_P2P_BASE_SESSIONDESCRIPTION_H_