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