blob: ceb9fd7c76af99072176fe505c05ee1a53dda6c3 [file] [log] [blame]
Steve Anton4ab68ee2017-12-19 14:26:11 -08001/*
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 Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
16#include <iosfwd>
Steve Anton4ab68ee2017-12-19 14:26:11 -080017#include <string>
18#include <vector>
19
Steve Antonafd8e8c2017-12-19 16:35:35 -080020#include "api/cryptoparams.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "api/mediatypes.h"
Steve Antonafd8e8c2017-12-19 16:35:35 -080022#include "api/rtpparameters.h"
23#include "api/rtptransceiverinterface.h"
Steve Antonafd8e8c2017-12-19 16:35:35 -080024#include "media/base/mediachannel.h"
25#include "media/base/streamparams.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "p2p/base/transportdescription.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080027#include "p2p/base/transportinfo.h"
Amit Hilbucha2012042018-12-03 11:35:05 -080028#include "pc/simulcastdescription.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "rtc_base/socketaddress.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080030
31namespace cricket {
32
Steve Antonafd8e8c2017-12-19 16:35:35 -080033typedef std::vector<AudioCodec> AudioCodecs;
34typedef std::vector<VideoCodec> VideoCodecs;
35typedef std::vector<DataCodec> DataCodecs;
36typedef std::vector<CryptoParams> CryptoParamsVec;
37typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
38
39// RTC4585 RTP/AVPF
40extern const char kMediaProtocolAvpf[];
41// RFC5124 RTP/SAVPF
42extern const char kMediaProtocolSavpf[];
43
44extern const char kMediaProtocolDtlsSavpf[];
45
46extern const char kMediaProtocolRtpPrefix[];
47
48extern const char kMediaProtocolSctp[];
49extern const char kMediaProtocolDtlsSctp[];
50extern const char kMediaProtocolUdpDtlsSctp[];
51extern const char kMediaProtocolTcpDtlsSctp[];
52
53// Options to control how session descriptions are generated.
54const int kAutoBandwidth = -1;
55
Steve Anton5adfafd2017-12-20 16:34:00 -080056class AudioContentDescription;
Steve Anton5adfafd2017-12-20 16:34:00 -080057class DataContentDescription;
Yves Gerey3e707812018-11-28 16:47:49 +010058class VideoContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080059
Steve Anton5adfafd2017-12-20 16:34:00 -080060// Describes a session description media section. There are subclasses for each
61// media type (audio, video, data) that will have additional information.
62class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080063 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080064 MediaContentDescription() = default;
65 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080066
67 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080068
69 // Try to cast this media description to an AudioContentDescription. Returns
70 // nullptr if the cast fails.
71 virtual AudioContentDescription* as_audio() { return nullptr; }
72 virtual const AudioContentDescription* as_audio() const { return nullptr; }
73
74 // Try to cast this media description to a VideoContentDescription. Returns
75 // nullptr if the cast fails.
76 virtual VideoContentDescription* as_video() { return nullptr; }
77 virtual const VideoContentDescription* as_video() const { return nullptr; }
78
79 // Try to cast this media description to a DataContentDescription. Returns
80 // nullptr if the cast fails.
81 virtual DataContentDescription* as_data() { return nullptr; }
82 virtual const DataContentDescription* as_data() const { return nullptr; }
83
Steve Antonafd8e8c2017-12-19 16:35:35 -080084 virtual bool has_codecs() const = 0;
85
Steve Anton5adfafd2017-12-20 16:34:00 -080086 virtual MediaContentDescription* Copy() const = 0;
87
Steve Antonafd8e8c2017-12-19 16:35:35 -080088 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
89 // RTP/SAVPF or SCTP/DTLS.
90 std::string protocol() const { return protocol_; }
91 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
92
93 webrtc::RtpTransceiverDirection direction() const { return direction_; }
94 void set_direction(webrtc::RtpTransceiverDirection direction) {
95 direction_ = direction;
96 }
97
98 bool rtcp_mux() const { return rtcp_mux_; }
99 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
100
101 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
102 void set_rtcp_reduced_size(bool reduced_size) {
103 rtcp_reduced_size_ = reduced_size;
104 }
105
106 int bandwidth() const { return bandwidth_; }
107 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
108
109 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
110 void AddCrypto(const CryptoParams& params) { cryptos_.push_back(params); }
111 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
112 cryptos_ = cryptos;
113 }
114
115 const RtpHeaderExtensions& rtp_header_extensions() const {
116 return rtp_header_extensions_;
117 }
118 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
119 rtp_header_extensions_ = extensions;
120 rtp_header_extensions_set_ = true;
121 }
122 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
123 rtp_header_extensions_.push_back(ext);
124 rtp_header_extensions_set_ = true;
125 }
126 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
127 webrtc::RtpExtension webrtc_extension;
128 webrtc_extension.uri = ext.uri;
129 webrtc_extension.id = ext.id;
130 rtp_header_extensions_.push_back(webrtc_extension);
131 rtp_header_extensions_set_ = true;
132 }
133 void ClearRtpHeaderExtensions() {
134 rtp_header_extensions_.clear();
135 rtp_header_extensions_set_ = true;
136 }
137 // We can't always tell if an empty list of header extensions is
138 // because the other side doesn't support them, or just isn't hooked up to
139 // signal them. For now we assume an empty list means no signaling, but
140 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
141 // clearly indicated (i.e. when derived from other information).
142 bool rtp_header_extensions_set() const { return rtp_header_extensions_set_; }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800143 const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800144 // TODO(pthatcher): Remove this by giving mediamessage.cc access
145 // to MediaContentDescription
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800146 StreamParamsVec& mutable_streams() { return send_streams_; }
147 void AddStream(const StreamParams& stream) {
148 send_streams_.push_back(stream);
149 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800150 // Legacy streams have an ssrc, but nothing else.
151 void AddLegacyStream(uint32_t ssrc) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800152 send_streams_.push_back(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800153 }
154 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
155 StreamParams sp = StreamParams::CreateLegacy(ssrc);
156 sp.AddFidSsrc(ssrc, fid_ssrc);
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800157 send_streams_.push_back(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800158 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800159
160 // In Unified Plan (ex. Simulcast scenario) the receive stream might need
161 // to be specified in the media section description to allow specifying
162 // restrictions and identifying it within the session (see also RID).
163 const StreamParams& receive_stream() const {
164 RTC_DCHECK(has_receive_stream());
165 return receive_stream_.value();
166 }
167
168 bool has_receive_stream() const { return receive_stream_.has_value(); }
169
170 void set_receive_stream(const StreamParams& receive_stream) {
171 receive_stream_ = receive_stream;
172 }
173
Steve Antonafd8e8c2017-12-19 16:35:35 -0800174 // Sets the CNAME of all StreamParams if it have not been set.
175 void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800176 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
177 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800178 if (it->cname.empty())
179 it->cname = cname;
180 }
181 }
182 uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800183 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800184 return 0;
185 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800186 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800187 }
188 bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800189 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800190 return false;
191 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800192 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800193 }
194
195 void set_conference_mode(bool enable) { conference_mode_ = enable; }
196 bool conference_mode() const { return conference_mode_; }
197
198 // https://tools.ietf.org/html/rfc4566#section-5.7
199 // May be present at the media or session level of SDP. If present at both
200 // levels, the media-level attribute overwrites the session-level one.
201 void set_connection_address(const rtc::SocketAddress& address) {
202 connection_address_ = address;
203 }
204 const rtc::SocketAddress& connection_address() const {
205 return connection_address_;
206 }
207
Johannes Kron0854eb62018-10-10 22:33:20 +0200208 // Determines if it's allowed to mix one- and two-byte rtp header extensions
209 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200210 enum ExtmapAllowMixed { kNo, kSession, kMedia };
211 void set_extmap_allow_mixed_enum(ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200212 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200213 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200214 // Do not downgrade from session level to media level.
215 return;
216 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200217 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200218 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200219 ExtmapAllowMixed extmap_allow_mixed_enum() const {
220 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200221 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200222 bool extmap_allow_mixed() const { return extmap_allow_mixed_enum_ != kNo; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200223
Amit Hilbucha2012042018-12-03 11:35:05 -0800224 // Simulcast functionality.
225 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
226 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
227 virtual const SimulcastDescription& simulcast_description() const {
228 return simulcast_;
229 }
230 virtual void set_simulcast_description(
231 const SimulcastDescription& simulcast) {
232 simulcast_ = simulcast;
233 }
234
Steve Antonafd8e8c2017-12-19 16:35:35 -0800235 protected:
236 bool rtcp_mux_ = false;
237 bool rtcp_reduced_size_ = false;
238 int bandwidth_ = kAutoBandwidth;
239 std::string protocol_;
240 std::vector<CryptoParams> cryptos_;
241 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
242 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800243 StreamParamsVec send_streams_;
244 absl::optional<StreamParams> receive_stream_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800245 bool conference_mode_ = false;
246 webrtc::RtpTransceiverDirection direction_ =
247 webrtc::RtpTransceiverDirection::kSendRecv;
248 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200249 // Mixed one- and two-byte header not included in offer on media level or
250 // session level, but we will respond that we support it. The plan is to add
251 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200252 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800253
254 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800255};
256
Steve Anton5adfafd2017-12-20 16:34:00 -0800257// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
258// updated.
259using ContentDescription = MediaContentDescription;
260
Steve Antonafd8e8c2017-12-19 16:35:35 -0800261template <class C>
262class MediaContentDescriptionImpl : public MediaContentDescription {
263 public:
264 typedef C CodecType;
265
266 // Codecs should be in preference order (most preferred codec first).
267 const std::vector<C>& codecs() const { return codecs_; }
268 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
269 virtual bool has_codecs() const { return !codecs_.empty(); }
270 bool HasCodec(int id) {
271 bool found = false;
272 for (typename std::vector<C>::iterator iter = codecs_.begin();
273 iter != codecs_.end(); ++iter) {
274 if (iter->id == id) {
275 found = true;
276 break;
277 }
278 }
279 return found;
280 }
281 void AddCodec(const C& codec) { codecs_.push_back(codec); }
282 void AddOrReplaceCodec(const C& codec) {
283 for (typename std::vector<C>::iterator iter = codecs_.begin();
284 iter != codecs_.end(); ++iter) {
285 if (iter->id == codec.id) {
286 *iter = codec;
287 return;
288 }
289 }
290 AddCodec(codec);
291 }
292 void AddCodecs(const std::vector<C>& codecs) {
293 typename std::vector<C>::const_iterator codec;
294 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
295 AddCodec(*codec);
296 }
297 }
298
299 private:
300 std::vector<C> codecs_;
301};
302
303class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
304 public:
305 AudioContentDescription() {}
306
Steve Antonb1c1de12017-12-21 15:14:30 -0800307 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800308 return new AudioContentDescription(*this);
309 }
310 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800311 virtual AudioContentDescription* as_audio() { return this; }
312 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800313};
314
315class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
316 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800317 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800318 return new VideoContentDescription(*this);
319 }
320 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800321 virtual VideoContentDescription* as_video() { return this; }
322 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800323};
324
325class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
326 public:
327 DataContentDescription() {}
328
Steve Antonb1c1de12017-12-21 15:14:30 -0800329 virtual DataContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800330 return new DataContentDescription(*this);
331 }
332 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800333 virtual DataContentDescription* as_data() { return this; }
334 virtual const DataContentDescription* as_data() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800335
336 bool use_sctpmap() const { return use_sctpmap_; }
337 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
338
339 private:
340 bool use_sctpmap_ = true;
341};
342
Steve Anton5adfafd2017-12-20 16:34:00 -0800343// Protocol used for encoding media. This is the "top level" protocol that may
344// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
345enum class MediaProtocolType {
346 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
347 // https://tools.ietf.org/html/rfc3550
348 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
349 // https://tools.ietf.org/html/rfc4960
350};
351
352// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
353constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
354constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
355
356// Represents a session description section. Most information about the section
357// is stored in the description, which is a subclass of MediaContentDescription.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800358struct ContentInfo {
Steve Antonb1c1de12017-12-21 15:14:30 -0800359 friend class SessionDescription;
360
Steve Anton5adfafd2017-12-20 16:34:00 -0800361 explicit ContentInfo(MediaProtocolType type) : type(type) {}
362
363 // Alias for |name|.
364 std::string mid() const { return name; }
365 void set_mid(const std::string& mid) { this->name = mid; }
366
367 // Alias for |description|.
368 MediaContentDescription* media_description() { return description; }
369 const MediaContentDescription* media_description() const {
370 return description;
371 }
Steve Anton81712112018-01-05 11:27:54 -0800372 void set_media_description(MediaContentDescription* desc) {
373 description = desc;
Steve Anton5adfafd2017-12-20 16:34:00 -0800374 }
375
Steve Anton81712112018-01-05 11:27:54 -0800376 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800377 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800378 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800379 bool rejected = false;
380 bool bundle_only = false;
Steve Anton81712112018-01-05 11:27:54 -0800381 // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this
382 // private.
Steve Antonb1c1de12017-12-21 15:14:30 -0800383 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800384};
385
386typedef std::vector<std::string> ContentNames;
387
388// This class provides a mechanism to aggregate different media contents into a
389// group. This group can also be shared with the peers in a pre-defined format.
390// GroupInfo should be populated only with the |content_name| of the
391// MediaDescription.
392class ContentGroup {
393 public:
394 explicit ContentGroup(const std::string& semantics);
395 ContentGroup(const ContentGroup&);
396 ContentGroup(ContentGroup&&);
397 ContentGroup& operator=(const ContentGroup&);
398 ContentGroup& operator=(ContentGroup&&);
399 ~ContentGroup();
400
401 const std::string& semantics() const { return semantics_; }
402 const ContentNames& content_names() const { return content_names_; }
403
404 const std::string* FirstContentName() const;
405 bool HasContentName(const std::string& content_name) const;
406 void AddContentName(const std::string& content_name);
407 bool RemoveContentName(const std::string& content_name);
408
409 private:
410 std::string semantics_;
411 ContentNames content_names_;
412};
413
414typedef std::vector<ContentInfo> ContentInfos;
415typedef std::vector<ContentGroup> ContentGroups;
416
417const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
418 const std::string& name);
419const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
420 const std::string& type);
421
Steve Antone831b8c2018-02-01 12:22:16 -0800422// Determines how the MSID will be signaled in the SDP. These can be used as
423// flags to indicate both or none.
424enum MsidSignaling {
425 // Signal MSID with one a=msid line in the media section.
426 kMsidSignalingMediaSection = 0x1,
427 // Signal MSID with a=ssrc: msid lines in the media section.
428 kMsidSignalingSsrcAttribute = 0x2
429};
430
Steve Anton4ab68ee2017-12-19 14:26:11 -0800431// Describes a collection of contents, each with its own name and
432// type. Analogous to a <jingle> or <session> stanza. Assumes that
433// contents are unique be name, but doesn't enforce that.
434class SessionDescription {
435 public:
436 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800437 ~SessionDescription();
438
439 SessionDescription* Copy() const;
440
441 // Content accessors.
442 const ContentInfos& contents() const { return contents_; }
443 ContentInfos& contents() { return contents_; }
444 const ContentInfo* GetContentByName(const std::string& name) const;
445 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800446 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800447 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800448 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800449 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800450 const ContentInfo* FirstContent() const;
451
452 // Content mutators.
453 // Adds a content to this description. Takes ownership of ContentDescription*.
454 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800455 MediaProtocolType type,
Steve Antonb1c1de12017-12-21 15:14:30 -0800456 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800457 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800458 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800459 bool rejected,
Steve Antonb1c1de12017-12-21 15:14:30 -0800460 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800461 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800462 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800463 bool rejected,
464 bool bundle_only,
Steve Antonb1c1de12017-12-21 15:14:30 -0800465 MediaContentDescription* description);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200466 void AddContent(ContentInfo* content);
467
Steve Anton4ab68ee2017-12-19 14:26:11 -0800468 bool RemoveContentByName(const std::string& name);
469
470 // Transport accessors.
471 const TransportInfos& transport_infos() const { return transport_infos_; }
472 TransportInfos& transport_infos() { return transport_infos_; }
473 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
474 TransportInfo* GetTransportInfoByName(const std::string& name);
475 const TransportDescription* GetTransportDescriptionByName(
476 const std::string& name) const {
477 const TransportInfo* tinfo = GetTransportInfoByName(name);
478 return tinfo ? &tinfo->description : NULL;
479 }
480
481 // Transport mutators.
482 void set_transport_infos(const TransportInfos& transport_infos) {
483 transport_infos_ = transport_infos;
484 }
485 // Adds a TransportInfo to this description.
486 // Returns false if a TransportInfo with the same name already exists.
487 bool AddTransportInfo(const TransportInfo& transport_info);
488 bool RemoveTransportInfoByName(const std::string& name);
489
490 // Group accessors.
491 const ContentGroups& groups() const { return content_groups_; }
492 const ContentGroup* GetGroupByName(const std::string& name) const;
493 bool HasGroup(const std::string& name) const;
494
495 // Group mutators.
496 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
497 // Remove the first group with the same semantics specified by |name|.
498 void RemoveGroupByName(const std::string& name);
499
500 // Global attributes.
501 void set_msid_supported(bool supported) { msid_supported_ = supported; }
502 bool msid_supported() const { return msid_supported_; }
503
Steve Antone831b8c2018-02-01 12:22:16 -0800504 // Determines how the MSIDs were/will be signaled. Flag value composed of
505 // MsidSignaling bits (see enum above).
506 void set_msid_signaling(int msid_signaling) {
507 msid_signaling_ = msid_signaling;
508 }
509 int msid_signaling() const { return msid_signaling_; }
510
Johannes Kron0854eb62018-10-10 22:33:20 +0200511 // Determines if it's allowed to mix one- and two-byte rtp header extensions
512 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200513 void set_extmap_allow_mixed(bool supported) {
514 extmap_allow_mixed_ = supported;
515 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200516 supported ? MediaContentDescription::kSession
517 : MediaContentDescription::kNo;
518 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200519 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200520 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
521 MediaContentDescription::kMedia) {
522 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200523 media_level_setting);
524 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200525 }
526 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200527 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200528
Steve Anton4ab68ee2017-12-19 14:26:11 -0800529 private:
530 SessionDescription(const SessionDescription&);
531
532 ContentInfos contents_;
533 TransportInfos transport_infos_;
534 ContentGroups content_groups_;
535 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800536 // Default to what Plan B would do.
537 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
538 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100539 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
540 // offer at session level. It's currently not included in offer by default
541 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
542 // correctly. If it's included in offer to us we will respond that we support
543 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200544 bool extmap_allow_mixed_ = false;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800545};
546
Steve Antonb1c1de12017-12-21 15:14:30 -0800547// Indicates whether a session description was sent by the local client or
548// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800549enum ContentSource { CS_LOCAL, CS_REMOTE };
550
551} // namespace cricket
552
553#endif // PC_SESSIONDESCRIPTION_H_