blob: afe9a9acc59ea2771612f02eb27b75bc3597da0a [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2010 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#include "p2p/base/sessiondescription.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000012
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013namespace cricket {
14
15ContentInfo* FindContentInfoByName(
16 ContentInfos& contents, const std::string& name) {
17 for (ContentInfos::iterator content = contents.begin();
18 content != contents.end(); ++content) {
19 if (content->name == name) {
20 return &(*content);
21 }
22 }
23 return NULL;
24}
25
26const ContentInfo* FindContentInfoByName(
27 const ContentInfos& contents, const std::string& name) {
28 for (ContentInfos::const_iterator content = contents.begin();
29 content != contents.end(); ++content) {
30 if (content->name == name) {
31 return &(*content);
32 }
33 }
34 return NULL;
35}
36
37const ContentInfo* FindContentInfoByType(
38 const ContentInfos& contents, const std::string& type) {
39 for (ContentInfos::const_iterator content = contents.begin();
40 content != contents.end(); ++content) {
41 if (content->type == type) {
42 return &(*content);
43 }
44 }
45 return NULL;
46}
47
Steve Antond3ea9992017-10-31 12:38:23 -070048ContentGroup::ContentGroup(const std::string& semantics)
49 : semantics_(semantics) {}
50
51ContentGroup::ContentGroup(const ContentGroup&) = default;
52ContentGroup::ContentGroup(ContentGroup&&) = default;
53ContentGroup& ContentGroup::operator=(const ContentGroup&) = default;
54ContentGroup& ContentGroup::operator=(ContentGroup&&) = default;
55ContentGroup::~ContentGroup() = default;
56
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000057const std::string* ContentGroup::FirstContentName() const {
58 return (!content_names_.empty()) ? &(*content_names_.begin()) : NULL;
59}
60
61bool ContentGroup::HasContentName(const std::string& content_name) const {
62 return (std::find(content_names_.begin(), content_names_.end(),
63 content_name) != content_names_.end());
64}
65
66void ContentGroup::AddContentName(const std::string& content_name) {
67 if (!HasContentName(content_name)) {
68 content_names_.push_back(content_name);
69 }
70}
71
72bool ContentGroup::RemoveContentName(const std::string& content_name) {
73 ContentNames::iterator iter = std::find(
74 content_names_.begin(), content_names_.end(), content_name);
75 if (iter == content_names_.end()) {
76 return false;
77 }
78 content_names_.erase(iter);
79 return true;
80}
81
Steve Antond3ea9992017-10-31 12:38:23 -070082SessionDescription::SessionDescription() = default;
83
84SessionDescription::SessionDescription(const ContentInfos& contents)
85 : contents_(contents) {}
86
87SessionDescription::SessionDescription(const ContentInfos& contents,
88 const ContentGroups& groups)
89 : contents_(contents), content_groups_(groups) {}
90
91SessionDescription::SessionDescription(const ContentInfos& contents,
92 const TransportInfos& transports,
93 const ContentGroups& groups)
94 : contents_(contents),
95 transport_infos_(transports),
96 content_groups_(groups) {}
97
98SessionDescription::SessionDescription(const SessionDescription&) = default;
99
100SessionDescription::~SessionDescription() {
101 for (ContentInfos::iterator content = contents_.begin();
102 content != contents_.end(); ++content) {
103 delete content->description;
104 }
105}
106
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000107SessionDescription* SessionDescription::Copy() const {
108 SessionDescription* copy = new SessionDescription(*this);
109 // Copy all ContentDescriptions.
110 for (ContentInfos::iterator content = copy->contents_.begin();
111 content != copy->contents().end(); ++content) {
112 content->description = content->description->Copy();
113 }
114 return copy;
115}
116
117const ContentInfo* SessionDescription::GetContentByName(
118 const std::string& name) const {
119 return FindContentInfoByName(contents_, name);
120}
121
122ContentInfo* SessionDescription::GetContentByName(
123 const std::string& name) {
124 return FindContentInfoByName(contents_, name);
125}
126
127const ContentDescription* SessionDescription::GetContentDescriptionByName(
128 const std::string& name) const {
129 const ContentInfo* cinfo = FindContentInfoByName(contents_, name);
130 if (cinfo == NULL) {
131 return NULL;
132 }
133
134 return cinfo->description;
135}
136
137ContentDescription* SessionDescription::GetContentDescriptionByName(
138 const std::string& name) {
139 ContentInfo* cinfo = FindContentInfoByName(contents_, name);
140 if (cinfo == NULL) {
141 return NULL;
142 }
143
144 return cinfo->description;
145}
146
147const ContentInfo* SessionDescription::FirstContentByType(
148 const std::string& type) const {
149 return FindContentInfoByType(contents_, type);
150}
151
152const ContentInfo* SessionDescription::FirstContent() const {
153 return (contents_.empty()) ? NULL : &(*contents_.begin());
154}
155
156void SessionDescription::AddContent(const std::string& name,
157 const std::string& type,
158 ContentDescription* description) {
159 contents_.push_back(ContentInfo(name, type, description));
160}
161
162void SessionDescription::AddContent(const std::string& name,
163 const std::string& type,
164 bool rejected,
165 ContentDescription* description) {
166 contents_.push_back(ContentInfo(name, type, rejected, description));
167}
168
deadbeef25ed4352016-12-12 18:37:36 -0800169void SessionDescription::AddContent(const std::string& name,
170 const std::string& type,
171 bool rejected,
172 bool bundle_only,
173 ContentDescription* description) {
174 contents_.push_back(
175 ContentInfo(name, type, rejected, bundle_only, description));
176}
177
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000178bool SessionDescription::RemoveContentByName(const std::string& name) {
179 for (ContentInfos::iterator content = contents_.begin();
180 content != contents_.end(); ++content) {
181 if (content->name == name) {
182 delete content->description;
183 contents_.erase(content);
184 return true;
185 }
186 }
187
188 return false;
189}
190
191bool SessionDescription::AddTransportInfo(const TransportInfo& transport_info) {
192 if (GetTransportInfoByName(transport_info.content_name) != NULL) {
193 return false;
194 }
195 transport_infos_.push_back(transport_info);
196 return true;
197}
198
199bool SessionDescription::RemoveTransportInfoByName(const std::string& name) {
200 for (TransportInfos::iterator transport_info = transport_infos_.begin();
201 transport_info != transport_infos_.end(); ++transport_info) {
202 if (transport_info->content_name == name) {
203 transport_infos_.erase(transport_info);
204 return true;
205 }
206 }
207 return false;
208}
209
210const TransportInfo* SessionDescription::GetTransportInfoByName(
211 const std::string& name) const {
212 for (TransportInfos::const_iterator iter = transport_infos_.begin();
213 iter != transport_infos_.end(); ++iter) {
214 if (iter->content_name == name) {
215 return &(*iter);
216 }
217 }
218 return NULL;
219}
220
221TransportInfo* SessionDescription::GetTransportInfoByName(
222 const std::string& name) {
223 for (TransportInfos::iterator iter = transport_infos_.begin();
224 iter != transport_infos_.end(); ++iter) {
225 if (iter->content_name == name) {
226 return &(*iter);
227 }
228 }
229 return NULL;
230}
231
232void SessionDescription::RemoveGroupByName(const std::string& name) {
233 for (ContentGroups::iterator iter = content_groups_.begin();
234 iter != content_groups_.end(); ++iter) {
235 if (iter->semantics() == name) {
236 content_groups_.erase(iter);
237 break;
238 }
239 }
240}
241
242bool SessionDescription::HasGroup(const std::string& name) const {
243 for (ContentGroups::const_iterator iter = content_groups_.begin();
244 iter != content_groups_.end(); ++iter) {
245 if (iter->semantics() == name) {
246 return true;
247 }
248 }
249 return false;
250}
251
252const ContentGroup* SessionDescription::GetGroupByName(
253 const std::string& name) const {
254 for (ContentGroups::const_iterator iter = content_groups_.begin();
255 iter != content_groups_.end(); ++iter) {
256 if (iter->semantics() == name) {
257 return &(*iter);
258 }
259 }
260 return NULL;
261}
262
263} // namespace cricket