blob: 430cbdb04cba97ede13e47cf9bb360773d7058fd [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_SESSION_DESCRIPTION_H_
12#define PC_SESSION_DESCRIPTION_H_
Steve Anton4ab68ee2017-12-19 14:26:11 -080013
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 Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto_params.h"
21#include "api/media_types.h"
22#include "api/rtp_parameters.h"
23#include "api/rtp_transceiver_interface.h"
24#include "media/base/media_channel.h"
25#include "media/base/stream_params.h"
26#include "p2p/base/transport_description.h"
27#include "p2p/base/transport_info.h"
28#include "pc/simulcast_description.h"
29#include "rtc_base/socket_address.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
Steve Antonafd8e8c2017-12-19 16:35:35 -0800160 // Sets the CNAME of all StreamParams if it have not been set.
161 void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800162 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
163 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800164 if (it->cname.empty())
165 it->cname = cname;
166 }
167 }
168 uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800169 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800170 return 0;
171 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800172 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800173 }
174 bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800175 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800176 return false;
177 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800178 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800179 }
180
181 void set_conference_mode(bool enable) { conference_mode_ = enable; }
182 bool conference_mode() const { return conference_mode_; }
183
184 // https://tools.ietf.org/html/rfc4566#section-5.7
185 // May be present at the media or session level of SDP. If present at both
186 // levels, the media-level attribute overwrites the session-level one.
187 void set_connection_address(const rtc::SocketAddress& address) {
188 connection_address_ = address;
189 }
190 const rtc::SocketAddress& connection_address() const {
191 return connection_address_;
192 }
193
Johannes Kron0854eb62018-10-10 22:33:20 +0200194 // Determines if it's allowed to mix one- and two-byte rtp header extensions
195 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200196 enum ExtmapAllowMixed { kNo, kSession, kMedia };
197 void set_extmap_allow_mixed_enum(ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200198 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200199 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200200 // Do not downgrade from session level to media level.
201 return;
202 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200203 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200204 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200205 ExtmapAllowMixed extmap_allow_mixed_enum() const {
206 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200207 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200208 bool extmap_allow_mixed() const { return extmap_allow_mixed_enum_ != kNo; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200209
Amit Hilbucha2012042018-12-03 11:35:05 -0800210 // Simulcast functionality.
211 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
212 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
213 virtual const SimulcastDescription& simulcast_description() const {
214 return simulcast_;
215 }
216 virtual void set_simulcast_description(
217 const SimulcastDescription& simulcast) {
218 simulcast_ = simulcast;
219 }
220
Steve Antonafd8e8c2017-12-19 16:35:35 -0800221 protected:
222 bool rtcp_mux_ = false;
223 bool rtcp_reduced_size_ = false;
224 int bandwidth_ = kAutoBandwidth;
225 std::string protocol_;
226 std::vector<CryptoParams> cryptos_;
227 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
228 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800229 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800230 bool conference_mode_ = false;
231 webrtc::RtpTransceiverDirection direction_ =
232 webrtc::RtpTransceiverDirection::kSendRecv;
233 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200234 // Mixed one- and two-byte header not included in offer on media level or
235 // session level, but we will respond that we support it. The plan is to add
236 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200237 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800238
239 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800240};
241
Steve Anton5adfafd2017-12-20 16:34:00 -0800242// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
243// updated.
244using ContentDescription = MediaContentDescription;
245
Steve Antonafd8e8c2017-12-19 16:35:35 -0800246template <class C>
247class MediaContentDescriptionImpl : public MediaContentDescription {
248 public:
249 typedef C CodecType;
250
251 // Codecs should be in preference order (most preferred codec first).
252 const std::vector<C>& codecs() const { return codecs_; }
253 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
254 virtual bool has_codecs() const { return !codecs_.empty(); }
255 bool HasCodec(int id) {
256 bool found = false;
257 for (typename std::vector<C>::iterator iter = codecs_.begin();
258 iter != codecs_.end(); ++iter) {
259 if (iter->id == id) {
260 found = true;
261 break;
262 }
263 }
264 return found;
265 }
266 void AddCodec(const C& codec) { codecs_.push_back(codec); }
267 void AddOrReplaceCodec(const C& codec) {
268 for (typename std::vector<C>::iterator iter = codecs_.begin();
269 iter != codecs_.end(); ++iter) {
270 if (iter->id == codec.id) {
271 *iter = codec;
272 return;
273 }
274 }
275 AddCodec(codec);
276 }
277 void AddCodecs(const std::vector<C>& codecs) {
278 typename std::vector<C>::const_iterator codec;
279 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
280 AddCodec(*codec);
281 }
282 }
283
284 private:
285 std::vector<C> codecs_;
286};
287
288class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
289 public:
290 AudioContentDescription() {}
291
Steve Antonb1c1de12017-12-21 15:14:30 -0800292 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800293 return new AudioContentDescription(*this);
294 }
295 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800296 virtual AudioContentDescription* as_audio() { return this; }
297 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800298};
299
300class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
301 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800302 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800303 return new VideoContentDescription(*this);
304 }
305 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800306 virtual VideoContentDescription* as_video() { return this; }
307 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800308};
309
310class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
311 public:
312 DataContentDescription() {}
313
Steve Antonb1c1de12017-12-21 15:14:30 -0800314 virtual DataContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800315 return new DataContentDescription(*this);
316 }
317 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800318 virtual DataContentDescription* as_data() { return this; }
319 virtual const DataContentDescription* as_data() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800320
321 bool use_sctpmap() const { return use_sctpmap_; }
322 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
323
324 private:
325 bool use_sctpmap_ = true;
326};
327
Steve Anton5adfafd2017-12-20 16:34:00 -0800328// Protocol used for encoding media. This is the "top level" protocol that may
329// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
330enum class MediaProtocolType {
331 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
332 // https://tools.ietf.org/html/rfc3550
333 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
334 // https://tools.ietf.org/html/rfc4960
335};
336
337// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
338constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
339constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
340
341// Represents a session description section. Most information about the section
342// is stored in the description, which is a subclass of MediaContentDescription.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800343struct ContentInfo {
Steve Antonb1c1de12017-12-21 15:14:30 -0800344 friend class SessionDescription;
345
Steve Anton5adfafd2017-12-20 16:34:00 -0800346 explicit ContentInfo(MediaProtocolType type) : type(type) {}
347
348 // Alias for |name|.
349 std::string mid() const { return name; }
350 void set_mid(const std::string& mid) { this->name = mid; }
351
352 // Alias for |description|.
353 MediaContentDescription* media_description() { return description; }
354 const MediaContentDescription* media_description() const {
355 return description;
356 }
Steve Anton81712112018-01-05 11:27:54 -0800357 void set_media_description(MediaContentDescription* desc) {
358 description = desc;
Steve Anton5adfafd2017-12-20 16:34:00 -0800359 }
360
Steve Anton81712112018-01-05 11:27:54 -0800361 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800362 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800363 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800364 bool rejected = false;
365 bool bundle_only = false;
Steve Anton81712112018-01-05 11:27:54 -0800366 // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this
367 // private.
Steve Antonb1c1de12017-12-21 15:14:30 -0800368 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800369};
370
371typedef std::vector<std::string> ContentNames;
372
373// This class provides a mechanism to aggregate different media contents into a
374// group. This group can also be shared with the peers in a pre-defined format.
375// GroupInfo should be populated only with the |content_name| of the
376// MediaDescription.
377class ContentGroup {
378 public:
379 explicit ContentGroup(const std::string& semantics);
380 ContentGroup(const ContentGroup&);
381 ContentGroup(ContentGroup&&);
382 ContentGroup& operator=(const ContentGroup&);
383 ContentGroup& operator=(ContentGroup&&);
384 ~ContentGroup();
385
386 const std::string& semantics() const { return semantics_; }
387 const ContentNames& content_names() const { return content_names_; }
388
389 const std::string* FirstContentName() const;
390 bool HasContentName(const std::string& content_name) const;
391 void AddContentName(const std::string& content_name);
392 bool RemoveContentName(const std::string& content_name);
393
394 private:
395 std::string semantics_;
396 ContentNames content_names_;
397};
398
399typedef std::vector<ContentInfo> ContentInfos;
400typedef std::vector<ContentGroup> ContentGroups;
401
402const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
403 const std::string& name);
404const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
405 const std::string& type);
406
Steve Antone831b8c2018-02-01 12:22:16 -0800407// Determines how the MSID will be signaled in the SDP. These can be used as
408// flags to indicate both or none.
409enum MsidSignaling {
410 // Signal MSID with one a=msid line in the media section.
411 kMsidSignalingMediaSection = 0x1,
412 // Signal MSID with a=ssrc: msid lines in the media section.
413 kMsidSignalingSsrcAttribute = 0x2
414};
415
Steve Anton4ab68ee2017-12-19 14:26:11 -0800416// Describes a collection of contents, each with its own name and
417// type. Analogous to a <jingle> or <session> stanza. Assumes that
418// contents are unique be name, but doesn't enforce that.
419class SessionDescription {
420 public:
421 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800422 ~SessionDescription();
423
424 SessionDescription* Copy() const;
425
426 // Content accessors.
427 const ContentInfos& contents() const { return contents_; }
428 ContentInfos& contents() { return contents_; }
429 const ContentInfo* GetContentByName(const std::string& name) const;
430 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800431 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800432 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800433 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800434 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800435 const ContentInfo* FirstContent() const;
436
437 // Content mutators.
438 // Adds a content to this description. Takes ownership of ContentDescription*.
439 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800440 MediaProtocolType type,
Steve Antonb1c1de12017-12-21 15:14:30 -0800441 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800442 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800443 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800444 bool rejected,
Steve Antonb1c1de12017-12-21 15:14:30 -0800445 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800446 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800447 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800448 bool rejected,
449 bool bundle_only,
Steve Antonb1c1de12017-12-21 15:14:30 -0800450 MediaContentDescription* description);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200451 void AddContent(ContentInfo* content);
452
Steve Anton4ab68ee2017-12-19 14:26:11 -0800453 bool RemoveContentByName(const std::string& name);
454
455 // Transport accessors.
456 const TransportInfos& transport_infos() const { return transport_infos_; }
457 TransportInfos& transport_infos() { return transport_infos_; }
458 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
459 TransportInfo* GetTransportInfoByName(const std::string& name);
460 const TransportDescription* GetTransportDescriptionByName(
461 const std::string& name) const {
462 const TransportInfo* tinfo = GetTransportInfoByName(name);
463 return tinfo ? &tinfo->description : NULL;
464 }
465
466 // Transport mutators.
467 void set_transport_infos(const TransportInfos& transport_infos) {
468 transport_infos_ = transport_infos;
469 }
470 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800471 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800472 bool RemoveTransportInfoByName(const std::string& name);
473
474 // Group accessors.
475 const ContentGroups& groups() const { return content_groups_; }
476 const ContentGroup* GetGroupByName(const std::string& name) const;
477 bool HasGroup(const std::string& name) const;
478
479 // Group mutators.
480 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
481 // Remove the first group with the same semantics specified by |name|.
482 void RemoveGroupByName(const std::string& name);
483
484 // Global attributes.
485 void set_msid_supported(bool supported) { msid_supported_ = supported; }
486 bool msid_supported() const { return msid_supported_; }
487
Steve Antone831b8c2018-02-01 12:22:16 -0800488 // Determines how the MSIDs were/will be signaled. Flag value composed of
489 // MsidSignaling bits (see enum above).
490 void set_msid_signaling(int msid_signaling) {
491 msid_signaling_ = msid_signaling;
492 }
493 int msid_signaling() const { return msid_signaling_; }
494
Johannes Kron0854eb62018-10-10 22:33:20 +0200495 // Determines if it's allowed to mix one- and two-byte rtp header extensions
496 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200497 void set_extmap_allow_mixed(bool supported) {
498 extmap_allow_mixed_ = supported;
499 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200500 supported ? MediaContentDescription::kSession
501 : MediaContentDescription::kNo;
502 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200503 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200504 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
505 MediaContentDescription::kMedia) {
506 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200507 media_level_setting);
508 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200509 }
510 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200511 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200512
Steve Anton4ab68ee2017-12-19 14:26:11 -0800513 private:
514 SessionDescription(const SessionDescription&);
515
516 ContentInfos contents_;
517 TransportInfos transport_infos_;
518 ContentGroups content_groups_;
519 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800520 // Default to what Plan B would do.
521 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
522 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100523 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
524 // offer at session level. It's currently not included in offer by default
525 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
526 // correctly. If it's included in offer to us we will respond that we support
527 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200528 bool extmap_allow_mixed_ = false;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800529};
530
Steve Antonb1c1de12017-12-21 15:14:30 -0800531// Indicates whether a session description was sent by the local client or
532// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800533enum ContentSource { CS_LOCAL, CS_REMOTE };
534
535} // namespace cricket
536
Steve Anton10542f22019-01-11 09:11:00 -0800537#endif // PC_SESSION_DESCRIPTION_H_