blob: 7e625109725aab369d9a36f8a5bd0099c25b97d5 [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>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020017#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080018#include <string>
19#include <vector>
20
Steve Anton10542f22019-01-11 09:11:00 -080021#include "api/crypto_params.h"
22#include "api/media_types.h"
23#include "api/rtp_parameters.h"
24#include "api/rtp_transceiver_interface.h"
25#include "media/base/media_channel.h"
26#include "media/base/stream_params.h"
27#include "p2p/base/transport_description.h"
28#include "p2p/base/transport_info.h"
29#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020030#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "rtc_base/socket_address.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080032
33namespace cricket {
34
Steve Antonafd8e8c2017-12-19 16:35:35 -080035typedef std::vector<AudioCodec> AudioCodecs;
36typedef std::vector<VideoCodec> VideoCodecs;
Steve Anton46afbf92019-05-10 11:15:18 -070037typedef std::vector<DataCodec> DataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080038typedef std::vector<CryptoParams> CryptoParamsVec;
39typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
40
41// RTC4585 RTP/AVPF
42extern const char kMediaProtocolAvpf[];
43// RFC5124 RTP/SAVPF
44extern const char kMediaProtocolSavpf[];
45
46extern const char kMediaProtocolDtlsSavpf[];
47
Steve Anton46afbf92019-05-10 11:15:18 -070048extern const char kMediaProtocolRtpPrefix[];
49
50extern const char kMediaProtocolSctp[];
51extern const char kMediaProtocolDtlsSctp[];
52extern const char kMediaProtocolUdpDtlsSctp[];
53extern const char kMediaProtocolTcpDtlsSctp[];
Steve Antonafd8e8c2017-12-19 16:35:35 -080054
55// Options to control how session descriptions are generated.
56const int kAutoBandwidth = -1;
57
Steve Anton5adfafd2017-12-20 16:34:00 -080058class AudioContentDescription;
Harald Alvestrand37f2b432019-05-09 09:19:54 +020059class DataContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070060class VideoContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080061
Steve Anton5adfafd2017-12-20 16:34:00 -080062// Describes a session description media section. There are subclasses for each
63// media type (audio, video, data) that will have additional information.
64class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080065 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080066 MediaContentDescription() = default;
67 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080068
69 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080070
71 // Try to cast this media description to an AudioContentDescription. Returns
72 // nullptr if the cast fails.
73 virtual AudioContentDescription* as_audio() { return nullptr; }
74 virtual const AudioContentDescription* as_audio() const { return nullptr; }
75
76 // Try to cast this media description to a VideoContentDescription. Returns
77 // nullptr if the cast fails.
78 virtual VideoContentDescription* as_video() { return nullptr; }
79 virtual const VideoContentDescription* as_video() const { return nullptr; }
80
Steve Anton46afbf92019-05-10 11:15:18 -070081 // Try to cast this media description to a DataContentDescription. Returns
82 // nullptr if the cast fails.
Steve Anton5adfafd2017-12-20 16:34:00 -080083 virtual DataContentDescription* as_data() { return nullptr; }
84 virtual const DataContentDescription* as_data() const { return nullptr; }
85
Steve Antonafd8e8c2017-12-19 16:35:35 -080086 virtual bool has_codecs() const = 0;
87
Steve Anton5adfafd2017-12-20 16:34:00 -080088 virtual MediaContentDescription* Copy() const = 0;
89
Steve Antonafd8e8c2017-12-19 16:35:35 -080090 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
91 // RTP/SAVPF or SCTP/DTLS.
Steve Anton46afbf92019-05-10 11:15:18 -070092 std::string protocol() const { return protocol_; }
93 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
Steve Antonafd8e8c2017-12-19 16:35:35 -080094
Steve Anton46afbf92019-05-10 11:15:18 -070095 webrtc::RtpTransceiverDirection direction() const { return direction_; }
96 void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -080097 direction_ = direction;
98 }
99
Steve Anton46afbf92019-05-10 11:15:18 -0700100 bool rtcp_mux() const { return rtcp_mux_; }
101 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800102
Steve Anton46afbf92019-05-10 11:15:18 -0700103 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
104 void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800105 rtcp_reduced_size_ = reduced_size;
106 }
107
Steve Anton46afbf92019-05-10 11:15:18 -0700108 int bandwidth() const { return bandwidth_; }
109 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800110
Steve Anton46afbf92019-05-10 11:15:18 -0700111 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
112 void AddCrypto(const CryptoParams& params) { cryptos_.push_back(params); }
113 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800114 cryptos_ = cryptos;
115 }
116
Steve Anton46afbf92019-05-10 11:15:18 -0700117 const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800118 return rtp_header_extensions_;
119 }
Steve Anton46afbf92019-05-10 11:15:18 -0700120 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800121 rtp_header_extensions_ = extensions;
122 rtp_header_extensions_set_ = true;
123 }
Steve Anton46afbf92019-05-10 11:15:18 -0700124 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800125 rtp_header_extensions_.push_back(ext);
126 rtp_header_extensions_set_ = true;
127 }
Steve Anton46afbf92019-05-10 11:15:18 -0700128 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800129 webrtc::RtpExtension webrtc_extension;
130 webrtc_extension.uri = ext.uri;
131 webrtc_extension.id = ext.id;
132 rtp_header_extensions_.push_back(webrtc_extension);
133 rtp_header_extensions_set_ = true;
134 }
Steve Anton46afbf92019-05-10 11:15:18 -0700135 void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800136 rtp_header_extensions_.clear();
137 rtp_header_extensions_set_ = true;
138 }
139 // We can't always tell if an empty list of header extensions is
140 // because the other side doesn't support them, or just isn't hooked up to
141 // signal them. For now we assume an empty list means no signaling, but
142 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
143 // clearly indicated (i.e. when derived from other information).
Steve Anton46afbf92019-05-10 11:15:18 -0700144 bool rtp_header_extensions_set() const { return rtp_header_extensions_set_; }
145 const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800146 // TODO(pthatcher): Remove this by giving mediamessage.cc access
147 // to MediaContentDescription
Steve Anton46afbf92019-05-10 11:15:18 -0700148 StreamParamsVec& mutable_streams() { return send_streams_; }
149 void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800150 send_streams_.push_back(stream);
151 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800152 // Legacy streams have an ssrc, but nothing else.
153 void AddLegacyStream(uint32_t ssrc) {
Steve Anton46afbf92019-05-10 11:15:18 -0700154 send_streams_.push_back(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800155 }
156 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
157 StreamParams sp = StreamParams::CreateLegacy(ssrc);
158 sp.AddFidSsrc(ssrc, fid_ssrc);
Steve Anton46afbf92019-05-10 11:15:18 -0700159 send_streams_.push_back(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800160 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800161
Steve Antonafd8e8c2017-12-19 16:35:35 -0800162 // Sets the CNAME of all StreamParams if it have not been set.
Steve Anton46afbf92019-05-10 11:15:18 -0700163 void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800164 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
165 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800166 if (it->cname.empty())
167 it->cname = cname;
168 }
169 }
Steve Anton46afbf92019-05-10 11:15:18 -0700170 uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800171 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800172 return 0;
173 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800174 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 }
Steve Anton46afbf92019-05-10 11:15:18 -0700176 bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800177 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800178 return false;
179 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800180 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800181 }
182
Steve Anton46afbf92019-05-10 11:15:18 -0700183 void set_conference_mode(bool enable) { conference_mode_ = enable; }
184 bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800185
186 // https://tools.ietf.org/html/rfc4566#section-5.7
187 // May be present at the media or session level of SDP. If present at both
188 // levels, the media-level attribute overwrites the session-level one.
Steve Anton46afbf92019-05-10 11:15:18 -0700189 void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800190 connection_address_ = address;
191 }
Steve Anton46afbf92019-05-10 11:15:18 -0700192 const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800193 return connection_address_;
194 }
195
Johannes Kron0854eb62018-10-10 22:33:20 +0200196 // Determines if it's allowed to mix one- and two-byte rtp header extensions
197 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200198 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Steve Anton46afbf92019-05-10 11:15:18 -0700199 void set_extmap_allow_mixed_enum(ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200200 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200201 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200202 // Do not downgrade from session level to media level.
203 return;
204 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200205 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200206 }
Steve Anton46afbf92019-05-10 11:15:18 -0700207 ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200208 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200209 }
Steve Anton46afbf92019-05-10 11:15:18 -0700210 bool extmap_allow_mixed() const { return extmap_allow_mixed_enum_ != kNo; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200211
Amit Hilbucha2012042018-12-03 11:35:05 -0800212 // Simulcast functionality.
213 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
214 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
215 virtual const SimulcastDescription& simulcast_description() const {
216 return simulcast_;
217 }
218 virtual void set_simulcast_description(
219 const SimulcastDescription& simulcast) {
220 simulcast_ = simulcast;
221 }
222
Steve Antonafd8e8c2017-12-19 16:35:35 -0800223 protected:
224 bool rtcp_mux_ = false;
225 bool rtcp_reduced_size_ = false;
226 int bandwidth_ = kAutoBandwidth;
227 std::string protocol_;
228 std::vector<CryptoParams> cryptos_;
229 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
230 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800231 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800232 bool conference_mode_ = false;
233 webrtc::RtpTransceiverDirection direction_ =
234 webrtc::RtpTransceiverDirection::kSendRecv;
235 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200236 // Mixed one- and two-byte header not included in offer on media level or
237 // session level, but we will respond that we support it. The plan is to add
238 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200239 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800240
241 SimulcastDescription simulcast_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800242};
243
Steve Anton5adfafd2017-12-20 16:34:00 -0800244// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
245// updated.
246using ContentDescription = MediaContentDescription;
247
Steve Antonafd8e8c2017-12-19 16:35:35 -0800248template <class C>
249class MediaContentDescriptionImpl : public MediaContentDescription {
250 public:
251 typedef C CodecType;
252
253 // Codecs should be in preference order (most preferred codec first).
Steve Anton46afbf92019-05-10 11:15:18 -0700254 const std::vector<C>& codecs() const { return codecs_; }
255 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
256 virtual bool has_codecs() const { return !codecs_.empty(); }
257 bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800258 bool found = false;
259 for (typename std::vector<C>::iterator iter = codecs_.begin();
260 iter != codecs_.end(); ++iter) {
261 if (iter->id == id) {
262 found = true;
263 break;
264 }
265 }
266 return found;
267 }
Steve Anton46afbf92019-05-10 11:15:18 -0700268 void AddCodec(const C& codec) { codecs_.push_back(codec); }
269 void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800270 for (typename std::vector<C>::iterator iter = codecs_.begin();
271 iter != codecs_.end(); ++iter) {
272 if (iter->id == codec.id) {
273 *iter = codec;
274 return;
275 }
276 }
277 AddCodec(codec);
278 }
Steve Anton46afbf92019-05-10 11:15:18 -0700279 void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800280 typename std::vector<C>::const_iterator codec;
281 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
282 AddCodec(*codec);
283 }
284 }
285
286 private:
287 std::vector<C> codecs_;
288};
289
290class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
291 public:
292 AudioContentDescription() {}
293
Steve Antonb1c1de12017-12-21 15:14:30 -0800294 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800295 return new AudioContentDescription(*this);
296 }
297 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800298 virtual AudioContentDescription* as_audio() { return this; }
299 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800300};
301
302class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
303 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800304 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800305 return new VideoContentDescription(*this);
306 }
307 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800308 virtual VideoContentDescription* as_video() { return this; }
309 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800310};
311
312class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
313 public:
Steve Anton46afbf92019-05-10 11:15:18 -0700314 DataContentDescription() {}
Steve Antonafd8e8c2017-12-19 16:35:35 -0800315
Steve Anton46afbf92019-05-10 11:15:18 -0700316 virtual DataContentDescription* Copy() const {
317 return new DataContentDescription(*this);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800318 }
Steve Anton46afbf92019-05-10 11:15:18 -0700319 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
320 virtual DataContentDescription* as_data() { return this; }
321 virtual const DataContentDescription* as_data() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800322
323 bool use_sctpmap() const { return use_sctpmap_; }
324 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
325
326 private:
Steve Anton46afbf92019-05-10 11:15:18 -0700327 bool use_sctpmap_ = true;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800328};
329
Steve Anton5adfafd2017-12-20 16:34:00 -0800330// Protocol used for encoding media. This is the "top level" protocol that may
331// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
332enum class MediaProtocolType {
333 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
334 // https://tools.ietf.org/html/rfc3550
335 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
336 // https://tools.ietf.org/html/rfc4960
337};
338
339// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
340constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
341constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
342
343// Represents a session description section. Most information about the section
344// is stored in the description, which is a subclass of MediaContentDescription.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800345struct ContentInfo {
Steve Antonb1c1de12017-12-21 15:14:30 -0800346 friend class SessionDescription;
347
Steve Anton5adfafd2017-12-20 16:34:00 -0800348 explicit ContentInfo(MediaProtocolType type) : type(type) {}
349
350 // Alias for |name|.
351 std::string mid() const { return name; }
352 void set_mid(const std::string& mid) { this->name = mid; }
353
354 // Alias for |description|.
355 MediaContentDescription* media_description() { return description; }
356 const MediaContentDescription* media_description() const {
357 return description;
358 }
Steve Anton81712112018-01-05 11:27:54 -0800359 void set_media_description(MediaContentDescription* desc) {
360 description = desc;
Steve Anton5adfafd2017-12-20 16:34:00 -0800361 }
362
Steve Anton81712112018-01-05 11:27:54 -0800363 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800364 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800365 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800366 bool rejected = false;
367 bool bundle_only = false;
Steve Anton81712112018-01-05 11:27:54 -0800368 // TODO(bugs.webrtc.org/8620): Switch to the getter and setter, and make this
369 // private.
Steve Antonb1c1de12017-12-21 15:14:30 -0800370 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800371};
372
373typedef std::vector<std::string> ContentNames;
374
375// This class provides a mechanism to aggregate different media contents into a
376// group. This group can also be shared with the peers in a pre-defined format.
377// GroupInfo should be populated only with the |content_name| of the
378// MediaDescription.
379class ContentGroup {
380 public:
381 explicit ContentGroup(const std::string& semantics);
382 ContentGroup(const ContentGroup&);
383 ContentGroup(ContentGroup&&);
384 ContentGroup& operator=(const ContentGroup&);
385 ContentGroup& operator=(ContentGroup&&);
386 ~ContentGroup();
387
388 const std::string& semantics() const { return semantics_; }
389 const ContentNames& content_names() const { return content_names_; }
390
391 const std::string* FirstContentName() const;
392 bool HasContentName(const std::string& content_name) const;
393 void AddContentName(const std::string& content_name);
394 bool RemoveContentName(const std::string& content_name);
395
396 private:
397 std::string semantics_;
398 ContentNames content_names_;
399};
400
401typedef std::vector<ContentInfo> ContentInfos;
402typedef std::vector<ContentGroup> ContentGroups;
403
404const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
405 const std::string& name);
406const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
407 const std::string& type);
408
Steve Antone831b8c2018-02-01 12:22:16 -0800409// Determines how the MSID will be signaled in the SDP. These can be used as
410// flags to indicate both or none.
411enum MsidSignaling {
412 // Signal MSID with one a=msid line in the media section.
413 kMsidSignalingMediaSection = 0x1,
414 // Signal MSID with a=ssrc: msid lines in the media section.
415 kMsidSignalingSsrcAttribute = 0x2
416};
417
Steve Anton4ab68ee2017-12-19 14:26:11 -0800418// Describes a collection of contents, each with its own name and
419// type. Analogous to a <jingle> or <session> stanza. Assumes that
420// contents are unique be name, but doesn't enforce that.
421class SessionDescription {
422 public:
423 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800424 ~SessionDescription();
425
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200426 std::unique_ptr<SessionDescription> Clone() const;
Harald Alvestrand8da35a62019-05-10 09:31:04 +0200427 // Older API - deprecated. Still expects caller to take ownership.
428 // Replace with Clone().
429 RTC_DEPRECATED SessionDescription* Copy() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800430
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800431 struct MediaTransportSetting;
432
Steve Anton4ab68ee2017-12-19 14:26:11 -0800433 // Content accessors.
434 const ContentInfos& contents() const { return contents_; }
435 ContentInfos& contents() { return contents_; }
436 const ContentInfo* GetContentByName(const std::string& name) const;
437 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800438 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800439 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800440 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800441 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800442 const ContentInfo* FirstContent() const;
443
444 // Content mutators.
445 // Adds a content to this description. Takes ownership of ContentDescription*.
446 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800447 MediaProtocolType type,
Steve Antonb1c1de12017-12-21 15:14:30 -0800448 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800449 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800450 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800451 bool rejected,
Steve Antonb1c1de12017-12-21 15:14:30 -0800452 MediaContentDescription* description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800453 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800454 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800455 bool rejected,
456 bool bundle_only,
Steve Antonb1c1de12017-12-21 15:14:30 -0800457 MediaContentDescription* description);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200458 void AddContent(ContentInfo* content);
459
Steve Anton4ab68ee2017-12-19 14:26:11 -0800460 bool RemoveContentByName(const std::string& name);
461
462 // Transport accessors.
463 const TransportInfos& transport_infos() const { return transport_infos_; }
464 TransportInfos& transport_infos() { return transport_infos_; }
465 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
466 TransportInfo* GetTransportInfoByName(const std::string& name);
467 const TransportDescription* GetTransportDescriptionByName(
468 const std::string& name) const {
469 const TransportInfo* tinfo = GetTransportInfoByName(name);
470 return tinfo ? &tinfo->description : NULL;
471 }
472
473 // Transport mutators.
474 void set_transport_infos(const TransportInfos& transport_infos) {
475 transport_infos_ = transport_infos;
476 }
477 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800478 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800479 bool RemoveTransportInfoByName(const std::string& name);
480
481 // Group accessors.
482 const ContentGroups& groups() const { return content_groups_; }
483 const ContentGroup* GetGroupByName(const std::string& name) const;
484 bool HasGroup(const std::string& name) const;
485
486 // Group mutators.
487 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
488 // Remove the first group with the same semantics specified by |name|.
489 void RemoveGroupByName(const std::string& name);
490
491 // Global attributes.
492 void set_msid_supported(bool supported) { msid_supported_ = supported; }
493 bool msid_supported() const { return msid_supported_; }
494
Steve Antone831b8c2018-02-01 12:22:16 -0800495 // Determines how the MSIDs were/will be signaled. Flag value composed of
496 // MsidSignaling bits (see enum above).
497 void set_msid_signaling(int msid_signaling) {
498 msid_signaling_ = msid_signaling;
499 }
500 int msid_signaling() const { return msid_signaling_; }
501
Johannes Kron0854eb62018-10-10 22:33:20 +0200502 // Determines if it's allowed to mix one- and two-byte rtp header extensions
503 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200504 void set_extmap_allow_mixed(bool supported) {
505 extmap_allow_mixed_ = supported;
506 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200507 supported ? MediaContentDescription::kSession
508 : MediaContentDescription::kNo;
509 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200510 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200511 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
512 MediaContentDescription::kMedia) {
513 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200514 media_level_setting);
515 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200516 }
517 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200518 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200519
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800520 // Adds the media transport setting.
521 // Media transport name uniquely identifies the type of media transport.
522 // The name cannot be empty, or repeated in the previously added transport
523 // settings.
524 void AddMediaTransportSetting(const std::string& media_transport_name,
525 const std::string& media_transport_setting) {
526 RTC_DCHECK(!media_transport_name.empty());
527 for (const auto& setting : media_transport_settings_) {
528 RTC_DCHECK(media_transport_name != setting.transport_name)
529 << "MediaTransportSetting was already registered, transport_name="
530 << setting.transport_name;
531 }
532 media_transport_settings_.push_back(
533 {media_transport_name, media_transport_setting});
534 }
535
536 // Gets the media transport settings, in order of preference.
537 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
538 return media_transport_settings_;
539 }
540
541 struct MediaTransportSetting {
542 std::string transport_name;
543 std::string transport_setting;
544 };
545
Steve Anton4ab68ee2017-12-19 14:26:11 -0800546 private:
547 SessionDescription(const SessionDescription&);
548
549 ContentInfos contents_;
550 TransportInfos transport_infos_;
551 ContentGroups content_groups_;
552 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800553 // Default to what Plan B would do.
554 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
555 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100556 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
557 // offer at session level. It's currently not included in offer by default
558 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
559 // correctly. If it's included in offer to us we will respond that we support
560 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200561 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800562
563 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800564};
565
Steve Antonb1c1de12017-12-21 15:14:30 -0800566// Indicates whether a session description was sent by the local client or
567// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800568enum ContentSource { CS_LOCAL, CS_REMOTE };
569
570} // namespace cricket
571
Steve Anton10542f22019-01-11 09:11:00 -0800572#endif // PC_SESSION_DESCRIPTION_H_