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