blob: 1182a67740a725f0a3f62711dcb8c9a7f846c7ab [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
17#include "webrtc/p2p/base/transportinfo.h"
18#include "webrtc/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() : description(NULL) {}
36 ContentInfo(const std::string& name,
37 const std::string& type,
38 ContentDescription* description) :
39 name(name), type(type), rejected(false), 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 std::string name;
46 std::string type;
47 bool rejected;
48 ContentDescription* description;
49};
50
51typedef std::vector<std::string> ContentNames;
52
53// This class provides a mechanism to aggregate different media contents into a
54// group. This group can also be shared with the peers in a pre-defined format.
55// GroupInfo should be populated only with the |content_name| of the
56// MediaDescription.
57class ContentGroup {
58 public:
59 explicit ContentGroup(const std::string& semantics) :
60 semantics_(semantics) {}
61
62 const std::string& semantics() const { return semantics_; }
63 const ContentNames& content_names() const { return content_names_; }
64
65 const std::string* FirstContentName() const;
66 bool HasContentName(const std::string& content_name) const;
67 void AddContentName(const std::string& content_name);
68 bool RemoveContentName(const std::string& content_name);
69
70 private:
71 std::string semantics_;
72 ContentNames content_names_;
73};
74
75typedef std::vector<ContentInfo> ContentInfos;
76typedef std::vector<ContentGroup> ContentGroups;
77
78const ContentInfo* FindContentInfoByName(
79 const ContentInfos& contents, const std::string& name);
80const ContentInfo* FindContentInfoByType(
81 const ContentInfos& contents, const std::string& type);
82
83// Describes a collection of contents, each with its own name and
84// type. Analogous to a <jingle> or <session> stanza. Assumes that
85// contents are unique be name, but doesn't enforce that.
86class SessionDescription {
87 public:
88 SessionDescription() {}
89 explicit SessionDescription(const ContentInfos& contents) :
90 contents_(contents) {}
91 SessionDescription(const ContentInfos& contents,
92 const ContentGroups& groups) :
93 contents_(contents),
94 content_groups_(groups) {}
95 SessionDescription(const ContentInfos& contents,
96 const TransportInfos& transports,
97 const ContentGroups& groups) :
98 contents_(contents),
99 transport_infos_(transports),
100 content_groups_(groups) {}
101 ~SessionDescription() {
102 for (ContentInfos::iterator content = contents_.begin();
103 content != contents_.end(); ++content) {
104 delete content->description;
105 }
106 }
107
108 SessionDescription* Copy() const;
109
110 // Content accessors.
111 const ContentInfos& contents() const { return contents_; }
112 ContentInfos& contents() { return contents_; }
113 const ContentInfo* GetContentByName(const std::string& name) const;
114 ContentInfo* GetContentByName(const std::string& name);
115 const ContentDescription* GetContentDescriptionByName(
116 const std::string& name) const;
117 ContentDescription* GetContentDescriptionByName(const std::string& name);
118 const ContentInfo* FirstContentByType(const std::string& type) const;
119 const ContentInfo* FirstContent() const;
120
121 // Content mutators.
122 // Adds a content to this description. Takes ownership of ContentDescription*.
123 void AddContent(const std::string& name,
124 const std::string& type,
125 ContentDescription* description);
126 void AddContent(const std::string& name,
127 const std::string& type,
128 bool rejected,
129 ContentDescription* description);
130 bool RemoveContentByName(const std::string& name);
131
132 // Transport accessors.
133 const TransportInfos& transport_infos() const { return transport_infos_; }
134 TransportInfos& transport_infos() { return transport_infos_; }
135 const TransportInfo* GetTransportInfoByName(
136 const std::string& name) const;
137 TransportInfo* GetTransportInfoByName(const std::string& name);
138 const TransportDescription* GetTransportDescriptionByName(
139 const std::string& name) const {
140 const TransportInfo* tinfo = GetTransportInfoByName(name);
141 return tinfo ? &tinfo->description : NULL;
142 }
143
144 // Transport mutators.
145 void set_transport_infos(const TransportInfos& transport_infos) {
146 transport_infos_ = transport_infos;
147 }
148 // Adds a TransportInfo to this description.
149 // Returns false if a TransportInfo with the same name already exists.
150 bool AddTransportInfo(const TransportInfo& transport_info);
151 bool RemoveTransportInfoByName(const std::string& name);
152
153 // Group accessors.
154 const ContentGroups& groups() const { return content_groups_; }
155 const ContentGroup* GetGroupByName(const std::string& name) const;
156 bool HasGroup(const std::string& name) const;
157
158 // Group mutators.
159 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
160 // Remove the first group with the same semantics specified by |name|.
161 void RemoveGroupByName(const std::string& name);
162
163 private:
164 ContentInfos contents_;
165 TransportInfos transport_infos_;
166 ContentGroups content_groups_;
167};
168
169// Indicates whether a ContentDescription was an offer or an answer, as
170// described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE
171// indicates a jingle update message which contains a subset of a full
172// session description
173enum ContentAction {
174 CA_OFFER, CA_PRANSWER, CA_ANSWER, CA_UPDATE
175};
176
177// Indicates whether a ContentDescription was sent by the local client
178// or received from the remote client.
179enum ContentSource {
180 CS_LOCAL, CS_REMOTE
181};
182
183} // namespace cricket
184
185#endif // WEBRTC_P2P_BASE_SESSIONDESCRIPTION_H_