blob: b7da8e05b4fa10456632810d9531d1e6aebe1a44 [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"
Mirko Bonadei35214fc2019-09-23 14:54:28 +020036#include "rtc_base/system/rtc_export.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080037
38namespace cricket {
39
Steve Antonafd8e8c2017-12-19 16:35:35 -080040typedef std::vector<AudioCodec> AudioCodecs;
41typedef std::vector<VideoCodec> VideoCodecs;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020042typedef std::vector<RtpDataCodec> RtpDataCodecs;
Steve Antonafd8e8c2017-12-19 16:35:35 -080043typedef std::vector<CryptoParams> CryptoParamsVec;
44typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
45
46// RTC4585 RTP/AVPF
47extern const char kMediaProtocolAvpf[];
48// RFC5124 RTP/SAVPF
49extern const char kMediaProtocolSavpf[];
50
51extern const char kMediaProtocolDtlsSavpf[];
52
Steve Antonafd8e8c2017-12-19 16:35:35 -080053// Options to control how session descriptions are generated.
54const int kAutoBandwidth = -1;
55
Steve Anton5adfafd2017-12-20 16:34:00 -080056class AudioContentDescription;
Steve Anton46afbf92019-05-10 11:15:18 -070057class VideoContentDescription;
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020058class RtpDataContentDescription;
59class SctpDataContentDescription;
Steve Anton4ab68ee2017-12-19 14:26:11 -080060
Steve Anton5adfafd2017-12-20 16:34:00 -080061// Describes a session description media section. There are subclasses for each
62// media type (audio, video, data) that will have additional information.
63class MediaContentDescription {
Steve Antonafd8e8c2017-12-19 16:35:35 -080064 public:
Steve Anton5adfafd2017-12-20 16:34:00 -080065 MediaContentDescription() = default;
66 virtual ~MediaContentDescription() = default;
Steve Antonafd8e8c2017-12-19 16:35:35 -080067
68 virtual MediaType type() const = 0;
Steve Anton5adfafd2017-12-20 16:34:00 -080069
70 // Try to cast this media description to an AudioContentDescription. Returns
71 // nullptr if the cast fails.
72 virtual AudioContentDescription* as_audio() { return nullptr; }
73 virtual const AudioContentDescription* as_audio() const { return nullptr; }
74
75 // Try to cast this media description to a VideoContentDescription. Returns
76 // nullptr if the cast fails.
77 virtual VideoContentDescription* as_video() { return nullptr; }
78 virtual const VideoContentDescription* as_video() const { return nullptr; }
79
Harald Alvestrand5fc28b12019-05-13 13:36:16 +020080 virtual RtpDataContentDescription* as_rtp_data() { return nullptr; }
81 virtual const RtpDataContentDescription* as_rtp_data() const {
82 return nullptr;
83 }
84
85 virtual SctpDataContentDescription* as_sctp() { return nullptr; }
86 virtual const SctpDataContentDescription* as_sctp() const { return nullptr; }
87
Steve Antonafd8e8c2017-12-19 16:35:35 -080088 virtual bool has_codecs() const = 0;
89
Harald Alvestrand0fb07f82020-02-27 20:21:37 +010090 RTC_DEPRECATED virtual MediaContentDescription* Copy() const {
91 return CloneInternal();
92 }
93 // Copy operator that returns an unique_ptr.
94 // Not a virtual function.
95 // If a type-specific variant of Clone() is desired, override it, or
96 // simply use std::make_unique<typename>(*this) instead of Clone().
97 std::unique_ptr<MediaContentDescription> Clone() const {
98 return absl::WrapUnique(CloneInternal());
Harald Alvestrand1716d392019-06-03 20:35:45 +020099 }
Steve Anton5adfafd2017-12-20 16:34:00 -0800100
Steve Antonafd8e8c2017-12-19 16:35:35 -0800101 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
102 // RTP/SAVPF or SCTP/DTLS.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200103 virtual std::string protocol() const { return protocol_; }
104 virtual void set_protocol(const std::string& protocol) {
105 protocol_ = protocol;
106 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800107
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200108 virtual webrtc::RtpTransceiverDirection direction() const {
109 return direction_;
110 }
111 virtual void set_direction(webrtc::RtpTransceiverDirection direction) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800112 direction_ = direction;
113 }
114
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200115 virtual bool rtcp_mux() const { return rtcp_mux_; }
116 virtual void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800117
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200118 virtual bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
119 virtual void set_rtcp_reduced_size(bool reduced_size) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800120 rtcp_reduced_size_ = reduced_size;
121 }
122
Sebastian Jansson97321b62019-07-24 14:01:18 +0200123 // Indicates support for the remote network estimate packet type. This
124 // functionality is experimental and subject to change without notice.
Sebastian Janssone1795f42019-07-24 11:38:03 +0200125 virtual bool remote_estimate() const { return remote_estimate_; }
126 virtual void set_remote_estimate(bool remote_estimate) {
127 remote_estimate_ = remote_estimate;
128 }
129
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200130 virtual int bandwidth() const { return bandwidth_; }
131 virtual void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800132
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200133 virtual const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
134 virtual void AddCrypto(const CryptoParams& params) {
135 cryptos_.push_back(params);
136 }
137 virtual void set_cryptos(const std::vector<CryptoParams>& cryptos) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800138 cryptos_ = cryptos;
139 }
140
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200141 virtual const RtpHeaderExtensions& rtp_header_extensions() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800142 return rtp_header_extensions_;
143 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200144 virtual void set_rtp_header_extensions(
145 const RtpHeaderExtensions& extensions) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800146 rtp_header_extensions_ = extensions;
147 rtp_header_extensions_set_ = true;
148 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200149 virtual void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800150 rtp_header_extensions_.push_back(ext);
151 rtp_header_extensions_set_ = true;
152 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200153 virtual void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800154 webrtc::RtpExtension webrtc_extension;
155 webrtc_extension.uri = ext.uri;
156 webrtc_extension.id = ext.id;
157 rtp_header_extensions_.push_back(webrtc_extension);
158 rtp_header_extensions_set_ = true;
159 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200160 virtual void ClearRtpHeaderExtensions() {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800161 rtp_header_extensions_.clear();
162 rtp_header_extensions_set_ = true;
163 }
164 // We can't always tell if an empty list of header extensions is
165 // because the other side doesn't support them, or just isn't hooked up to
166 // signal them. For now we assume an empty list means no signaling, but
167 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
168 // clearly indicated (i.e. when derived from other information).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200169 virtual bool rtp_header_extensions_set() const {
170 return rtp_header_extensions_set_;
171 }
172 virtual const StreamParamsVec& streams() const { return send_streams_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800173 // TODO(pthatcher): Remove this by giving mediamessage.cc access
174 // to MediaContentDescription
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200175 virtual StreamParamsVec& mutable_streams() { return send_streams_; }
176 virtual void AddStream(const StreamParams& stream) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800177 send_streams_.push_back(stream);
178 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800179 // Legacy streams have an ssrc, but nothing else.
180 void AddLegacyStream(uint32_t ssrc) {
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200181 AddStream(StreamParams::CreateLegacy(ssrc));
Steve Antonafd8e8c2017-12-19 16:35:35 -0800182 }
183 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
184 StreamParams sp = StreamParams::CreateLegacy(ssrc);
185 sp.AddFidSsrc(ssrc, fid_ssrc);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200186 AddStream(sp);
Steve Antonafd8e8c2017-12-19 16:35:35 -0800187 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800188
Steve Antonafd8e8c2017-12-19 16:35:35 -0800189 // Sets the CNAME of all StreamParams if it have not been set.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200190 virtual void SetCnameIfEmpty(const std::string& cname) {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800191 for (cricket::StreamParamsVec::iterator it = send_streams_.begin();
192 it != send_streams_.end(); ++it) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800193 if (it->cname.empty())
194 it->cname = cname;
195 }
196 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200197 virtual uint32_t first_ssrc() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800198 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800199 return 0;
200 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800201 return send_streams_[0].first_ssrc();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800202 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200203 virtual bool has_ssrcs() const {
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800204 if (send_streams_.empty()) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800205 return false;
206 }
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800207 return send_streams_[0].has_ssrcs();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800208 }
209
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200210 virtual void set_conference_mode(bool enable) { conference_mode_ = enable; }
211 virtual bool conference_mode() const { return conference_mode_; }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800212
213 // https://tools.ietf.org/html/rfc4566#section-5.7
214 // May be present at the media or session level of SDP. If present at both
215 // levels, the media-level attribute overwrites the session-level one.
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200216 virtual void set_connection_address(const rtc::SocketAddress& address) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800217 connection_address_ = address;
218 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200219 virtual const rtc::SocketAddress& connection_address() const {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800220 return connection_address_;
221 }
222
Johannes Kron0854eb62018-10-10 22:33:20 +0200223 // Determines if it's allowed to mix one- and two-byte rtp header extensions
224 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200225 enum ExtmapAllowMixed { kNo, kSession, kMedia };
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200226 virtual void set_extmap_allow_mixed_enum(
227 ExtmapAllowMixed new_extmap_allow_mixed) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200228 if (new_extmap_allow_mixed == kMedia &&
Johannes Kron9581bc42018-10-23 10:17:39 +0200229 extmap_allow_mixed_enum_ == kSession) {
Johannes Kron0854eb62018-10-10 22:33:20 +0200230 // Do not downgrade from session level to media level.
231 return;
232 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200233 extmap_allow_mixed_enum_ = new_extmap_allow_mixed;
Johannes Kron0854eb62018-10-10 22:33:20 +0200234 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200235 virtual ExtmapAllowMixed extmap_allow_mixed_enum() const {
Johannes Kron9581bc42018-10-23 10:17:39 +0200236 return extmap_allow_mixed_enum_;
Johannes Kron9ac3c912018-10-12 10:54:26 +0200237 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200238 virtual bool extmap_allow_mixed() const {
239 return extmap_allow_mixed_enum_ != kNo;
240 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200241
Amit Hilbucha2012042018-12-03 11:35:05 -0800242 // Simulcast functionality.
243 virtual bool HasSimulcast() const { return !simulcast_.empty(); }
244 virtual SimulcastDescription& simulcast_description() { return simulcast_; }
245 virtual const SimulcastDescription& simulcast_description() const {
246 return simulcast_;
247 }
248 virtual void set_simulcast_description(
249 const SimulcastDescription& simulcast) {
250 simulcast_ = simulcast;
251 }
Florent Castellib60141b2019-07-03 12:47:54 +0200252 virtual const std::vector<RidDescription>& receive_rids() const {
253 return receive_rids_;
254 }
255 virtual void set_receive_rids(const std::vector<RidDescription>& rids) {
256 receive_rids_ = rids;
257 }
Amit Hilbucha2012042018-12-03 11:35:05 -0800258
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700259 virtual const absl::optional<std::string>& alt_protocol() const {
260 return alt_protocol_;
261 }
262 virtual void set_alt_protocol(const absl::optional<std::string>& protocol) {
263 alt_protocol_ = protocol;
264 }
265
Steve Antonafd8e8c2017-12-19 16:35:35 -0800266 protected:
267 bool rtcp_mux_ = false;
268 bool rtcp_reduced_size_ = false;
Sebastian Janssone1795f42019-07-24 11:38:03 +0200269 bool remote_estimate_ = false;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800270 int bandwidth_ = kAutoBandwidth;
271 std::string protocol_;
272 std::vector<CryptoParams> cryptos_;
273 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
274 bool rtp_header_extensions_set_ = false;
Amit Hilbuchc57d5732018-12-11 15:30:11 -0800275 StreamParamsVec send_streams_;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800276 bool conference_mode_ = false;
277 webrtc::RtpTransceiverDirection direction_ =
278 webrtc::RtpTransceiverDirection::kSendRecv;
279 rtc::SocketAddress connection_address_;
Johannes Kron0854eb62018-10-10 22:33:20 +0200280 // Mixed one- and two-byte header not included in offer on media level or
281 // session level, but we will respond that we support it. The plan is to add
282 // it to our offer on session level. See todo in SessionDescription.
Johannes Kron9581bc42018-10-23 10:17:39 +0200283 ExtmapAllowMixed extmap_allow_mixed_enum_ = kNo;
Amit Hilbucha2012042018-12-03 11:35:05 -0800284
285 SimulcastDescription simulcast_;
Florent Castellib60141b2019-07-03 12:47:54 +0200286 std::vector<RidDescription> receive_rids_;
Bjorn A Mellem8e1343a2019-09-30 15:12:47 -0700287
288 absl::optional<std::string> alt_protocol_;
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100289
290 private:
291 // Copy function that returns a raw pointer. Caller will assert ownership.
292 // Should only be called by the Clone() function. Must be implemented
293 // by each final subclass.
294 virtual MediaContentDescription* CloneInternal() const = 0;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800295};
296
Steve Anton5adfafd2017-12-20 16:34:00 -0800297// TODO(bugs.webrtc.org/8620): Remove this alias once downstream projects have
298// updated.
299using ContentDescription = MediaContentDescription;
300
Steve Antonafd8e8c2017-12-19 16:35:35 -0800301template <class C>
302class MediaContentDescriptionImpl : public MediaContentDescription {
303 public:
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200304 void set_protocol(const std::string& protocol) override {
305 RTC_DCHECK(IsRtpProtocol(protocol));
306 protocol_ = protocol;
307 }
308
Steve Antonafd8e8c2017-12-19 16:35:35 -0800309 typedef C CodecType;
310
311 // Codecs should be in preference order (most preferred codec first).
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200312 virtual const std::vector<C>& codecs() const { return codecs_; }
313 virtual void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
314 bool has_codecs() const override { return !codecs_.empty(); }
315 virtual bool HasCodec(int id) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800316 bool found = false;
317 for (typename std::vector<C>::iterator iter = codecs_.begin();
318 iter != codecs_.end(); ++iter) {
319 if (iter->id == id) {
320 found = true;
321 break;
322 }
323 }
324 return found;
325 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200326 virtual void AddCodec(const C& codec) { codecs_.push_back(codec); }
327 virtual void AddOrReplaceCodec(const C& codec) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800328 for (typename std::vector<C>::iterator iter = codecs_.begin();
329 iter != codecs_.end(); ++iter) {
330 if (iter->id == codec.id) {
331 *iter = codec;
332 return;
333 }
334 }
335 AddCodec(codec);
336 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200337 virtual void AddCodecs(const std::vector<C>& codecs) {
Steve Antonafd8e8c2017-12-19 16:35:35 -0800338 typename std::vector<C>::const_iterator codec;
339 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
340 AddCodec(*codec);
341 }
342 }
343
344 private:
345 std::vector<C> codecs_;
346};
347
348class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
349 public:
350 AudioContentDescription() {}
351
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100352 RTC_DEPRECATED virtual AudioContentDescription* Copy() const {
353 return CloneInternal();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800354 }
355 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800356 virtual AudioContentDescription* as_audio() { return this; }
357 virtual const AudioContentDescription* as_audio() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100358
359 private:
360 virtual AudioContentDescription* CloneInternal() const {
361 return new AudioContentDescription(*this);
362 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800363};
364
365class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
366 public:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100367 RTC_DEPRECATED virtual VideoContentDescription* Copy() const {
368 return CloneInternal();
Steve Antonafd8e8c2017-12-19 16:35:35 -0800369 }
370 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
Steve Anton5adfafd2017-12-20 16:34:00 -0800371 virtual VideoContentDescription* as_video() { return this; }
372 virtual const VideoContentDescription* as_video() const { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100373
374 private:
375 virtual VideoContentDescription* CloneInternal() const {
376 return new VideoContentDescription(*this);
377 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800378};
379
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200380class RtpDataContentDescription
381 : public MediaContentDescriptionImpl<RtpDataCodec> {
382 public:
383 RtpDataContentDescription() {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200384 MediaType type() const override { return MEDIA_TYPE_DATA; }
385 RtpDataContentDescription* as_rtp_data() override { return this; }
386 const RtpDataContentDescription* as_rtp_data() const override { return this; }
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100387
388 private:
389 RtpDataContentDescription* CloneInternal() const override {
390 return new RtpDataContentDescription(*this);
391 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200392};
393
394class SctpDataContentDescription : public MediaContentDescription {
395 public:
396 SctpDataContentDescription() {}
397 SctpDataContentDescription(const SctpDataContentDescription& o)
398 : MediaContentDescription(o),
399 use_sctpmap_(o.use_sctpmap_),
400 port_(o.port_),
Harald Alvestrandc5effc22019-06-11 11:46:59 +0200401 max_message_size_(o.max_message_size_) {}
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200402 MediaType type() const override { return MEDIA_TYPE_DATA; }
403 SctpDataContentDescription* as_sctp() override { return this; }
404 const SctpDataContentDescription* as_sctp() const override { return this; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200405
406 bool has_codecs() const override { return false; }
407 void set_protocol(const std::string& protocol) override {
408 RTC_DCHECK(IsSctpProtocol(protocol));
409 protocol_ = protocol;
410 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800411
412 bool use_sctpmap() const { return use_sctpmap_; }
413 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200414 int port() const { return port_; }
415 void set_port(int port) { port_ = port; }
416 int max_message_size() const { return max_message_size_; }
417 void set_max_message_size(int max_message_size) {
418 max_message_size_ = max_message_size;
419 }
Steve Antonafd8e8c2017-12-19 16:35:35 -0800420
421 private:
Harald Alvestrand0fb07f82020-02-27 20:21:37 +0100422 SctpDataContentDescription* CloneInternal() const override {
423 return new SctpDataContentDescription(*this);
424 }
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200425 bool use_sctpmap_ = true; // Note: "true" is no longer conformant.
426 // Defaults should be constants imported from SCTP. Quick hack.
427 int port_ = 5000;
Harald Alvestrandfbb45bd2019-05-15 08:07:47 +0200428 // draft-ietf-mmusic-sdp-sctp-23: Max message size default is 64K
429 int max_message_size_ = 64 * 1024;
Steve Antonafd8e8c2017-12-19 16:35:35 -0800430};
431
Steve Anton5adfafd2017-12-20 16:34:00 -0800432// Protocol used for encoding media. This is the "top level" protocol that may
433// be wrapped by zero or many transport protocols (UDP, ICE, etc.).
434enum class MediaProtocolType {
435 kRtp, // Section will use the RTP protocol (e.g., for audio or video).
436 // https://tools.ietf.org/html/rfc3550
437 kSctp // Section will use the SCTP protocol (e.g., for a data channel).
438 // https://tools.ietf.org/html/rfc4960
439};
440
441// TODO(bugs.webrtc.org/8620): Remove once downstream projects have updated.
442constexpr MediaProtocolType NS_JINGLE_RTP = MediaProtocolType::kRtp;
443constexpr MediaProtocolType NS_JINGLE_DRAFT_SCTP = MediaProtocolType::kSctp;
444
445// Represents a session description section. Most information about the section
446// is stored in the description, which is a subclass of MediaContentDescription.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200447// Owns the description.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200448class RTC_EXPORT ContentInfo {
Harald Alvestrand1716d392019-06-03 20:35:45 +0200449 public:
Steve Anton5adfafd2017-12-20 16:34:00 -0800450 explicit ContentInfo(MediaProtocolType type) : type(type) {}
Harald Alvestrand1716d392019-06-03 20:35:45 +0200451 ~ContentInfo();
452 // Copy
453 ContentInfo(const ContentInfo& o);
454 ContentInfo& operator=(const ContentInfo& o);
455 ContentInfo(ContentInfo&& o) = default;
456 ContentInfo& operator=(ContentInfo&& o) = default;
Steve Anton5adfafd2017-12-20 16:34:00 -0800457
458 // Alias for |name|.
459 std::string mid() const { return name; }
460 void set_mid(const std::string& mid) { this->name = mid; }
461
462 // Alias for |description|.
Harald Alvestrand1716d392019-06-03 20:35:45 +0200463 MediaContentDescription* media_description();
464 const MediaContentDescription* media_description() const;
465
466 void set_media_description(std::unique_ptr<MediaContentDescription> desc) {
467 description_ = std::move(desc);
Steve Anton5adfafd2017-12-20 16:34:00 -0800468 }
469
Steve Anton81712112018-01-05 11:27:54 -0800470 // TODO(bugs.webrtc.org/8620): Rename this to mid.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800471 std::string name;
Steve Anton5adfafd2017-12-20 16:34:00 -0800472 MediaProtocolType type;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800473 bool rejected = false;
474 bool bundle_only = false;
Harald Alvestrand1716d392019-06-03 20:35:45 +0200475
476 private:
477 friend class SessionDescription;
478 std::unique_ptr<MediaContentDescription> description_;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800479};
480
481typedef std::vector<std::string> ContentNames;
482
483// This class provides a mechanism to aggregate different media contents into a
484// group. This group can also be shared with the peers in a pre-defined format.
485// GroupInfo should be populated only with the |content_name| of the
486// MediaDescription.
487class ContentGroup {
488 public:
489 explicit ContentGroup(const std::string& semantics);
490 ContentGroup(const ContentGroup&);
491 ContentGroup(ContentGroup&&);
492 ContentGroup& operator=(const ContentGroup&);
493 ContentGroup& operator=(ContentGroup&&);
494 ~ContentGroup();
495
496 const std::string& semantics() const { return semantics_; }
497 const ContentNames& content_names() const { return content_names_; }
498
499 const std::string* FirstContentName() const;
500 bool HasContentName(const std::string& content_name) const;
501 void AddContentName(const std::string& content_name);
502 bool RemoveContentName(const std::string& content_name);
503
504 private:
505 std::string semantics_;
506 ContentNames content_names_;
507};
508
509typedef std::vector<ContentInfo> ContentInfos;
510typedef std::vector<ContentGroup> ContentGroups;
511
512const ContentInfo* FindContentInfoByName(const ContentInfos& contents,
513 const std::string& name);
514const ContentInfo* FindContentInfoByType(const ContentInfos& contents,
515 const std::string& type);
516
Steve Antone831b8c2018-02-01 12:22:16 -0800517// Determines how the MSID will be signaled in the SDP. These can be used as
518// flags to indicate both or none.
519enum MsidSignaling {
520 // Signal MSID with one a=msid line in the media section.
521 kMsidSignalingMediaSection = 0x1,
522 // Signal MSID with a=ssrc: msid lines in the media section.
523 kMsidSignalingSsrcAttribute = 0x2
524};
525
Steve Anton4ab68ee2017-12-19 14:26:11 -0800526// Describes a collection of contents, each with its own name and
527// type. Analogous to a <jingle> or <session> stanza. Assumes that
528// contents are unique be name, but doesn't enforce that.
529class SessionDescription {
530 public:
531 SessionDescription();
Steve Anton4ab68ee2017-12-19 14:26:11 -0800532 ~SessionDescription();
533
Harald Alvestrand4d7160e2019-04-12 07:01:29 +0200534 std::unique_ptr<SessionDescription> Clone() const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800535
536 // Content accessors.
537 const ContentInfos& contents() const { return contents_; }
538 ContentInfos& contents() { return contents_; }
539 const ContentInfo* GetContentByName(const std::string& name) const;
540 ContentInfo* GetContentByName(const std::string& name);
Steve Antonb1c1de12017-12-21 15:14:30 -0800541 const MediaContentDescription* GetContentDescriptionByName(
Steve Anton4ab68ee2017-12-19 14:26:11 -0800542 const std::string& name) const;
Steve Antonb1c1de12017-12-21 15:14:30 -0800543 MediaContentDescription* GetContentDescriptionByName(const std::string& name);
Steve Anton5adfafd2017-12-20 16:34:00 -0800544 const ContentInfo* FirstContentByType(MediaProtocolType type) const;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800545 const ContentInfo* FirstContent() const;
546
547 // Content mutators.
548 // Adds a content to this description. Takes ownership of ContentDescription*.
549 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800550 MediaProtocolType type,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200551 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800552 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800553 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800554 bool rejected,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200555 std::unique_ptr<MediaContentDescription> description);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800556 void AddContent(const std::string& name,
Steve Anton5adfafd2017-12-20 16:34:00 -0800557 MediaProtocolType type,
Steve Anton4ab68ee2017-12-19 14:26:11 -0800558 bool rejected,
559 bool bundle_only,
Harald Alvestrand1716d392019-06-03 20:35:45 +0200560 std::unique_ptr<MediaContentDescription> description);
561 void AddContent(ContentInfo&& content);
Johannes Kron9ac3c912018-10-12 10:54:26 +0200562
Steve Anton4ab68ee2017-12-19 14:26:11 -0800563 bool RemoveContentByName(const std::string& name);
564
565 // Transport accessors.
566 const TransportInfos& transport_infos() const { return transport_infos_; }
567 TransportInfos& transport_infos() { return transport_infos_; }
568 const TransportInfo* GetTransportInfoByName(const std::string& name) const;
569 TransportInfo* GetTransportInfoByName(const std::string& name);
570 const TransportDescription* GetTransportDescriptionByName(
571 const std::string& name) const {
572 const TransportInfo* tinfo = GetTransportInfoByName(name);
573 return tinfo ? &tinfo->description : NULL;
574 }
575
576 // Transport mutators.
577 void set_transport_infos(const TransportInfos& transport_infos) {
578 transport_infos_ = transport_infos;
579 }
580 // Adds a TransportInfo to this description.
Steve Anton06817cd2018-12-18 15:55:30 -0800581 void AddTransportInfo(const TransportInfo& transport_info);
Steve Anton4ab68ee2017-12-19 14:26:11 -0800582 bool RemoveTransportInfoByName(const std::string& name);
583
584 // Group accessors.
585 const ContentGroups& groups() const { return content_groups_; }
586 const ContentGroup* GetGroupByName(const std::string& name) const;
587 bool HasGroup(const std::string& name) const;
588
589 // Group mutators.
590 void AddGroup(const ContentGroup& group) { content_groups_.push_back(group); }
591 // Remove the first group with the same semantics specified by |name|.
592 void RemoveGroupByName(const std::string& name);
593
594 // Global attributes.
595 void set_msid_supported(bool supported) { msid_supported_ = supported; }
596 bool msid_supported() const { return msid_supported_; }
597
Steve Antone831b8c2018-02-01 12:22:16 -0800598 // Determines how the MSIDs were/will be signaled. Flag value composed of
599 // MsidSignaling bits (see enum above).
600 void set_msid_signaling(int msid_signaling) {
601 msid_signaling_ = msid_signaling;
602 }
603 int msid_signaling() const { return msid_signaling_; }
604
Johannes Kron0854eb62018-10-10 22:33:20 +0200605 // Determines if it's allowed to mix one- and two-byte rtp header extensions
606 // within the same rtp stream.
Johannes Kron9581bc42018-10-23 10:17:39 +0200607 void set_extmap_allow_mixed(bool supported) {
608 extmap_allow_mixed_ = supported;
609 MediaContentDescription::ExtmapAllowMixed media_level_setting =
Johannes Kron0854eb62018-10-10 22:33:20 +0200610 supported ? MediaContentDescription::kSession
611 : MediaContentDescription::kNo;
612 for (auto& content : contents_) {
Johannes Kron9ac3c912018-10-12 10:54:26 +0200613 // Do not set to kNo if the current setting is kMedia.
Johannes Kron9581bc42018-10-23 10:17:39 +0200614 if (supported || content.media_description()->extmap_allow_mixed_enum() !=
615 MediaContentDescription::kMedia) {
616 content.media_description()->set_extmap_allow_mixed_enum(
Johannes Kron9ac3c912018-10-12 10:54:26 +0200617 media_level_setting);
618 }
Johannes Kron0854eb62018-10-10 22:33:20 +0200619 }
620 }
Johannes Kron9581bc42018-10-23 10:17:39 +0200621 bool extmap_allow_mixed() const { return extmap_allow_mixed_; }
Johannes Kron0854eb62018-10-10 22:33:20 +0200622
Steve Anton4ab68ee2017-12-19 14:26:11 -0800623 private:
624 SessionDescription(const SessionDescription&);
625
626 ContentInfos contents_;
627 TransportInfos transport_infos_;
628 ContentGroups content_groups_;
629 bool msid_supported_ = true;
Steve Antone831b8c2018-02-01 12:22:16 -0800630 // Default to what Plan B would do.
631 // TODO(bugs.webrtc.org/8530): Change default to kMsidSignalingMediaSection.
632 int msid_signaling_ = kMsidSignalingSsrcAttribute;
Johannes Kron89f874e2018-11-12 10:25:48 +0100633 // TODO(webrtc:9985): Activate mixed one- and two-byte header extension in
634 // offer at session level. It's currently not included in offer by default
635 // because clients prior to https://bugs.webrtc.org/9712 cannot parse this
636 // correctly. If it's included in offer to us we will respond that we support
637 // it.
Johannes Kron9581bc42018-10-23 10:17:39 +0200638 bool extmap_allow_mixed_ = false;
Steve Anton4ab68ee2017-12-19 14:26:11 -0800639};
640
Steve Antonb1c1de12017-12-21 15:14:30 -0800641// Indicates whether a session description was sent by the local client or
642// received from the remote client.
Steve Anton4ab68ee2017-12-19 14:26:11 -0800643enum ContentSource { CS_LOCAL, CS_REMOTE };
644
645} // namespace cricket
646
Steve Anton10542f22019-01-11 09:11:00 -0800647#endif // PC_SESSION_DESCRIPTION_H_