You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
7.6 KiB

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