Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 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 | |
| 11 | #ifndef PC_SESSIONDESCRIPTION_H_ |
| 12 | #define PC_SESSIONDESCRIPTION_H_ |
| 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 17 | #include "api/cryptoparams.h" |
| 18 | #include "api/rtpparameters.h" |
| 19 | #include "api/rtptransceiverinterface.h" |
| 20 | #include "media/base/codec.h" |
| 21 | #include "media/base/mediachannel.h" |
| 22 | #include "media/base/streamparams.h" |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 23 | #include "p2p/base/transportinfo.h" |
| 24 | #include "rtc_base/constructormagic.h" |
| 25 | |
| 26 | namespace cricket { |
| 27 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 28 | typedef std::vector<AudioCodec> AudioCodecs; |
| 29 | typedef std::vector<VideoCodec> VideoCodecs; |
| 30 | typedef std::vector<DataCodec> DataCodecs; |
| 31 | typedef std::vector<CryptoParams> CryptoParamsVec; |
| 32 | typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions; |
| 33 | |
| 34 | // RTC4585 RTP/AVPF |
| 35 | extern const char kMediaProtocolAvpf[]; |
| 36 | // RFC5124 RTP/SAVPF |
| 37 | extern const char kMediaProtocolSavpf[]; |
| 38 | |
| 39 | extern const char kMediaProtocolDtlsSavpf[]; |
| 40 | |
| 41 | extern const char kMediaProtocolRtpPrefix[]; |
| 42 | |
| 43 | extern const char kMediaProtocolSctp[]; |
| 44 | extern const char kMediaProtocolDtlsSctp[]; |
| 45 | extern const char kMediaProtocolUdpDtlsSctp[]; |
| 46 | extern const char kMediaProtocolTcpDtlsSctp[]; |
| 47 | |
| 48 | // Options to control how session descriptions are generated. |
| 49 | const int kAutoBandwidth = -1; |
| 50 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 51 | class AudioContentDescription; |
| 52 | class VideoContentDescription; |
| 53 | class DataContentDescription; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 54 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 55 | // Describes a session description media section. There are subclasses for each |
| 56 | // media type (audio, video, data) that will have additional information. |
| 57 | class MediaContentDescription { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 58 | public: |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 59 | MediaContentDescription() = default; |
| 60 | virtual ~MediaContentDescription() = default; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 61 | |
| 62 | virtual MediaType type() const = 0; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 63 | |
| 64 | // Try to cast this media description to an AudioContentDescription. Returns |
| 65 | // nullptr if the cast fails. |
| 66 | virtual AudioContentDescription* as_audio() { return nullptr; } |
| 67 | virtual const AudioContentDescription* as_audio() const { return nullptr; } |
| 68 | |
| 69 | // Try to cast this media description to a VideoContentDescription. Returns |
| 70 | // nullptr if the cast fails. |
| 71 | virtual VideoContentDescription* as_video() { return nullptr; } |
| 72 | virtual const VideoContentDescription* as_video() const { return nullptr; } |
| 73 | |
| 74 | // Try to cast this media description to a DataContentDescription. Returns |
| 75 | // nullptr if the cast fails. |
| 76 | virtual DataContentDescription* as_data() { return nullptr; } |
| 77 | virtual const DataContentDescription* as_data() const { return nullptr; } |
| 78 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 79 | virtual bool has_codecs() const = 0; |
| 80 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 81 | virtual MediaContentDescription* Copy() const = 0; |
| 82 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 83 | // |protocol| is the expected media transport protocol, such as RTP/AVPF, |
| 84 | // RTP/SAVPF or SCTP/DTLS. |
| 85 | std::string protocol() const { return protocol_; } |
| 86 | void set_protocol(const std::string& protocol) { protocol_ = protocol; } |
| 87 | |
| 88 | webrtc::RtpTransceiverDirection direction() const { return direction_; } |
| 89 | void set_direction(webrtc::RtpTransceiverDirection direction) { |
| 90 | direction_ = direction; |
| 91 | } |
| 92 | |
| 93 | bool rtcp_mux() const { return rtcp_mux_; } |
| 94 | void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; } |
| 95 | |
| 96 | bool rtcp_reduced_size() const { return rtcp_reduced_size_; } |
| 97 | void set_rtcp_reduced_size(bool reduced_size) { |
| 98 | rtcp_reduced_size_ = reduced_size; |
| 99 | } |
| 100 | |
| 101 | int bandwidth() const { return bandwidth_; } |
| 102 | void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; } |
| 103 | |
| 104 | const std::vector<CryptoParams>& cryptos() const { return cryptos_; } |
| 105 | void AddCrypto(const CryptoParams& params) { cryptos_.push_back(params); } |
| 106 | void set_cryptos(const std::vector<CryptoParams>& cryptos) { |
| 107 | cryptos_ = cryptos; |
| 108 | } |
| 109 | |
| 110 | const RtpHeaderExtensions& rtp_header_extensions() const { |
| 111 | return rtp_header_extensions_; |
| 112 | } |
| 113 | void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
| 114 | rtp_header_extensions_ = extensions; |
| 115 | rtp_header_extensions_set_ = true; |
| 116 | } |
| 117 | void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) { |
| 118 | rtp_header_extensions_.push_back(ext); |
| 119 | rtp_header_extensions_set_ = true; |
| 120 | } |
| 121 | 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 | 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 | bool rtp_header_extensions_set() const { return rtp_header_extensions_set_; } |
| 138 | const StreamParamsVec& streams() const { return streams_; } |
| 139 | // TODO(pthatcher): Remove this by giving mediamessage.cc access |
| 140 | // to MediaContentDescription |
| 141 | StreamParamsVec& mutable_streams() { return streams_; } |
| 142 | void AddStream(const StreamParams& stream) { streams_.push_back(stream); } |
| 143 | // Legacy streams have an ssrc, but nothing else. |
| 144 | void AddLegacyStream(uint32_t ssrc) { |
| 145 | streams_.push_back(StreamParams::CreateLegacy(ssrc)); |
| 146 | } |
| 147 | void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
| 148 | StreamParams sp = StreamParams::CreateLegacy(ssrc); |
| 149 | sp.AddFidSsrc(ssrc, fid_ssrc); |
| 150 | streams_.push_back(sp); |
| 151 | } |
| 152 | // Sets the CNAME of all StreamParams if it have not been set. |
| 153 | void SetCnameIfEmpty(const std::string& cname) { |
| 154 | for (cricket::StreamParamsVec::iterator it = streams_.begin(); |
| 155 | it != streams_.end(); ++it) { |
| 156 | if (it->cname.empty()) |
| 157 | it->cname = cname; |
| 158 | } |
| 159 | } |
| 160 | uint32_t first_ssrc() const { |
| 161 | if (streams_.empty()) { |
| 162 | return 0; |
| 163 | } |
| 164 | return streams_[0].first_ssrc(); |
| 165 | } |
| 166 | bool has_ssrcs() const { |
| 167 | if (streams_.empty()) { |
| 168 | return false; |
| 169 | } |
| 170 | return streams_[0].has_ssrcs(); |
| 171 | } |
| 172 | |
| 173 | void set_conference_mode(bool enable) { conference_mode_ = enable; } |
| 174 | bool conference_mode() const { return conference_mode_; } |
| 175 | |
| 176 | // https://tools.ietf.org/html/rfc4566#section-5.7 |
| 177 | // May be present at the media or session level of SDP. If present at both |
| 178 | // levels, the media-level attribute overwrites the session-level one. |
| 179 | void set_connection_address(const rtc::SocketAddress& address) { |
| 180 | connection_address_ = address; |
| 181 | } |
| 182 | const rtc::SocketAddress& connection_address() const { |
| 183 | return connection_address_; |
| 184 | } |
| 185 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 186 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 187 | // within the same rtp stream. |
| 188 | enum ExtmapAllowMixed { kNo, kSession, kMedia }; |
| 189 | void set_mixed_one_two_byte_header_extensions_supported( |
| 190 | ExtmapAllowMixed supported) { |
| 191 | if (supported == kMedia && |
| 192 | mixed_one_two_byte_header_extensions_supported_ == kSession) { |
| 193 | // Do not downgrade from session level to media level. |
| 194 | return; |
| 195 | } |
| 196 | mixed_one_two_byte_header_extensions_supported_ = supported; |
| 197 | } |
| 198 | ExtmapAllowMixed mixed_one_two_byte_header_extensions_supported() const { |
| 199 | return mixed_one_two_byte_header_extensions_supported_; |
| 200 | } |
| 201 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 202 | protected: |
| 203 | bool rtcp_mux_ = false; |
| 204 | bool rtcp_reduced_size_ = false; |
| 205 | int bandwidth_ = kAutoBandwidth; |
| 206 | std::string protocol_; |
| 207 | std::vector<CryptoParams> cryptos_; |
| 208 | std::vector<webrtc::RtpExtension> rtp_header_extensions_; |
| 209 | bool rtp_header_extensions_set_ = false; |
| 210 | StreamParamsVec streams_; |
| 211 | bool conference_mode_ = false; |
| 212 | webrtc::RtpTransceiverDirection direction_ = |
| 213 | webrtc::RtpTransceiverDirection::kSendRecv; |
| 214 | rtc::SocketAddress connection_address_; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 215 | // Mixed one- and two-byte header not included in offer on media level or |
| 216 | // session level, but we will respond that we support it. The plan is to add |
| 217 | // it to our offer on session level. See todo in SessionDescription. |
| 218 | ExtmapAllowMixed mixed_one_two_byte_header_extensions_supported_ = kNo; |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 221 | // TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have |
| 222 | // updated. |
| 223 | using ContentDescription = MediaContentDescription; |
| 224 | |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 225 | template <class C> |
| 226 | class MediaContentDescriptionImpl : public MediaContentDescription { |
| 227 | public: |
| 228 | typedef C CodecType; |
| 229 | |
| 230 | // Codecs should be in preference order (most preferred codec first). |
| 231 | const std::vector<C>& codecs() const { return codecs_; } |
| 232 | void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; } |
| 233 | virtual bool has_codecs() const { return !codecs_.empty(); } |
| 234 | bool HasCodec(int id) { |
| 235 | bool found = false; |
| 236 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 237 | iter != codecs_.end(); ++iter) { |
| 238 | if (iter->id == id) { |
| 239 | found = true; |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | return found; |
| 244 | } |
| 245 | void AddCodec(const C& codec) { codecs_.push_back(codec); } |
| 246 | void AddOrReplaceCodec(const C& codec) { |
| 247 | for (typename std::vector<C>::iterator iter = codecs_.begin(); |
| 248 | iter != codecs_.end(); ++iter) { |
| 249 | if (iter->id == codec.id) { |
| 250 | *iter = codec; |
| 251 | return; |
| 252 | } |
| 253 | } |
| 254 | AddCodec(codec); |
| 255 | } |
| 256 | void AddCodecs(const std::vector<C>& codecs) { |
| 257 | typename std::vector<C>::const_iterator codec; |
| 258 | for (codec = codecs.begin(); codec != codecs.end(); ++codec) { |
| 259 | AddCodec(*codec); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | private: |
| 264 | std::vector<C> codecs_; |
| 265 | }; |
| 266 | |
| 267 | class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> { |
| 268 | public: |
| 269 | AudioContentDescription() {} |
| 270 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 271 | virtual AudioContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 272 | return new AudioContentDescription(*this); |
| 273 | } |
| 274 | virtual MediaType type() const { return MEDIA_TYPE_AUDIO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 275 | virtual AudioContentDescription* as_audio() { return this; } |
| 276 | virtual const AudioContentDescription* as_audio() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> { |
| 280 | public: |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 281 | virtual VideoContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 282 | return new VideoContentDescription(*this); |
| 283 | } |
| 284 | virtual MediaType type() const { return MEDIA_TYPE_VIDEO; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 285 | virtual VideoContentDescription* as_video() { return this; } |
| 286 | virtual const VideoContentDescription* as_video() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> { |
| 290 | public: |
| 291 | DataContentDescription() {} |
| 292 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 293 | virtual DataContentDescription* Copy() const { |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 294 | return new DataContentDescription(*this); |
| 295 | } |
| 296 | virtual MediaType type() const { return MEDIA_TYPE_DATA; } |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 297 | virtual DataContentDescription* as_data() { return this; } |
| 298 | virtual const DataContentDescription* as_data() const { return this; } |
Steve Anton | afd8e8c | 2017-12-19 16:35:35 -0800 | [diff] [blame] | 299 | |
| 300 | bool use_sctpmap() const { return use_sctpmap_; } |
| 301 | void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; } |
| 302 | |
| 303 | private: |
| 304 | bool use_sctpmap_ = true; |
| 305 | }; |
| 306 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 307 | // Protocol used for encoding media. This is the "top level" protocol that may |
| 308 | // be wrapped by zero or many transport protocols (UDP, ICE, etc.). |
| 309 | enum class MediaProtocolType { |
| 310 | kRtp, // Section will use the RTP protocol (e.g., for audio or video). |
| 311 | // https://tools.ietf.org/html/rfc3550 |
| 312 | kSctp // Section will use the SCTP protocol (e.g., for a data channel). |
| 313 | // https://tools.ietf.org/html/rfc4960 |
| 314 | }; |
| 315 | |
| 316 | // TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated. |
| 317 | constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp; |
| 318 | constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp; |
| 319 | |
| 320 | // Represents a session description section. Most information about the section |
| 321 | // is stored in the description, which is a subclass of MediaContentDescription. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 322 | struct ContentInfo { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 323 | friend class SessionDescription; |
| 324 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 325 | explicit ContentInfo(MediaProtocolType type) : type(type) {} |
| 326 | |
| 327 | // Alias for |name|. |
| 328 | std::string mid() const { return name; } |
| 329 | void set_mid(const std::string& mid) { this->name = mid; } |
| 330 | |
| 331 | // Alias for |description|. |
| 332 | MediaContentDescription* media_description() { return description; } |
| 333 | const MediaContentDescription* media_description() const { |
| 334 | return description; |
| 335 | } |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 336 | void set_media_description(MediaContentDescription* desc) { |
| 337 | description = desc; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 340 | // TODO(bugs.webrtc.org/8620): Rename this to mid. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 341 | std::string name; |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 342 | MediaProtocolType type; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 343 | bool rejected = false; |
| 344 | bool bundle_only = false; |
Steve Anton | 8171211 | 2018-01-05 11:27:54 -0800 | [diff] [blame] | 345 | // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this |
| 346 | // private. |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 347 | MediaContentDescription* description = nullptr; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | typedef std::vector<std::string> ContentNames; |
| 351 | |
| 352 | // This class provides a mechanism to aggregate different media contents into a |
| 353 | // group. This group can also be shared with the peers in a pre-defined format. |
| 354 | // GroupInfo should be populated only with the |content_name| of the |
| 355 | // MediaDescription. |
| 356 | class ContentGroup { |
| 357 | public: |
| 358 | explicit ContentGroup(const std::string& semantics); |
| 359 | ContentGroup(const ContentGroup&); |
| 360 | ContentGroup(ContentGroup&&); |
| 361 | ContentGroup& operator=(const ContentGroup&); |
| 362 | ContentGroup& operator=(ContentGroup&&); |
| 363 | ~ContentGroup(); |
| 364 | |
| 365 | const std::string& semantics() const { return semantics_; } |
| 366 | const ContentNames& content_names() const { return content_names_; } |
| 367 | |
| 368 | const std::string* FirstContentName() const; |
| 369 | bool HasContentName(const std::string& content_name) const; |
| 370 | void AddContentName(const std::string& content_name); |
| 371 | bool RemoveContentName(const std::string& content_name); |
| 372 | |
| 373 | private: |
| 374 | std::string semantics_; |
| 375 | ContentNames content_names_; |
| 376 | }; |
| 377 | |
| 378 | typedef std::vector<ContentInfo> ContentInfos; |
| 379 | typedef std::vector<ContentGroup> ContentGroups; |
| 380 | |
| 381 | const ContentInfo* FindContentInfoByName(const ContentInfos& contents, |
| 382 | const std::string& name); |
| 383 | const ContentInfo* FindContentInfoByType(const ContentInfos& contents, |
| 384 | const std::string& type); |
| 385 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 386 | // Determines how the MSID will be signaled in the SDP. These can be used as |
| 387 | // flags to indicate both or none. |
| 388 | enum MsidSignaling { |
| 389 | // Signal MSID with one a=msid line in the media section. |
| 390 | kMsidSignalingMediaSection = 0x1, |
| 391 | // Signal MSID with a=ssrc: msid lines in the media section. |
| 392 | kMsidSignalingSsrcAttribute = 0x2 |
| 393 | }; |
| 394 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 395 | // Describes a collection of contents, each with its own name and |
| 396 | // type. Analogous to a <jingle> or <session> stanza. Assumes that |
| 397 | // contents are unique be name, but doesn't enforce that. |
| 398 | class SessionDescription { |
| 399 | public: |
| 400 | SessionDescription(); |
| 401 | explicit SessionDescription(const ContentInfos& contents); |
| 402 | SessionDescription(const ContentInfos& contents, const ContentGroups& groups); |
| 403 | SessionDescription(const ContentInfos& contents, |
| 404 | const TransportInfos& transports, |
| 405 | const ContentGroups& groups); |
| 406 | ~SessionDescription(); |
| 407 | |
| 408 | SessionDescription* Copy() const; |
| 409 | |
| 410 | // Content accessors. |
| 411 | const ContentInfos& contents() const { return contents_; } |
| 412 | ContentInfos& contents() { return contents_; } |
| 413 | const ContentInfo* GetContentByName(const std::string& name) const; |
| 414 | ContentInfo* GetContentByName(const std::string& name); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 415 | const MediaContentDescription* GetContentDescriptionByName( |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 416 | const std::string& name) const; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 417 | MediaContentDescription* GetContentDescriptionByName(const std::string& name); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 418 | const ContentInfo* FirstContentByType(MediaProtocolType type) const; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 419 | const ContentInfo* FirstContent() const; |
| 420 | |
| 421 | // Content mutators. |
| 422 | // Adds a content to this description. Takes ownership of ContentDescription*. |
| 423 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 424 | MediaProtocolType type, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 425 | MediaContentDescription* description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 426 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 427 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 428 | bool rejected, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 429 | MediaContentDescription* description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 430 | void AddContent(const std::string& name, |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 431 | MediaProtocolType type, |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 432 | bool rejected, |
| 433 | bool bundle_only, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 434 | MediaContentDescription* description); |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 435 | bool RemoveContentByName(const std::string& name); |
| 436 | |
| 437 | // Transport accessors. |
| 438 | const TransportInfos& transport_infos() const { return transport_infos_; } |
| 439 | TransportInfos& transport_infos() { return transport_infos_; } |
| 440 | const TransportInfo* GetTransportInfoByName(const std::string& name) const; |
| 441 | TransportInfo* GetTransportInfoByName(const std::string& name); |
| 442 | const TransportDescription* GetTransportDescriptionByName( |
| 443 | const std::string& name) const { |
| 444 | const TransportInfo* tinfo = GetTransportInfoByName(name); |
| 445 | return tinfo ? &tinfo->description : NULL; |
| 446 | } |
| 447 | |
| 448 | // Transport mutators. |
| 449 | void set_transport_infos(const TransportInfos& transport_infos) { |
| 450 | transport_infos_ = transport_infos; |
| 451 | } |
| 452 | // Adds a TransportInfo to this description. |
| 453 | // Returns false if a TransportInfo with the same name already exists. |
| 454 | bool AddTransportInfo(const TransportInfo& transport_info); |
| 455 | bool RemoveTransportInfoByName(const std::string& name); |
| 456 | |
| 457 | // Group accessors. |
| 458 | const ContentGroups& groups() const { return content_groups_; } |
| 459 | const ContentGroup* GetGroupByName(const std::string& name) const; |
| 460 | bool HasGroup(const std::string& name) const; |
| 461 | |
| 462 | // Group mutators. |
| 463 | void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); } |
| 464 | // Remove the first group with the same semantics specified by |name|. |
| 465 | void RemoveGroupByName(const std::string& name); |
| 466 | |
| 467 | // Global attributes. |
| 468 | void set_msid_supported(bool supported) { msid_supported_ = supported; } |
| 469 | bool msid_supported() const { return msid_supported_; } |
| 470 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 471 | // Determines how the MSIDs were/will be signaled. Flag value composed of |
| 472 | // MsidSignaling bits (see enum above). |
| 473 | void set_msid_signaling(int msid_signaling) { |
| 474 | msid_signaling_ = msid_signaling; |
| 475 | } |
| 476 | int msid_signaling() const { return msid_signaling_; } |
| 477 | |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 478 | // Determines if it's allowed to mix one- and two-byte rtp header extensions |
| 479 | // within the same rtp stream. |
| 480 | void set_mixed_one_two_byte_header_extensions_supported(bool supported) { |
| 481 | mixed_one_two_byte_header_extensions_supported_ = supported; |
| 482 | MediaContentDescription::ExtmapAllowMixed extmap_allow_mixed = |
| 483 | supported ? MediaContentDescription::kSession |
| 484 | : MediaContentDescription::kNo; |
| 485 | for (auto& content : contents_) { |
| 486 | content.media_description() |
| 487 | ->set_mixed_one_two_byte_header_extensions_supported( |
| 488 | extmap_allow_mixed); |
| 489 | } |
| 490 | } |
| 491 | bool mixed_one_two_byte_header_extensions_supported() const { |
| 492 | return mixed_one_two_byte_header_extensions_supported_; |
| 493 | } |
| 494 | |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 495 | private: |
| 496 | SessionDescription(const SessionDescription&); |
| 497 | |
| 498 | ContentInfos contents_; |
| 499 | TransportInfos transport_infos_; |
| 500 | ContentGroups content_groups_; |
| 501 | bool msid_supported_ = true; |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 502 | // Default to what Plan B would do. |
| 503 | // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection. |
| 504 | int msid_signaling_ = kMsidSignalingSsrcAttribute; |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 505 | // TODO(kron): Activate mixed one- and two-byte header extension in offer at |
| 506 | // session level. It's currently not included in offer by default because |
| 507 | // clients prior to https://bugs.webrtc.org/9712 cannot parse this correctly. |
| 508 | // If it's included in offer to us we will respond that we support it. |
| 509 | bool mixed_one_two_byte_header_extensions_supported_ = false; |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 510 | }; |
| 511 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 512 | // Indicates whether a session description was sent by the local client or |
| 513 | // received from the remote client. |
Steve Anton | 4ab68ee | 2017-12-19 14:26:11 -0800 | [diff] [blame] | 514 | enum ContentSource { CS_LOCAL, CS_REMOTE }; |
| 515 | |
| 516 | } // namespace cricket |
| 517 | |
| 518 | #endif // PC_SESSIONDESCRIPTION_H_ |