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.

682 lines
25 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  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. #ifndef PC_SESSION_DESCRIPTION_H_
  11. #define PC_SESSION_DESCRIPTION_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <iosfwd>
  15. #include <memory>
  16. #include <string>
  17. #include <utility>
  18. #include <vector>
  19. #include "absl/memory/memory.h"
  20. #include "api/crypto_params.h"
  21. #include "api/media_types.h"
  22. #include "api/rtp_parameters.h"
  23. #include "api/rtp_transceiver_interface.h"
  24. #include "media/base/media_channel.h"
  25. #include "media/base/stream_params.h"
  26. #include "p2p/base/transport_description.h"
  27. #include "p2p/base/transport_info.h"
  28. #include "pc/media_protocol_names.h"
  29. #include "pc/simulcast_description.h"
  30. #include "rtc_base/deprecation.h"
  31. #include "rtc_base/socket_address.h"
  32. #include "rtc_base/system/rtc_export.h"
  33. namespace cricket {
  34. typedef std::vector<AudioCodec> AudioCodecs;
  35. typedef std::vector<VideoCodec> VideoCodecs;
  36. typedef std::vector<RtpDataCodec> RtpDataCodecs;
  37. typedef std::vector<CryptoParams> CryptoParamsVec;
  38. typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
  39. // RTC4585 RTP/AVPF
  40. extern const char kMediaProtocolAvpf[];
  41. // RFC5124 RTP/SAVPF
  42. extern const char kMediaProtocolSavpf[];
  43. extern const char kMediaProtocolDtlsSavpf[];
  44. // Options to control how session descriptions are generated.
  45. const int kAutoBandwidth = -1;
  46. class AudioContentDescription;
  47. class VideoContentDescription;
  48. class RtpDataContentDescription;
  49. class SctpDataContentDescription;
  50. // Describes a session description media section. There are subclasses for each
  51. // media type (audio, video, data) that will have additional information.
  52. class MediaContentDescription {
  53. public:
  54. MediaContentDescription() = default;
  55. virtual ~MediaContentDescription() = default;
  56. virtual MediaType type() const = 0;
  57. // Try to cast this media description to an AudioContentDescription. Returns
  58. // nullptr if the cast fails.
  59. virtual AudioContentDescription* as_audio() { return nullptr; }
  60. virtual const AudioContentDescription* as_audio() const { return nullptr; }
  61. // Try to cast this media description to a VideoContentDescription. Returns
  62. // nullptr if the cast fails.
  63. virtual VideoContentDescription* as_video() { return nullptr; }
  64. virtual const VideoContentDescription* as_video() const { return nullptr; }
  65. virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
  66. virtual const RtpDataContentDescription* as_rtp_data() const {
  67. return nullptr;
  68. }
  69. virtual SctpDataContentDescription* as_sctp() { return nullptr; }
  70. virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
  71. virtual bool has_codecs() const = 0;
  72. virtual MediaContentDescription* Copy() const = 0;
  73. virtual std::unique_ptr<MediaContentDescription> Clone() const {
  74. return absl::WrapUnique(Copy());
  75. }
  76. // |protocol| is the expected media transport protocol, such as RTP/AVPF,
  77. // RTP/SAVPF or SCTP/DTLS.
  78. virtual std::string protocol() const { return protocol_; }
  79. virtual void set_protocol(const std::string& protocol) {
  80. protocol_ = protocol;
  81. }
  82. virtual webrtc::RtpTransceiverDirection direction() const {
  83. return direction_;
  84. }
  85. virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
  86. direction_ = direction;
  87. }
  88. virtual bool rtcp_mux() const { return rtcp_mux_; }
  89. virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
  90. virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
  91. virtual void set_rtcp_reduced_size(bool reduced_size) {
  92. rtcp_reduced_size_ = reduced_size;
  93. }
  94. // Indicates support for the remote network estimate packet type. This
  95. // functionality is experimental and subject to change without notice.
  96. virtual bool remote_estimate() const { return remote_estimate_; }
  97. virtual void set_remote_estimate(bool remote_estimate) {
  98. remote_estimate_ = remote_estimate;
  99. }
  100. virtual int bandwidth() const { return bandwidth_; }
  101. virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
  102. virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
  103. virtual void AddCrypto(const CryptoParams& params) {
  104. cryptos_.push_back(params);
  105. }
  106. virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
  107. cryptos_ = cryptos;
  108. }
  109. virtual const RtpHeaderExtensions& rtp_header_extensions() const {
  110. return rtp_header_extensions_;
  111. }
  112. virtual void set_rtp_header_extensions(
  113. const RtpHeaderExtensions& extensions) {
  114. rtp_header_extensions_ = extensions;
  115. rtp_header_extensions_set_ = true;
  116. }
  117. virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
  118. rtp_header_extensions_.push_back(ext);
  119. rtp_header_extensions_set_ = true;
  120. }
  121. virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
  122. webrtc::RtpExtension webrtc_extension;
  123. webrtc_extension.uri = ext.uri;
  124. webrtc_extension.id = ext.id;
  125. rtp_header_extensions_.push_back(webrtc_extension);
  126. rtp_header_extensions_set_ = true;
  127. }
  128. virtual void ClearRtpHeaderExtensions() {
  129. rtp_header_extensions_.clear();
  130. rtp_header_extensions_set_ = true;
  131. }
  132. // We can't always tell if an empty list of header extensions is
  133. // because the other side doesn't support them, or just isn't hooked up to
  134. // signal them. For now we assume an empty list means no signaling, but
  135. // provide the ClearRtpHeaderExtensions method to allow "no support" to be
  136. // clearly indicated (i.e. when derived from other information).
  137. virtual bool rtp_header_extensions_set() const {
  138. return rtp_header_extensions_set_;
  139. }
  140. virtual const StreamParamsVec& streams() const { return send_streams_; }
  141. // TODO(pthatcher): Remove this by giving mediamessage.cc access
  142. // to MediaContentDescription
  143. virtual StreamParamsVec& mutable_streams() { return send_streams_; }
  144. virtual void AddStream(const StreamParams& stream) {
  145. send_streams_.push_back(stream);
  146. }
  147. // Legacy streams have an ssrc, but nothing else.
  148. void AddLegacyStream(uint32_t ssrc) {
  149. AddStream(StreamParams::CreateLegacy(ssrc));
  150. }
  151. void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
  152. StreamParams sp = StreamParams::CreateLegacy(ssrc);
  153. sp.AddFidSsrc(ssrc, fid_ssrc);
  154. AddStream(sp);
  155. }
  156. // Sets the CNAME of all StreamParams if it have not been set.
  157. virtual void SetCnameIfEmpty(const std::string& cname) {
  158. for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
  159. it != send_streams_.end(); ++it) {
  160. if (it->cname.empty())
  161. it->cname = cname;
  162. }
  163. }
  164. virtual uint32_t first_ssrc() const {
  165. if (send_streams_.empty()) {
  166. return 0;
  167. }
  168. return send_streams_[0].first_ssrc();
  169. }
  170. virtual bool has_ssrcs() const {
  171. if (send_streams_.empty()) {
  172. return false;
  173. }
  174. return send_streams_[0].has_ssrcs();
  175. }
  176. virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
  177. virtual bool conference_mode() const { return conference_mode_; }
  178. // https://tools.ietf.org/html/rfc4566#section-5.7
  179. // May be present at the media or session level of SDP. If present at both
  180. // levels, the media-level attribute overwrites the session-level one.
  181. virtual void set_connection_address(const rtc::SocketAddress& address) {
  182. connection_address_ = address;
  183. }
  184. virtual const rtc::SocketAddress& connection_address() const {
  185. return connection_address_;
  186. }
  187. // Determines if it's allowed to mix one- and two-byte rtp header extensions
  188. // within the same rtp stream.
  189. enum ExtmapAllowMixed { kNo, kSession, kMedia };
  190. virtual void set_extmap_allow_mixed_enum(
  191. ExtmapAllowMixed new_extmap_allow_mixed) {
  192. if (new_extmap_allow_mixed == kMedia &&
  193. extmap_allow_mixed_enum_ == kSession) {
  194. // Do not downgrade from session level to media level.
  195. return;
  196. }
  197. extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
  198. }
  199. virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
  200. return extmap_allow_mixed_enum_;
  201. }
  202. virtual bool extmap_allow_mixed() const {
  203. return extmap_allow_mixed_enum_ != kNo;
  204. }
  205. // Simulcast functionality.
  206. virtual bool HasSimulcast() const { return !simulcast_.empty(); }
  207. virtual SimulcastDescription& simulcast_description() { return simulcast_; }
  208. virtual const SimulcastDescription& simulcast_description() const {
  209. return simulcast_;
  210. }
  211. virtual void set_simulcast_description(
  212. const SimulcastDescription& simulcast) {
  213. simulcast_ = simulcast;
  214. }
  215. virtual const std::vector<RidDescription>& receive_rids() const {
  216. return receive_rids_;
  217. }
  218. virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
  219. receive_rids_ = rids;
  220. }
  221. virtual const absl::optional<std::string>& alt_protocol() const {
  222. return alt_protocol_;
  223. }
  224. virtual void set_alt_protocol(const absl::optional<std::string>& protocol) {
  225. alt_protocol_ = protocol;
  226. }
  227. protected:
  228. bool rtcp_mux_ = false;
  229. bool rtcp_reduced_size_ = false;
  230. bool remote_estimate_ = false;
  231. int bandwidth_ = kAutoBandwidth;
  232. std::string protocol_;
  233. std::vector<CryptoParams> cryptos_;
  234. std::vector<webrtc::RtpExtension> rtp_header_extensions_;
  235. bool rtp_header_extensions_set_ = false;
  236. StreamParamsVec send_streams_;
  237. bool conference_mode_ = false;
  238. webrtc::RtpTransceiverDirection direction_ =
  239. webrtc::RtpTransceiverDirection::kSendRecv;
  240. rtc::SocketAddress connection_address_;
  241. // Mixed one- and two-byte header not included in offer on media level or
  242. // session level, but we will respond that we support it. The plan is to add
  243. // it to our offer on session level. See todo in SessionDescription.
  244. ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
  245. SimulcastDescription simulcast_;
  246. std::vector<RidDescription> receive_rids_;
  247. absl::optional<std::string> alt_protocol_;
  248. };
  249. // TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
  250. // updated.
  251. using ContentDescription = MediaContentDescription;
  252. template <class C>
  253. class MediaContentDescriptionImpl : public MediaContentDescription {
  254. public:
  255. void set_protocol(const std::string& protocol) override {
  256. RTC_DCHECK(IsRtpProtocol(protocol));
  257. protocol_ = protocol;
  258. }
  259. typedef C CodecType;
  260. // Codecs should be in preference order (most preferred codec first).
  261. virtual const std::vector<C>& codecs() const { return codecs_; }
  262. virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
  263. bool has_codecs() const override { return !codecs_.empty(); }
  264. virtual bool HasCodec(int id) {
  265. bool found = false;
  266. for (typename std::vector<C>::iterator iter = codecs_.begin();
  267. iter != codecs_.end(); ++iter) {
  268. if (iter->id == id) {
  269. found = true;
  270. break;
  271. }
  272. }
  273. return found;
  274. }
  275. virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
  276. virtual void AddOrReplaceCodec(const C& codec) {
  277. for (typename std::vector<C>::iterator iter = codecs_.begin();
  278. iter != codecs_.end(); ++iter) {
  279. if (iter->id == codec.id) {
  280. *iter = codec;
  281. return;
  282. }
  283. }
  284. AddCodec(codec);
  285. }
  286. virtual void AddCodecs(const std::vector<C>& codecs) {
  287. typename std::vector<C>::const_iterator codec;
  288. for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
  289. AddCodec(*codec);
  290. }
  291. }
  292. private:
  293. std::vector<C> codecs_;
  294. };
  295. class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
  296. public:
  297. AudioContentDescription() {}
  298. virtual AudioContentDescription* Copy() const {
  299. return new AudioContentDescription(*this);
  300. }
  301. virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
  302. virtual AudioContentDescription* as_audio() { return this; }
  303. virtual const AudioContentDescription* as_audio() const { return this; }
  304. };
  305. class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
  306. public:
  307. virtual VideoContentDescription* Copy() const {
  308. return new VideoContentDescription(*this);
  309. }
  310. virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
  311. virtual VideoContentDescription* as_video() { return this; }
  312. virtual const VideoContentDescription* as_video() const { return this; }
  313. };
  314. class RtpDataContentDescription
  315. : public MediaContentDescriptionImpl<RtpDataCodec> {
  316. public:
  317. RtpDataContentDescription() {}
  318. RtpDataContentDescription* Copy() const override {
  319. return new RtpDataContentDescription(*this);
  320. }
  321. MediaType type() const override { return MEDIA_TYPE_DATA; }
  322. RtpDataContentDescription* as_rtp_data() override { return this; }
  323. const RtpDataContentDescription* as_rtp_data() const override { return this; }
  324. };
  325. class SctpDataContentDescription : public MediaContentDescription {
  326. public:
  327. SctpDataContentDescription() {}
  328. SctpDataContentDescription(const SctpDataContentDescription& o)
  329. : MediaContentDescription(o),
  330. use_sctpmap_(o.use_sctpmap_),
  331. port_(o.port_),
  332. max_message_size_(o.max_message_size_) {}
  333. SctpDataContentDescription* Copy() const override {
  334. return new SctpDataContentDescription(*this);
  335. }
  336. MediaType type() const override { return MEDIA_TYPE_DATA; }
  337. SctpDataContentDescription* as_sctp() override { return this; }
  338. const SctpDataContentDescription* as_sctp() const override { return this; }
  339. bool has_codecs() const override { return false; }
  340. void set_protocol(const std::string& protocol) override {
  341. RTC_DCHECK(IsSctpProtocol(protocol));
  342. protocol_ = protocol;
  343. }
  344. bool use_sctpmap() const { return use_sctpmap_; }
  345. void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
  346. int port() const { return port_; }
  347. void set_port(int port) { port_ = port; }
  348. int max_message_size() const { return max_message_size_; }
  349. void set_max_message_size(int max_message_size) {
  350. max_message_size_ = max_message_size;
  351. }
  352. private:
  353. bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
  354. // Defaults should be constants imported from SCTP. Quick hack.
  355. int port_ = 5000;
  356. // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
  357. int max_message_size_ = 64 * 1024;
  358. };
  359. // Protocol used for encoding media. This is the "top level" protocol that may
  360. // be wrapped by zero or many transport protocols (UDP, ICE, etc.).
  361. enum class MediaProtocolType {
  362. kRtp, // Section will use the RTP protocol (e.g., for audio or video).
  363. // https://tools.ietf.org/html/rfc3550
  364. kSctp // Section will use the SCTP protocol (e.g., for a data channel).
  365. // https://tools.ietf.org/html/rfc4960
  366. };
  367. // TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
  368. constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
  369. constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
  370. // Represents a session description section. Most information about the section
  371. // is stored in the description, which is a subclass of MediaContentDescription.
  372. // Owns the description.
  373. class RTC_EXPORT ContentInfo {
  374. public:
  375. explicit ContentInfo(MediaProtocolType type) : type(type) {}
  376. ~ContentInfo();
  377. // Copy
  378. ContentInfo(const ContentInfo& o);
  379. ContentInfo& operator=(const ContentInfo& o);
  380. ContentInfo(ContentInfo&& o) = default;
  381. ContentInfo& operator=(ContentInfo&& o) = default;
  382. // Alias for |name|.
  383. std::string mid() const { return name; }
  384. void set_mid(const std::string& mid) { this->name = mid; }
  385. // Alias for |description|.
  386. MediaContentDescription* media_description();
  387. const MediaContentDescription* media_description() const;
  388. void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
  389. description_ = std::move(desc);
  390. // For backwards compatibility only.
  391. description = description_.get();
  392. }
  393. // TODO(bugs.webrtc.org/8620): Rename this to mid.
  394. std::string name;
  395. MediaProtocolType type;
  396. bool rejected = false;
  397. bool bundle_only = false;
  398. private:
  399. friend class SessionDescription;
  400. std::unique_ptr<MediaContentDescription> description_;
  401. public:
  402. // Kept for backwards compatibility only.
  403. MediaContentDescription* description = nullptr;
  404. };
  405. typedef std::vector<std::string> ContentNames;
  406. // This class provides a mechanism to aggregate different media contents into a
  407. // group. This group can also be shared with the peers in a pre-defined format.
  408. // GroupInfo should be populated only with the |content_name| of the
  409. // MediaDescription.
  410. class ContentGroup {
  411. public:
  412. explicit ContentGroup(const std::string& semantics);
  413. ContentGroup(const ContentGroup&);
  414. ContentGroup(ContentGroup&&);
  415. ContentGroup& operator=(const ContentGroup&);
  416. ContentGroup& operator=(ContentGroup&&);
  417. ~ContentGroup();
  418. const std::string& semantics() const { return semantics_; }
  419. const ContentNames& content_names() const { return content_names_; }
  420. const std::string* FirstContentName() const;
  421. bool HasContentName(const std::string& content_name) const;
  422. void AddContentName(const std::string& content_name);
  423. bool RemoveContentName(const std::string& content_name);
  424. private:
  425. std::string semantics_;
  426. ContentNames content_names_;
  427. };
  428. typedef std::vector<ContentInfo> ContentInfos;
  429. typedef std::vector<ContentGroup> ContentGroups;
  430. const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
  431. const std::string& name);
  432. const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
  433. const std::string& type);
  434. // Determines how the MSID will be signaled in the SDP. These can be used as
  435. // flags to indicate both or none.
  436. enum MsidSignaling {
  437. // Signal MSID with one a=msid line in the media section.
  438. kMsidSignalingMediaSection = 0x1,
  439. // Signal MSID with a=ssrc: msid lines in the media section.
  440. kMsidSignalingSsrcAttribute = 0x2
  441. };
  442. // Describes a collection of contents, each with its own name and
  443. // type. Analogous to a <jingle> or <session> stanza. Assumes that
  444. // contents are unique be name, but doesn't enforce that.
  445. class SessionDescription {
  446. public:
  447. SessionDescription();
  448. ~SessionDescription();
  449. std::unique_ptr<SessionDescription> Clone() const;
  450. struct MediaTransportSetting;
  451. // Content accessors.
  452. const ContentInfos& contents() const { return contents_; }
  453. ContentInfos& contents() { return contents_; }
  454. const ContentInfo* GetContentByName(const std::string& name) const;
  455. ContentInfo* GetContentByName(const std::string& name);
  456. const MediaContentDescription* GetContentDescriptionByName(
  457. const std::string& name) const;
  458. MediaContentDescription* GetContentDescriptionByName(const std::string& name);
  459. const ContentInfo* FirstContentByType(MediaProtocolType type) const;
  460. const ContentInfo* FirstContent() const;
  461. // Content mutators.
  462. // Adds a content to this description. Takes ownership of ContentDescription*.
  463. void AddContent(const std::string& name,
  464. MediaProtocolType type,
  465. std::unique_ptr<MediaContentDescription> description);
  466. void AddContent(const std::string& name,
  467. MediaProtocolType type,
  468. bool rejected,
  469. std::unique_ptr<MediaContentDescription> description);
  470. void AddContent(const std::string& name,
  471. MediaProtocolType type,
  472. bool rejected,
  473. bool bundle_only,
  474. std::unique_ptr<MediaContentDescription> description);
  475. void AddContent(ContentInfo&& content);
  476. RTC_DEPRECATED void AddContent(const std::string& name,
  477. MediaProtocolType type,
  478. MediaContentDescription* description) {
  479. AddContent(name, type, absl::WrapUnique(description));
  480. }
  481. RTC_DEPRECATED void AddContent(const std::string& name,
  482. MediaProtocolType type,
  483. bool rejected,
  484. MediaContentDescription* description) {
  485. AddContent(name, type, rejected, absl::WrapUnique(description));
  486. }
  487. RTC_DEPRECATED void AddContent(const std::string& name,
  488. MediaProtocolType type,
  489. bool rejected,
  490. bool bundle_only,
  491. MediaContentDescription* description) {
  492. AddContent(name, type, rejected, bundle_only,
  493. absl::WrapUnique(description));
  494. }
  495. RTC_DEPRECATED void AddContent(ContentInfo* content) {
  496. AddContent(std::move(*content));
  497. }
  498. bool RemoveContentByName(const std::string& name);
  499. // Transport accessors.
  500. const TransportInfos& transport_infos() const { return transport_infos_; }
  501. TransportInfos& transport_infos() { return transport_infos_; }
  502. const TransportInfo* GetTransportInfoByName(const std::string& name) const;
  503. TransportInfo* GetTransportInfoByName(const std::string& name);
  504. const TransportDescription* GetTransportDescriptionByName(
  505. const std::string& name) const {
  506. const TransportInfo* tinfo = GetTransportInfoByName(name);
  507. return tinfo ? &tinfo->description : NULL;
  508. }
  509. // Transport mutators.
  510. void set_transport_infos(const TransportInfos& transport_infos) {
  511. transport_infos_ = transport_infos;
  512. }
  513. // Adds a TransportInfo to this description.
  514. void AddTransportInfo(const TransportInfo& transport_info);
  515. bool RemoveTransportInfoByName(const std::string& name);
  516. // Group accessors.
  517. const ContentGroups& groups() const { return content_groups_; }
  518. const ContentGroup* GetGroupByName(const std::string& name) const;
  519. bool HasGroup(const std::string& name) const;
  520. // Group mutators.
  521. void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
  522. // Remove the first group with the same semantics specified by |name|.
  523. void RemoveGroupByName(const std::string& name);
  524. // Global attributes.
  525. void set_msid_supported(bool supported) { msid_supported_ = supported; }
  526. bool msid_supported() const { return msid_supported_; }
  527. // Determines how the MSIDs were/will be signaled. Flag value composed of
  528. // MsidSignaling bits (see enum above).
  529. void set_msid_signaling(int msid_signaling) {
  530. msid_signaling_ = msid_signaling;
  531. }
  532. int msid_signaling() const { return msid_signaling_; }
  533. // Determines if it's allowed to mix one- and two-byte rtp header extensions
  534. // within the same rtp stream.
  535. void set_extmap_allow_mixed(bool supported) {
  536. extmap_allow_mixed_ = supported;
  537. MediaContentDescription::ExtmapAllowMixed media_level_setting =
  538. supported ? MediaContentDescription::kSession
  539. : MediaContentDescription::kNo;
  540. for (auto& content : contents_) {
  541. // Do not set to kNo if the current setting is kMedia.
  542. if (supported || content.media_description()->extmap_allow_mixed_enum() !=
  543. MediaContentDescription::kMedia) {
  544. content.media_description()->set_extmap_allow_mixed_enum(
  545. media_level_setting);
  546. }
  547. }
  548. }
  549. bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
  550. // Adds the media transport setting.
  551. // Media transport name uniquely identifies the type of media transport.
  552. // The name cannot be empty, or repeated in the previously added transport
  553. // settings.
  554. void AddMediaTransportSetting(const std::string& media_transport_name,
  555. const std::string& media_transport_setting) {
  556. RTC_DCHECK(!media_transport_name.empty());
  557. for (const auto& setting : media_transport_settings_) {
  558. RTC_DCHECK(media_transport_name != setting.transport_name)
  559. << "MediaTransportSetting was already registered, transport_name="
  560. << setting.transport_name;
  561. }
  562. media_transport_settings_.push_back(
  563. {media_transport_name, media_transport_setting});
  564. }
  565. // Gets the media transport settings, in order of preference.
  566. const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
  567. return media_transport_settings_;
  568. }
  569. struct MediaTransportSetting {
  570. std::string transport_name;
  571. std::string transport_setting;
  572. };
  573. private:
  574. SessionDescription(const SessionDescription&);
  575. ContentInfos contents_;
  576. TransportInfos transport_infos_;
  577. ContentGroups content_groups_;
  578. bool msid_supported_ = true;
  579. // Default to what Plan B would do.
  580. // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
  581. int msid_signaling_ = kMsidSignalingSsrcAttribute;
  582. // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
  583. // offer at session level. It's currently not included in offer by default
  584. // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
  585. // correctly. If it's included in offer to us we will respond that we support
  586. // it.
  587. bool extmap_allow_mixed_ = false;
  588. std::vector<MediaTransportSetting> media_transport_settings_;
  589. };
  590. // Indicates whether a session description was sent by the local client or
  591. // received from the remote client.
  592. enum ContentSource { CS_LOCAL, CS_REMOTE };
  593. } // namespace cricket
  594. #endif // PC_SESSION_DESCRIPTION_H_