blob: c959f2a362b1a00197c1351d7832a4b16e2aa058 [file] [log] [blame]
Steve Anton4ab68ee2017-12-19 14:26:11 -08001/*
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 PC_SESSIONDESCRIPTION_H_
12#define PC_SESSIONDESCRIPTION_H_
13
14#include <string>
15#include <vector>
16
17#include "p2p/base/transportinfo.h"
18#include "rtc_base/constructormagic.h"
19
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 {
35 ContentInfo() {}
36 ContentInfo(const std::string& name,
37 const std::string& type,
38 ContentDescription* description)
39 : name(name), type(type), description(description) {}
40 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) {}
45 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) {}
55 std::string name;
56 std::string type;
57 bool rejected = false;
58 bool bundle_only = false;
59 ContentDescription* description = nullptr;
60};
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 ContentGroup(const ContentGroup&);
72 ContentGroup(ContentGroup&&);
73 ContentGroup& operator=(const ContentGroup&);
74 ContentGroup& operator=(ContentGroup&&);
75 ~ContentGroup();
76
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(const ContentInfos& contents,
94 const std::string& name);
95const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
96 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:
103 SessionDescription();
104 explicit SessionDescription(const ContentInfos& contents);
105 SessionDescription(const ContentInfos& contents, const ContentGroups& groups);
106 SessionDescription(const ContentInfos& contents,
107 const TransportInfos& transports,
108 const ContentGroups& groups);
109 ~SessionDescription();
110
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);
133 void AddContent(const std::string& name,
134 const std::string& type,
135 bool rejected,
136 bool bundle_only,
137 ContentDescription* description);
138 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(const std::string& name) const;
144 TransportInfo* GetTransportInfoByName(const std::string& name);
145 const TransportDescription* GetTransportDescriptionByName(
146 const std::string& name) const {
147 const TransportInfo* tinfo = GetTransportInfoByName(name);
148 return tinfo ? &tinfo->description : NULL;
149 }
150
151 // Transport mutators.
152 void set_transport_infos(const TransportInfos& transport_infos) {
153 transport_infos_ = transport_infos;
154 }
155 // Adds a TransportInfo to this description.
156 // Returns false if a TransportInfo with the same name already exists.
157 bool AddTransportInfo(const TransportInfo& transport_info);
158 bool RemoveTransportInfoByName(const std::string& name);
159
160 // Group accessors.
161 const ContentGroups& groups() const { return content_groups_; }
162 const ContentGroup* GetGroupByName(const std::string& name) const;
163 bool HasGroup(const std::string& name) const;
164
165 // Group mutators.
166 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
167 // Remove the first group with the same semantics specified by |name|.
168 void RemoveGroupByName(const std::string& name);
169
170 // Global attributes.
171 void set_msid_supported(bool supported) { msid_supported_ = supported; }
172 bool msid_supported() const { return msid_supported_; }
173
174 private:
175 SessionDescription(const SessionDescription&);
176
177 ContentInfos contents_;
178 TransportInfos transport_infos_;
179 ContentGroups content_groups_;
180 bool msid_supported_ = true;
181};
182
183// Indicates whether a ContentDescription was sent by the local client
184// or received from the remote client.
185enum ContentSource { CS_LOCAL, CS_REMOTE };
186
187} // namespace cricket
188
189#endif // PC_SESSIONDESCRIPTION_H_