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