blob: 9856cd6534c871ee9d5af05f90d53e43a15ebf30 [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <iosfwd>
Harald Alvestrand4d7160e2019-04-12 07:01:29 +020018#include <memory>
Steve Anton4ab68ee2017-12-19 14:26:11 -080019#include <string>
Harald Alvestrand1716d392019-06-03 20:35:45 +020020#include <utility>
Steve Anton4ab68ee2017-12-19 14:26:11 -080021#include <vector>
22
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020023#include "absl/memory/memory.h"
Steve Anton10542f22019-01-11 09:11:00 -080024#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/stream_params.h"
30#include "p2p/base/transport_description.h"
31#include "p2p/base/transport_info.h"
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020032#include "pc/media_protocol_names.h"
Steve Anton10542f22019-01-11 09:11:00 -080033#include "pc/simulcast_description.h"
Harald Alvestrand8da35a62019-05-10 09:31:04 +020034#include "rtc_base/deprecation.h"
Steve Anton10542f22019-01-11 09:11:00 -080035#include "rtc_base/socket_address.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080036
37namespace cricket {
38
Steve Antonafd8e8c2017-12-19 16:35:35 -080039typedef std::vector<AudioCodec> AudioCodecs;
40typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020041typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080042typedef std::vector<CryptoParams> CryptoParamsVec;
43typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
44
45// RTC4585 RTP/AVPF
46extern const char kMediaProtocolAvpf[];
47// RFC5124 RTP/SAVPF
48extern const char kMediaProtocolSavpf[];
49
50extern const char kMediaProtocolDtlsSavpf[];
51
Steve Antonafd8e8c2017-12-19 16:35:35 -080052// Options to control how session descriptions are generated.
53const int kAutoBandwidth = -1;
54
Steve Anton5adfafd2017-12-20 16:34:00 -080055class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070056class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020057class RtpDataContentDescription;
58class SctpDataContentDescription;
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
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020079 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
80 virtual const RtpDataContentDescription* as_rtp_data() const {
81 return nullptr;
82 }
83
84 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
85 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
86
Steve Antonafd8e8c2017-12-19 16:35:35 -080087 virtual bool has_codecs() const = 0;
88
Steve Anton5adfafd2017-12-20 16:34:00 -080089 virtual MediaContentDescription* Copy() const = 0;
Harald Alvestrand1716d392019-06-03 20:35:45 +020090 virtual std::unique_ptr<MediaContentDescription> Clone() const {
91 return absl::WrapUnique(Copy());
92 }
Steve Anton5adfafd2017-12-20 16:34:00 -080093
Steve Antonafd8e8c2017-12-19 16:35:35 -080094 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
95 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020096 virtual std::string protocol() const { return protocol_; }
97 virtual void set_protocol(const std::string& protocol) {
98 protocol_ = protocol;
99 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800100
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200101 virtual webrtc::RtpTransceiverDirection direction() const {
102 return direction_;
103 }
104 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800105 direction_ = direction;
106 }
107
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200108 virtual bool rtcp_mux() const { return rtcp_mux_; }
109 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800110
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200111 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
112 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800113 rtcp_reduced_size_ = reduced_size;
114 }
115
Sebastian Jansson97321b62019-07-24 14:01:18 +0200116 // Indicates support for the remote network estimate packet type. This
117 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200118 virtual bool remote_estimate() const { return remote_estimate_; }
119 virtual void set_remote_estimate(bool remote_estimate) {
120 remote_estimate_ = remote_estimate;
121 }
122
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200123 virtual int bandwidth() const { return bandwidth_; }
124 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800125
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200126 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
127 virtual void AddCrypto(const CryptoParams& params) {
128 cryptos_.push_back(params);
129 }
130 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800131 cryptos_ = cryptos;
132 }
133
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200134 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800135 return rtp_header_extensions_;
136 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200137 virtual void set_rtp_header_extensions(
138 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800139 rtp_header_extensions_ = extensions;
140 rtp_header_extensions_set_ = true;
141 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200142 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800143 rtp_header_extensions_.push_back(ext);
144 rtp_header_extensions_set_ = true;
145 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200146 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800147 webrtc::RtpExtension webrtc_extension;
148 webrtc_extension.uri = ext.uri;
149 webrtc_extension.id = ext.id;
150 rtp_header_extensions_.push_back(webrtc_extension);
151 rtp_header_extensions_set_ = true;
152 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200153 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800154 rtp_header_extensions_.clear();
155 rtp_header_extensions_set_ = true;
156 }
157 // We can't always tell if an empty list of header extensions is
158 // because the other side doesn't support them, or just isn't hooked up to
159 // signal them. For now we assume an empty list means no signaling, but
160 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
161 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200162 virtual bool rtp_header_extensions_set() const {
163 return rtp_header_extensions_set_;
164 }
165 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800166 // TODO(pthatcher): Remove this by giving mediamessage.cc access
167 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200168 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
169 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800170 send_streams_.push_back(stream);
171 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800172 // Legacy streams have an ssrc, but nothing else.
173 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200174 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800175 }
176 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
177 StreamParams sp = StreamParams::CreateLegacy(ssrc);
178 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200179 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800180 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800181
Steve Antonafd8e8c2017-12-19 16:35:35 -0800182 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200183 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800184 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
185 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800186 if (it->cname.empty())
187 it->cname = cname;
188 }
189 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200190 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800191 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800192 return 0;
193 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800194 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800195 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200196 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800197 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800198 return false;
199 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800200 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800201 }
202
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200203 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
204 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800205
206 // https://tools.ietf.org/html/rfc4566#section-5.7
207 // May be present at the media or session level of SDP. If present at both
208 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200209 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800210 connection_address_ = address;
211 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200212 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800213 return connection_address_;
214 }
215
Johannes Kron0854eb62018-10-10 22:33:20 +0200216 // Determines if it's allowed to mix one- and two-byte rtp header extensions
217 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200218 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200219 virtual void set_extmap_allow_mixed_enum(
220 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200221 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200222 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200223 // Do not downgrade from session level to media level.
224 return;
225 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200226 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200227 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200228 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200229 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200230 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200231 virtual bool extmap_allow_mixed() const {
232 return extmap_allow_mixed_enum_ != kNo;
233 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200234
Amit Hilbucha2012042018-12-03 11:35:05 -0800235 // Simulcast functionality.
236 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
237 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
238 virtual const SimulcastDescription& simulcast_description() const {
239 return simulcast_;
240 }
241 virtual void set_simulcast_description(
242 const SimulcastDescription& simulcast) {
243 simulcast_ = simulcast;
244 }
Florent Castellib60141b2019-07-03 12:47:54 +0200245 virtual const std::vector<RidDescription>& receive_rids() const {
246 return receive_rids_;
247 }
248 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
249 receive_rids_ = rids;
250 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800251
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700252 virtual const absl::optional<std::string>& alt_protocol() const {
253 return alt_protocol_;
254 }
255 virtual void set_alt_protocol(const absl::optional<std::string>& protocol) {
256 alt_protocol_ = protocol;
257 }
258
Steve Antonafd8e8c2017-12-19 16:35:35 -0800259 protected:
260 bool rtcp_mux_ = false;
261 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200262 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800263 int bandwidth_ = kAutoBandwidth;
264 std::string protocol_;
265 std::vector<CryptoParams> cryptos_;
266 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
267 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800268 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800269 bool conference_mode_ = false;
270 webrtc::RtpTransceiverDirection direction_ =
271 webrtc::RtpTransceiverDirection::kSendRecv;
272 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200273 // Mixed one- and two-byte header not included in offer on media level or
274 // session level, but we will respond that we support it. The plan is to add
275 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200276 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800277
278 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200279 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700280
281 absl::optional<std::string> alt_protocol_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800282};
283
Steve Anton5adfafd2017-12-20 16:34:00 -0800284// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
285// updated.
286using ContentDescription = MediaContentDescription;
287
Steve Antonafd8e8c2017-12-19 16:35:35 -0800288template <class C>
289class MediaContentDescriptionImpl : public MediaContentDescription {
290 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200291 void set_protocol(const std::string& protocol) override {
292 RTC_DCHECK(IsRtpProtocol(protocol));
293 protocol_ = protocol;
294 }
295
Steve Antonafd8e8c2017-12-19 16:35:35 -0800296 typedef C CodecType;
297
298 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200299 virtual const std::vector<C>& codecs() const { return codecs_; }
300 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
301 bool has_codecs() const override { return !codecs_.empty(); }
302 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800303 bool found = false;
304 for (typename std::vector<C>::iterator iter = codecs_.begin();
305 iter != codecs_.end(); ++iter) {
306 if (iter->id == id) {
307 found = true;
308 break;
309 }
310 }
311 return found;
312 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200313 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
314 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800315 for (typename std::vector<C>::iterator iter = codecs_.begin();
316 iter != codecs_.end(); ++iter) {
317 if (iter->id == codec.id) {
318 *iter = codec;
319 return;
320 }
321 }
322 AddCodec(codec);
323 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200324 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800325 typename std::vector<C>::const_iterator codec;
326 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
327 AddCodec(*codec);
328 }
329 }
330
331 private:
332 std::vector<C> codecs_;
333};
334
335class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
336 public:
337 AudioContentDescription() {}
338
Steve Antonb1c1de12017-12-21 15:14:30 -0800339 virtual AudioContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800340 return new AudioContentDescription(*this);
341 }
342 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800343 virtual AudioContentDescription* as_audio() { return this; }
344 virtual const AudioContentDescription* as_audio() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800345};
346
347class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
348 public:
Steve Antonb1c1de12017-12-21 15:14:30 -0800349 virtual VideoContentDescription* Copy() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800350 return new VideoContentDescription(*this);
351 }
352 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800353 virtual VideoContentDescription* as_video() { return this; }
354 virtual const VideoContentDescription* as_video() const { return this; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800355};
356
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200357class RtpDataContentDescription
358 : public MediaContentDescriptionImpl<RtpDataCodec> {
359 public:
360 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200361 RtpDataContentDescription* Copy() const override {
362 return new RtpDataContentDescription(*this);
363 }
364 MediaType type() const override { return MEDIA_TYPE_DATA; }
365 RtpDataContentDescription* as_rtp_data() override { return this; }
366 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200367};
368
369class SctpDataContentDescription : public MediaContentDescription {
370 public:
371 SctpDataContentDescription() {}
372 SctpDataContentDescription(const SctpDataContentDescription& o)
373 : MediaContentDescription(o),
374 use_sctpmap_(o.use_sctpmap_),
375 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200376 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200377 SctpDataContentDescription* Copy() const override {
378 return new SctpDataContentDescription(*this);
379 }
380 MediaType type() const override { return MEDIA_TYPE_DATA; }
381 SctpDataContentDescription* as_sctp() override { return this; }
382 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200383
384 bool has_codecs() const override { return false; }
385 void set_protocol(const std::string& protocol) override {
386 RTC_DCHECK(IsSctpProtocol(protocol));
387 protocol_ = protocol;
388 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800389
390 bool use_sctpmap() const { return use_sctpmap_; }
391 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200392 int port() const { return port_; }
393 void set_port(int port) { port_ = port; }
394 int max_message_size() const { return max_message_size_; }
395 void set_max_message_size(int max_message_size) {
396 max_message_size_ = max_message_size;
397 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800398
399 private:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200400 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
401 // Defaults should be constants imported from SCTP. Quick hack.
402 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200403 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
404 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800405};
406
Steve Anton5adfafd2017-12-20 16:34:00 -0800407// Protocol used for encoding media. This is the "top level" protocol that may
408// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
409enum class MediaProtocolType {
410 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
411 // https://tools.ietf.org/html/rfc3550
412 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
413 // https://tools.ietf.org/html/rfc4960
414};
415
416// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
417constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
418constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
419
420// Represents a session description section. Most information about the section
421// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200422// Owns the description.
423class ContentInfo {
424 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800425 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200426 ~ContentInfo();
427 // Copy
428 ContentInfo(const ContentInfo& o);
429 ContentInfo& operator=(const ContentInfo& o);
430 ContentInfo(ContentInfo&& o) = default;
431 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800432
433 // Alias for |name|.
434 std::string mid() const { return name; }
435 void set_mid(const std::string& mid) { this->name = mid; }
436
437 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200438 MediaContentDescription* media_description();
439 const MediaContentDescription* media_description() const;
440
441 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
442 description_ = std::move(desc);
443 // For backwards compatibility only.
444 description = description_.get();
Steve Anton5adfafd2017-12-20 16:34:00 -0800445 }
446
Steve Anton81712112018-01-05 11:27:54 -0800447 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800448 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800449 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800450 bool rejected = false;
451 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200452
453 private:
454 friend class SessionDescription;
455 std::unique_ptr<MediaContentDescription> description_;
456
457 public:
458 // Kept for backwards compatibility only.
Steve Antonb1c1de12017-12-21 15:14:30 -0800459 MediaContentDescription* description = nullptr;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800460};
461
462typedef std::vector<std::string> ContentNames;
463
464// This class provides a mechanism to aggregate different media contents into a
465// group. This group can also be shared with the peers in a pre-defined format.
466// GroupInfo should be populated only with the |content_name| of the
467// MediaDescription.
468class ContentGroup {
469 public:
470 explicit ContentGroup(const std::string& semantics);
471 ContentGroup(const ContentGroup&);
472 ContentGroup(ContentGroup&&);
473 ContentGroup& operator=(const ContentGroup&);
474 ContentGroup& operator=(ContentGroup&&);
475 ~ContentGroup();
476
477 const std::string& semantics() const { return semantics_; }
478 const ContentNames& content_names() const { return content_names_; }
479
480 const std::string* FirstContentName() const;
481 bool HasContentName(const std::string& content_name) const;
482 void AddContentName(const std::string& content_name);
483 bool RemoveContentName(const std::string& content_name);
484
485 private:
486 std::string semantics_;
487 ContentNames content_names_;
488};
489
490typedef std::vector<ContentInfo> ContentInfos;
491typedef std::vector<ContentGroup> ContentGroups;
492
493const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
494 const std::string& name);
495const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
496 const std::string& type);
497
Steve Antone831b8c2018-02-01 12:22:16 -0800498// Determines how the MSID will be signaled in the SDP. These can be used as
499// flags to indicate both or none.
500enum MsidSignaling {
501 // Signal MSID with one a=msid line in the media section.
502 kMsidSignalingMediaSection = 0x1,
503 // Signal MSID with a=ssrc: msid lines in the media section.
504 kMsidSignalingSsrcAttribute = 0x2
505};
506
Steve Anton4ab68ee2017-12-19 14:26:11 -0800507// Describes a collection of contents, each with its own name and
508// type. Analogous to a <jingle> or <session> stanza. Assumes that
509// contents are unique be name, but doesn't enforce that.
510class SessionDescription {
511 public:
512 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800513 ~SessionDescription();
514
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200515 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800516
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800517 struct MediaTransportSetting;
518
Steve Anton4ab68ee2017-12-19 14:26:11 -0800519 // Content accessors.
520 const ContentInfos& contents() const { return contents_; }
521 ContentInfos& contents() { return contents_; }
522 const ContentInfo* GetContentByName(const std::string& name) const;
523 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800524 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800525 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800526 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800527 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800528 const ContentInfo* FirstContent() const;
529
530 // Content mutators.
531 // Adds a content to this description. Takes ownership of ContentDescription*.
532 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800533 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200534 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800535 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800536 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800537 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200538 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800539 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800540 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800541 bool rejected,
542 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200543 std::unique_ptr<MediaContentDescription> description);
544 void AddContent(ContentInfo&& content);
545 RTC_DEPRECATED void AddContent(const std::string& name,
546 MediaProtocolType type,
547 MediaContentDescription* description) {
548 AddContent(name, type, absl::WrapUnique(description));
549 }
550 RTC_DEPRECATED void AddContent(const std::string& name,
551 MediaProtocolType type,
552 bool rejected,
553 MediaContentDescription* description) {
554 AddContent(name, type, rejected, absl::WrapUnique(description));
555 }
556 RTC_DEPRECATED void AddContent(const std::string& name,
557 MediaProtocolType type,
558 bool rejected,
559 bool bundle_only,
560 MediaContentDescription* description) {
561 AddContent(name, type, rejected, bundle_only,
562 absl::WrapUnique(description));
563 }
564
565 RTC_DEPRECATED void AddContent(ContentInfo* content) {
566 AddContent(std::move(*content));
567 }
Johannes Kron9ac3c912018-10-12 10:54:26 +0200568
Steve Anton4ab68ee2017-12-19 14:26:11 -0800569 bool RemoveContentByName(const std::string& name);
570
571 // Transport accessors.
572 const TransportInfos& transport_infos() const { return transport_infos_; }
573 TransportInfos& transport_infos() { return transport_infos_; }
574 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
575 TransportInfo* GetTransportInfoByName(const std::string& name);
576 const TransportDescription* GetTransportDescriptionByName(
577 const std::string& name) const {
578 const TransportInfo* tinfo = GetTransportInfoByName(name);
579 return tinfo ? &tinfo->description : NULL;
580 }
581
582 // Transport mutators.
583 void set_transport_infos(const TransportInfos& transport_infos) {
584 transport_infos_ = transport_infos;
585 }
586 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800587 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800588 bool RemoveTransportInfoByName(const std::string& name);
589
590 // Group accessors.
591 const ContentGroups& groups() const { return content_groups_; }
592 const ContentGroup* GetGroupByName(const std::string& name) const;
593 bool HasGroup(const std::string& name) const;
594
595 // Group mutators.
596 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
597 // Remove the first group with the same semantics specified by |name|.
598 void RemoveGroupByName(const std::string& name);
599
600 // Global attributes.
601 void set_msid_supported(bool supported) { msid_supported_ = supported; }
602 bool msid_supported() const { return msid_supported_; }
603
Steve Antone831b8c2018-02-01 12:22:16 -0800604 // Determines how the MSIDs were/will be signaled. Flag value composed of
605 // MsidSignaling bits (see enum above).
606 void set_msid_signaling(int msid_signaling) {
607 msid_signaling_ = msid_signaling;
608 }
609 int msid_signaling() const { return msid_signaling_; }
610
Johannes Kron0854eb62018-10-10 22:33:20 +0200611 // Determines if it's allowed to mix one- and two-byte rtp header extensions
612 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200613 void set_extmap_allow_mixed(bool supported) {
614 extmap_allow_mixed_ = supported;
615 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200616 supported ? MediaContentDescription::kSession
617 : MediaContentDescription::kNo;
618 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200619 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200620 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
621 MediaContentDescription::kMedia) {
622 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200623 media_level_setting);
624 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200625 }
626 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200627 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200628
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800629 // Adds the media transport setting.
630 // Media transport name uniquely identifies the type of media transport.
631 // The name cannot be empty, or repeated in the previously added transport
632 // settings.
633 void AddMediaTransportSetting(const std::string& media_transport_name,
634 const std::string& media_transport_setting) {
635 RTC_DCHECK(!media_transport_name.empty());
636 for (const auto& setting : media_transport_settings_) {
637 RTC_DCHECK(media_transport_name != setting.transport_name)
638 << "MediaTransportSetting was already registered, transport_name="
639 << setting.transport_name;
640 }
641 media_transport_settings_.push_back(
642 {media_transport_name, media_transport_setting});
643 }
644
645 // Gets the media transport settings, in order of preference.
646 const std::vector<MediaTransportSetting>& MediaTransportSettings() const {
647 return media_transport_settings_;
648 }
649
650 struct MediaTransportSetting {
651 std::string transport_name;
652 std::string transport_setting;
653 };
654
Steve Anton4ab68ee2017-12-19 14:26:11 -0800655 private:
656 SessionDescription(const SessionDescription&);
657
658 ContentInfos contents_;
659 TransportInfos transport_infos_;
660 ContentGroups content_groups_;
661 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800662 // Default to what Plan B would do.
663 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
664 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100665 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
666 // offer at session level. It's currently not included in offer by default
667 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
668 // correctly. If it's included in offer to us we will respond that we support
669 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200670 bool extmap_allow_mixed_ = false;
Piotr (Peter) Slatala13e570f2019-02-27 11:34:26 -0800671
672 std::vector<MediaTransportSetting> media_transport_settings_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800673};
674
Steve Antonb1c1de12017-12-21 15:14:30 -0800675// Indicates whether a session description was sent by the local client or
676// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800677enum ContentSource { CS_LOCAL, CS_REMOTE };
678
679} // namespace cricket
680
Steve Anton10542f22019-01-11 09:11:00 -0800681#endif // PC_SESSION_DESCRIPTION_H_