henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004--2005, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef TALK_P2P_BASE_SESSIONDESCRIPTION_H_ |
| 29 | #define TALK_P2P_BASE_SESSIONDESCRIPTION_H_ |
| 30 | |
| 31 | #include <string> |
| 32 | #include <vector> |
| 33 | |
| 34 | #include "talk/base/constructormagic.h" |
| 35 | #include "talk/p2p/base/transportinfo.h" |
| 36 | |
| 37 | namespace cricket { |
| 38 | |
| 39 | // Describes a session content. Individual content types inherit from |
| 40 | // this class. Analagous to a <jingle><content><description> or |
| 41 | // <session><description>. |
| 42 | class ContentDescription { |
| 43 | public: |
| 44 | virtual ~ContentDescription() {} |
| 45 | virtual ContentDescription* Copy() const = 0; |
| 46 | }; |
| 47 | |
| 48 | // Analagous to a <jingle><content> or <session><description>. |
| 49 | // name = name of <content name="..."> |
| 50 | // type = xmlns of <content> |
| 51 | struct ContentInfo { |
| 52 | ContentInfo() : description(NULL) {} |
| 53 | ContentInfo(const std::string& name, |
| 54 | const std::string& type, |
| 55 | ContentDescription* description) : |
| 56 | name(name), type(type), rejected(false), description(description) {} |
| 57 | ContentInfo(const std::string& name, |
| 58 | const std::string& type, |
| 59 | bool rejected, |
| 60 | ContentDescription* description) : |
| 61 | name(name), type(type), rejected(rejected), description(description) {} |
| 62 | std::string name; |
| 63 | std::string type; |
| 64 | bool rejected; |
| 65 | ContentDescription* description; |
| 66 | }; |
| 67 | |
| 68 | typedef std::vector<std::string> ContentNames; |
| 69 | |
| 70 | // This class provides a mechanism to aggregate different media contents into a |
| 71 | // group. This group can also be shared with the peers in a pre-defined format. |
| 72 | // GroupInfo should be populated only with the |content_name| of the |
| 73 | // MediaDescription. |
| 74 | class ContentGroup { |
| 75 | public: |
| 76 | explicit ContentGroup(const std::string& semantics) : |
| 77 | semantics_(semantics) {} |
| 78 | |
| 79 | const std::string& semantics() const { return semantics_; } |
| 80 | const ContentNames& content_names() const { return content_names_; } |
| 81 | |
| 82 | const std::string* FirstContentName() const; |
| 83 | bool HasContentName(const std::string& content_name) const; |
| 84 | void AddContentName(const std::string& content_name); |
| 85 | bool RemoveContentName(const std::string& content_name); |
| 86 | |
| 87 | private: |
| 88 | std::string semantics_; |
| 89 | ContentNames content_names_; |
| 90 | }; |
| 91 | |
| 92 | typedef std::vector<ContentInfo> ContentInfos; |
| 93 | typedef std::vector<ContentGroup> ContentGroups; |
| 94 | |
| 95 | const ContentInfo* FindContentInfoByName( |
| 96 | const ContentInfos& contents, const std::string& name); |
| 97 | const ContentInfo* FindContentInfoByType( |
| 98 | const ContentInfos& contents, const std::string& type); |
| 99 | |
| 100 | // Describes a collection of contents, each with its own name and |
| 101 | // type. Analogous to a <jingle> or <session> stanza. Assumes that |
| 102 | // contents are unique be name, but doesn't enforce that. |
| 103 | class SessionDescription { |
| 104 | public: |
| 105 | SessionDescription() {} |
| 106 | explicit SessionDescription(const ContentInfos& contents) : |
| 107 | contents_(contents) {} |
| 108 | SessionDescription(const ContentInfos& contents, |
| 109 | const ContentGroups& groups) : |
| 110 | contents_(contents), |
| 111 | content_groups_(groups) {} |
| 112 | SessionDescription(const ContentInfos& contents, |
| 113 | const TransportInfos& transports, |
| 114 | const ContentGroups& groups) : |
| 115 | contents_(contents), |
| 116 | transport_infos_(transports), |
| 117 | content_groups_(groups) {} |
| 118 | ~SessionDescription() { |
| 119 | for (ContentInfos::iterator content = contents_.begin(); |
| 120 | content != contents_.end(); ++content) { |
| 121 | delete content->description; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | SessionDescription* Copy() const; |
| 126 | |
| 127 | // Content accessors. |
| 128 | const ContentInfos& contents() const { return contents_; } |
| 129 | ContentInfos& contents() { return contents_; } |
| 130 | const ContentInfo* GetContentByName(const std::string& name) const; |
| 131 | ContentInfo* GetContentByName(const std::string& name); |
| 132 | const ContentDescription* GetContentDescriptionByName( |
| 133 | const std::string& name) const; |
| 134 | ContentDescription* GetContentDescriptionByName(const std::string& name); |
| 135 | const ContentInfo* FirstContentByType(const std::string& type) const; |
| 136 | const ContentInfo* FirstContent() const; |
| 137 | |
| 138 | // Content mutators. |
| 139 | // Adds a content to this description. Takes ownership of ContentDescription*. |
| 140 | void AddContent(const std::string& name, |
| 141 | const std::string& type, |
| 142 | ContentDescription* description); |
| 143 | void AddContent(const std::string& name, |
| 144 | const std::string& type, |
| 145 | bool rejected, |
| 146 | ContentDescription* description); |
| 147 | bool RemoveContentByName(const std::string& name); |
| 148 | |
| 149 | // Transport accessors. |
| 150 | const TransportInfos& transport_infos() const { return transport_infos_; } |
| 151 | TransportInfos& transport_infos() { return transport_infos_; } |
| 152 | const TransportInfo* GetTransportInfoByName( |
| 153 | const std::string& name) const; |
| 154 | TransportInfo* GetTransportInfoByName(const std::string& name); |
| 155 | const TransportDescription* GetTransportDescriptionByName( |
| 156 | const std::string& name) const { |
| 157 | const TransportInfo* tinfo = GetTransportInfoByName(name); |
| 158 | return tinfo ? &tinfo->description : NULL; |
| 159 | } |
| 160 | |
| 161 | // Transport mutators. |
| 162 | void set_transport_infos(const TransportInfos& transport_infos) { |
| 163 | transport_infos_ = transport_infos; |
| 164 | } |
| 165 | // Adds a TransportInfo to this description. |
| 166 | // Returns false if a TransportInfo with the same name already exists. |
| 167 | bool AddTransportInfo(const TransportInfo& transport_info); |
| 168 | bool RemoveTransportInfoByName(const std::string& name); |
| 169 | |
| 170 | // Group accessors. |
| 171 | const ContentGroups& groups() const { return content_groups_; } |
| 172 | const ContentGroup* GetGroupByName(const std::string& name) const; |
| 173 | bool HasGroup(const std::string& name) const; |
| 174 | |
| 175 | // Group mutators. |
| 176 | void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); } |
| 177 | // Remove the first group with the same semantics specified by |name|. |
| 178 | void RemoveGroupByName(const std::string& name); |
| 179 | |
| 180 | private: |
| 181 | ContentInfos contents_; |
| 182 | TransportInfos transport_infos_; |
| 183 | ContentGroups content_groups_; |
| 184 | }; |
| 185 | |
| 186 | // Indicates whether a ContentDescription was an offer or an answer, as |
| 187 | // described in http://www.ietf.org/rfc/rfc3264.txt. CA_UPDATE |
| 188 | // indicates a jingle update message which contains a subset of a full |
| 189 | // session description |
| 190 | enum ContentAction { |
| 191 | CA_OFFER, CA_PRANSWER, CA_ANSWER, CA_UPDATE |
| 192 | }; |
| 193 | |
| 194 | // Indicates whether a ContentDescription was sent by the local client |
| 195 | // or received from the remote client. |
| 196 | enum ContentSource { |
| 197 | CS_LOCAL, CS_REMOTE |
| 198 | }; |
| 199 | |
| 200 | } // namespace cricket |
| 201 | |
| 202 | #endif // TALK_P2P_BASE_SESSIONDESCRIPTION_H_ |