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